feat(react): add the Switch primitive#7
Open
ivanbanov wants to merge 2 commits into
Open
Conversation
Adds @dunky.dev/switch (core machine) and @dunky.dev/react-switch (React binding). Anatomy: Switch root owning checked state, with Control (switch role) wrapping a visual Thumb, plus a Label whose press also toggles. A binary on/off control per the WAI-ARIA APG switch pattern: controlled/uncontrolled checked state, press/Space toggles, disabled gates user intent in the machine, and every part carries data-state. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Adds the Switch primitive as two packages:
@dunky.dev/switch— the framework-free core: a state machine (built on@dunky.dev/state-machine) owning the checked/unchecked graph, the disabled guard, and the connect that exposes parts and reactions.@dunky.dev/react-switch— the thin React binding rendering the compound component on top of the core connect.A switch is a binary on/off control that takes effect immediately (airplane mode, dark theme), following the WAI-ARIA APG switch pattern. Checked state is exposed both controlled and uncontrolled, and every toggle is reported back through
onCheckedChange.Anatomy
Behavior
role="switch"witharia-checkedalwaystrueorfalse— never mixed.toggleintent.<label>: it carries its own press binding and names the control througharia-labelledby, which only ever references a rendered Label.aria-disabled; controlled/programmatic changes still apply so consumer state never desyncs.data-state="checked" | "unchecked"anddata-disabledas styling/animation hooks.Test plan
pnpm test:cipnpm typecheckpnpm lintpnpm format:checkpnpm build🤖 Generated with Claude Code