Switch
since v0.4.0Toggle switch — controlled via checked+onCheckedChange or uncontrolled via defaultChecked.
Forwards ref to the root <label>.
Install
Add the package and import the component.
pnpm add @hey-mike/tungstenpnpm add @hey-mike/tungstenimport { Switch } from '@hey-mike/tungsten';import { Switch } from '@hey-mike/tungsten';Preview
Same fixtures used by the visual-regression suite.
Usage
apps/docs/app/snapshots/switch/page.tsx
import { Switch } from '@hey-mike/tungsten';
import { VariantGrid } from '../_components/VariantGrid';
export default function SwitchSnapshot() {
return (
<VariantGrid
title="Switch"
variants={[
{ label: 'off', node: <Switch /> },
{ label: 'on', node: <Switch defaultChecked /> },
{ label: 'disabled off', node: <Switch disabled /> },
{ label: 'disabled on', node: <Switch defaultChecked disabled /> },
]}
/>
);
}
import { Switch } from '@hey-mike/tungsten';
import { VariantGrid } from '../_components/VariantGrid';
export default function SwitchSnapshot() {
return (
<VariantGrid
title="Switch"
variants={[
{ label: 'off', node: <Switch /> },
{ label: 'on', node: <Switch defaultChecked /> },
{ label: 'disabled off', node: <Switch disabled /> },
{ label: 'disabled on', node: <Switch defaultChecked disabled /> },
]}
/>
);
}
Props
Surface specific to <Switch />.
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | — | — |
| defaultChecked | boolean | false | — |
| onCheckedChange | ((checked: boolean) => void) | — | — |
| disabled | boolean | false | — |
| label | string | — | — |
| pending | boolean | — | When true, disables toggling and shows a spinner inside the knob.
Sets disabled on the native input element to suppress browser change
events. Visual disabled styling (opacity-50) only applies when the
disabled prop is also set. |