Switch
A headless Switch (toggle) component for ReactLynx. It provides unstyled primitives for toggle states.You can check the source code to understand how it works, and you're welcome to submit PRs to enhance its capabilities.
Basic Usage
The basic usage of <Switch>
Examples
Theme Control
Use a controlled Switch (checked + onChange) to drive page theme, and let token changes update the Switch visuals automatically. The example also shows a composed ThemedSwitch wrapper alongside part-level primitives; see Styling & Theming.
Structure
Component API
Switch
Props for the Switch component.
checked is provided, the component is controlled and defaultChecked is ignored.true, the Switch cannot be toggled.State-based styling & rendering
This component exposes runtime states through one or both of the following channels. The table lists only the channels available for each state:
- UI variant class — when supported, a class like
ui-<state>is toggled on the corresponding component node for selectors such as.ui-<state> { ... }. - Render-prop field — when supported and
childrenis a function, the state is passed in viachildren({ <state>: boolean, ... })for runtime-driven rendering.
UI variants applied by Switch based on its render state.
| Class Name | Render Prop | Type | Description |
|---|---|---|---|
| ui-active | active | boolean | Whether the Switch is active (pressed or being interacted with). Applied when `status.active` is true. |
| ui-checked | checked | boolean | Whether the Switch is currently checked. Applied when `status.checked` is true. |
| ui-disabled | disabled | boolean | Whether the Switch is disabled. Applied when `status.disabled` is true. |
SwitchTrack
The track of the Switch. Represents the background area on which the thumb slides. Can also be used for pressed overlays or state decorations.
UI variants applied by SwitchTrack.
| Class Name | Description |
|---|---|
| ui-active | Whether the Switch is active (pressed or being interacted with). Applied when `status.active` is true. |
| ui-checked | Whether the Switch is currently checked. Applied when `status.checked` is true. |
| ui-disabled | Whether the Switch is disabled. Applied when `status.disabled` is true. |
SwitchThumb
The thumb of the Switch. The draggable/clickable handle that toggles the state.
UI variants applied by SwitchThumb.
| Class Name | Description |
|---|---|
| ui-active | Whether the Switch is active (pressed or being interacted with). Applied when `status.active` is true. |
| ui-checked | Whether the Switch is currently checked. Applied when `status.checked` is true. |
| ui-disabled | Whether the Switch is disabled. Applied when `status.disabled` is true. |