feat(Switch): add on/off toggle control (16th atom, D21)#153
Merged
Conversation
Switch is the shadcn "Switch" contract over Base UI's Switch — a role="switch" button + hidden form input, Space to toggle, shared Button/Input/Checkbox focus ring. Second of the boolean form-control family, completing it next to Checkbox (D20): Checkbox -> Switch -> Radio. - Sibling API to Checkbox (checked/onCheckedChange/disabled), label-less (Escuela 1, D11): pair with <label htmlFor>; error via aria-invalid. No size axis in v1 (shadcn ships none). No indeterminate — a toggle is binary. - role="switch" (ARIA APG toggle), not a restyled checkbox. On track reuses neutral-900 (the Checkbox checked fill) for one "active control" color; off track neutral-300 with a white/neutral-500 thumb as the perceivable state indicator (WCAG 1.4.11). Geometry fully token-derived (40x24 track, 16px thumb, spacing-4 travel) — no hardcoded pixels, no icon dep (thumb is a span). - Stories (WithLabel + States matrix + Invalid), unit tests (8), NAMING-decisions D21, changeset minor. - Harness (rule #8): Settings form gains a "Send me a weekly digest" switch; settings.spec toggles it (+ label-click) — 25 e2e specs. Verified: build + dist-types, typecheck, lint, unit (Switch 8/8, 205 total), test:storybook a11y (102 stories, +3), build-storybook, e2e 25/25. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AgnovjGivnndpV7Yzt6AmY
|
Tip All tests passed and all changes approved!🟢 UI Tests: 3 visual and accessibility changes accepted as baselines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
Switch, the 16th Pharos atom — a single on/off toggle (the shadcn Switch contract) over Base UI'sSwitch. It completes the boolean form-control family opened byCheckbox(D20): Checkbox → Switch → Radio.Built as the exact sibling of the Checkbox (PR #148): same wrapping pattern, same
checked/onCheckedChange/disabledAPI, same label-less design, same two-stop focus ring.Design (D21)
role="switch"(ARIA APG toggle semantics), Space to toggle, hidden form input — not a restyled checkbox.indeterminate(Base UI'sSwitchexposes none either).<label htmlFor>. Error viaaria-invalid(inset 1pxsemantic.errorring — no layout shift). Nosizeaxis in v1 (shadcn ships none).neutral-900(the Checkbox checked fill) for one "active control" color across the family; off trackneutral-300with a white/neutral-500thumb as the perceivable state indicator (WCAG 1.4.11).spacing-10×spacing-6, 16px thumb =spacing-4,spacing-1padding → cleanspacing-4travel) — no hardcoded pixels (NON-NEGOTIABLE chore: scaffold pharos-react (phase 1B.1-1B.3) #1). No icon dependency (the thumb is a plain<span>).Changes
src/components/Switch.{tsx,module.css,stories.tsx}+tests/Switch.test.tsx(8 unit tests).src/index.ts; D21 entry inNAMING-decisions.md; minor changeset.settings.spec.tstoggles it (+ label-click).Verification (all local, green)
pnpm build(+verify:dist-types),pnpm typecheck,pnpm lintpnpm test— 205/205 (Switch 8/8)pnpm test:storybook(axe a11y) — 102/102 (+3 Switch stories)pnpm build-storybookpnpm --filter @examples/saas-demo test:e2e— 25/25 (incl.toggles the weekly-digest switch)Notes
Select 'closes on Escape…'flake is pre-existing (green in CI) — unrelated.🤖 Generated with Claude Code
https://claude.ai/code/session_01AgnovjGivnndpV7Yzt6AmY