-
Notifications
You must be signed in to change notification settings - Fork 2
feat: checkbox component #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6519f71
b9b5ffb
74cd7d2
1ed5302
d39bfef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { ClassValue, KeyEvent, PressHandler, Style } from '@geastack/core' | ||
|
|
||
| export interface CheckboxProps { | ||
| /** Checked state of the checkbox */ | ||
| checked?: boolean | ||
| /** Indeterminate/mixed state of the checkbox */ | ||
| indeterminate?: boolean | ||
| /** Whether the checkbox is disabled */ | ||
| disabled?: boolean | ||
| /** Optional text label to display beside the checkbox */ | ||
| label?: string | ||
| /** Custom class names (string, array, or class map) */ | ||
| class?: ClassValue | ||
| /** Custom inline styles */ | ||
| style?: Style | ||
| /** Triggered when the checked state changes */ | ||
| onChange?: (checked: boolean) => void | ||
| /** Triggered via press/click. Note: Runs through the native click event path */ | ||
| onPress?: PressHandler | ||
| /** Triggered via click. Note: Runs through the native click event path */ | ||
| onClick?: PressHandler | ||
| /** Accessibility Labels When Labels Are Not Displayed */ | ||
| ariaLabel?: string | ||
| } | ||
|
|
||
| export function Checkbox(props: CheckboxProps): any | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import type { ClassValue, KeyEvent, PressHandler, Style } from '@geastack/core' | ||
|
|
||
| export interface CheckboxProps { | ||
| checked?: boolean | ||
| indeterminate?: boolean | ||
| disabled?: boolean | ||
| label?: string | ||
| class?: ClassValue | ||
| style?: Style | ||
| onChange?: (checked: boolean) => void | ||
| onPress?: PressHandler | ||
| onClick?: PressHandler | ||
| ariaLabel?: string | ||
| } | ||
|
|
||
| const resolveClass = (val?: ClassValue | null): string => { | ||
| if (!val) return '' | ||
| if (typeof val === 'string') return val | ||
| if (Array.isArray(val)) return val.map(resolveClass).filter(Boolean).join(' ') | ||
| if (typeof val === 'object') { | ||
| return Object.entries(val) | ||
| .filter(([_, enabled]) => Boolean(enabled)) | ||
| .map(([key]) => key) | ||
| .join(' ') | ||
| } | ||
| return '' | ||
| } | ||
|
|
||
| export function Checkbox({ | ||
| checked = false, | ||
| indeterminate = false, | ||
| disabled = false, | ||
| label, | ||
| class: cls, | ||
| style, | ||
| onChange, | ||
| onPress, | ||
| onClick, | ||
|
Comment on lines
+31
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: rg -n 'Checkbox|checkbox' examples docs --glob '*.{ts,tsx,md,mdx,json}' | head -180
git diff --name-only 1e40a7a25b2ac23c842ecd95932e4ca7e0b9a1dd 6519f714d99ce8cc88f41e29ec01f3a9d2f88981Repository: geastack/core Length of output: 388 🏁 Script executed: printf '%s\n' '--- tracked candidate files ---'
git ls-files | rg -i '(^|/)(gallery|example|examples|demo|demos|storybook|stories|showcase)(/|\.|$)|\.(stories|story|mdx)$' | head -240
printf '%s\n' '--- Checkbox references across tracked source/docs ---'
rg -n -i 'Checkbox|checkbox' --glob '!packages/engine/components/Checkbox.tsx' --glob '!packages/engine/components/Checkbox.d.ts' --glob '!packages/engine/components/index.ts' --glob '!packages/engine/components/index.d.ts'
printf '%s\n' '--- full PR changed paths and focused diff ---'
git diff --name-only 1e40a7a25b2ac23c842ecd95932e4ca7e0b9a1dd 6519f714d99ce8cc88f41e29ec01f3a9d2f88981
git diff --unified=20 1e40a7a25b2ac23c842ecd95932e4ca7e0b9a1dd 6519f714d99ce8cc88f41e29ec01f3a9d2f88981 -- packages/engine/package.json packages/engine/components/Checkbox.tsx packages/engine/components/index.tsRepository: geastack/core Length of output: 4797 Add the required Checkbox example and gallery entry. Issue 🤖 Prompt for AI Agents |
||
| ariaLabel | ||
| }: CheckboxProps) { | ||
| const toggle = () => { | ||
| if (disabled) return | ||
| onChange?.(indeterminate ? true : !checked) | ||
| } | ||
|
|
||
| const handlePress = (e: any) => { | ||
| if (disabled) return | ||
| toggle() | ||
| onPress?.(e) | ||
| onClick?.(e) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const handleKeyDown = (e: KeyEvent) => { | ||
| if (e.keyCode === 32 || e.which === 32) { | ||
| toggle() | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+41
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🌐 Web query:
💡 Result: I couldn’t find a GitHub result matching all those terms. The closest match I found was the 🏁 Script executed: #!/bin/bash
set -u
printf '%s\n' '--- remotes and issue references ---'
git remote -v || true
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' '(^|[^0-9])`#39`([^0-9]|$)|issue.?39|focused tests|focused test' . || true
printf '%s\n' '--- changed component ---'
cat -n packages/engine/components/Checkbox.tsx
printf '%s\n' '--- repository test/config files ---'
git ls-files | rg '(^|/)(package\.json|.*(test|spec|jest|vitest|mocha|karma|playwright|testing).*)(/|$)' | head -200
printf '%s\n' '--- package scripts and test dependencies ---'
python3 - <<'PY'
import json
from pathlib import Path
for p in [Path('package.json'), Path('packages/engine/package.json')]:
if p.exists():
print(f'### {p}')
try:
d=json.loads(p.read_text())
print(json.dumps({'scripts': d.get('scripts', {}), 'devDependencies': d.get('devDependencies', {}), 'dependencies': d.get('dependencies', {})}, indent=2))
except Exception as e:
print(f'parse error: {e}')
PY
printf '%s\n' '--- concise full PR diff stat ---'
git diff --stat 1e40a7a25b2ac23c842ecd95932e4ca7e0b9a1dd 6519f714d99ce8cc88f41e29ec01f3a9d2f88981Repository: geastack/core Length of output: 11061 🏁 Script executed: #!/bin/bash
set -u
printf '%s\n' '--- development guidance ---'
cat -n docs/DEVELOPMENT.md | sed -n '20,70p'
printf '%s\n' '--- architecture guidance ---'
cat -n docs/ARCHITECTURE.md | sed -n '65,85p'
printf '%s\n' '--- issue `#39` from repository owner ---'
if command -v curl >/dev/null 2>&1; then
curl -L --fail --silent --show-error \
-H 'Accept: application/vnd.github+json' \
https://api.github.com/repos/geastack/core/issues/39 \
| python3 -c 'import json,sys; d=json.load(sys.stdin); print(json.dumps({k:d.get(k) for k in ("number","title","state","html_url","body","pull_request")}, indent=2))'
else
printf '%s\n' 'curl unavailable'
fiRepository: geastack/core Length of output: 4662 Add the focused Checkbox tests required by issue Issue 🤖 Prompt for AI Agents |
||
| const checkClass = [ | ||
| 'gea-checkbox', | ||
| disabled && 'gea-checkbox-disabled', | ||
| indeterminate && 'gea-checkbox-indeterminate', | ||
| !indeterminate && checked && 'gea-checkbox-checked', | ||
| !indeterminate && !checked && 'gea-checkbox-unchecked', | ||
| resolveClass(cls), | ||
| ] | ||
| .filter(Boolean) | ||
| .join(' ') | ||
|
|
||
| const mark = indeterminate ? '-' : checked ? '✓' : '' | ||
|
|
||
| const computedAriaLabel = ariaLabel || label || 'Checkbox' | ||
|
|
||
| return ( | ||
| <div | ||
| class={checkClass} | ||
| style={style} | ||
| onPress={handlePress} | ||
| onClick={handlePress} | ||
| onKeyDown={handleKeyDown} | ||
| role="checkbox" | ||
| aria-checked={indeterminate ? 'mixed' : checked} | ||
| aria-disabled={disabled} | ||
| aria-label={computedAriaLabel} | ||
| tabIndex={disabled ? -1 : 0} | ||
| > | ||
| <span class="gea-checkbox-mark">{mark}</span> | ||
| {label && <span class="gea-checkbox-label">{label}</span>} | ||
| </div> | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: geastack/core
Length of output: 2946
Document
Checkboxcallbacks and their actual event path.Issue
#39requires public API documentation, butpackages/engine/README.mdhas noCheckboxAPI section. Document all public props and state thatonPressruns through the nativeclickpath. It is not bound to a nativepressevent.Suggested fix
🤖 Prompt for AI Agents