Switch
A native switch with an animated thumb and label.
Installation
Import from the Reflow workspace package.
Playground
Open demoimport { Switch } from '@rtzll/reflow'
import { type Handle } from 'remix/component'
export function Example(handle: Handle) {
return () => (
<>
<Switch label="Notifications" name="notifications" defaultChecked />
</>
)
}Disabled
import { Switch } from '@rtzll/reflow'
import { type Handle } from 'remix/component'
export function Example(handle: Handle) {
return () => (
<>
<Switch label="Disabled option" disabled />
</>
)
}Controlled
import { Switch } from '@rtzll/reflow'
import { type Handle } from 'remix/component'
export function Example(handle: Handle) {
let enabled = false
const setEnabled = (value: boolean) => { enabled = value; handle.update() }
return () => (
<>
<Switch label="Notifications" checked={enabled} onCheckedChange={setEnabled} />
</>
)
}API Reference
Public props for the Reflow implementation. Native controls also accept their standard HTML attributes and Remix event mixes.
Switch
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | — | The `disabled` HTML attribute. |
name | string | — | The `name` HTML attribute. |
value | string | number | — | The `value` HTML attribute. |
size | "default" | "compact" | — | Control density or icon-button dimensions. |
checked | boolean | — | The `checked` HTML attribute. |
defaultChecked | boolean | — | The `defaultChecked` HTML attribute. |
defaultValue | string | number | — | The `defaultValue` HTML attribute. |
placeholder | string | — | The `placeholder` HTML attribute. |
required | boolean | — | The `required` HTML attribute. |
label | RemixNode | — | Accessible name or visible label for the control. |
onCheckedChange | ((checked: boolean, event: Event) => void) | — | Called when the checked state changes. |