Switch button
Required44px-minimum interactive root.
button[role=switch]Fields & selection
A controlled switch for an immediate on/off setting.
ToggleTogglePropsConfigure the production component, inspect it at responsive widths, copy synchronized JSX, and share the exact state from one workspace.
This JSX stays synchronized with the controls and uses only public package APIs.
'use client';
import { useState } from 'react';
import { Toggle } from '@ai-created/ui';
export function Example() {
const [checked, setChecked] = useState(false);
return (
<Toggle
checked={checked}
onChange={setChecked}
label={"Enable notifications"}
/>
);
}
import { Toggle } from '@ai-created/ui';Replace the version placeholder with the release tag your product has reviewed.
npm install --install-links "git+https://github.com/TheMarco/ai-created-ui.git#vX.Y.Z"@import '@ai-created/ui/styles/tokens.css';
@tailwind base;
@tailwind components;
@tailwind utilities;module.exports = {
presets: [require('@ai-created/ui/tailwind-preset')],
content: [
'./src/**/*.{js,ts,jsx,tsx,mdx}',
'./node_modules/@ai-created/ui/src/**/*.{js,ts,jsx,tsx}',
],
};Named regions define what belongs to the component, what remains optional, and where semantic responsibility lives.
44px-minimum interactive root.
button[role=switch]40 × 24px visual state container and focus proxy.
16px moving state marker.
Visible switch name.
The Figma-equivalent asset model, auto-layout, resizing, properties, slots, content bounds, localization, and governance contract.
Asset kind
component
Design library name
Components/Forms/Toggle
Maturity
stable
Last reviewed
2026-08-29
Canvas applicability
Publish on, off, disabled, hover, focus, and pressed states with a label property.
| Property | Type | Default | Code mapping | Options or notes |
|---|---|---|---|---|
| OnRequired | boolean | false | checked | No additional constraint |
| Disabled | boolean | false | disabled | No additional constraint |
| LabelRequired | text | Enable notifications | label | No additional constraint |
Native button with switch semantics.
<button role="switch">40px by 24px state surface.
Internal span16px moving state indicator.
Internal spanSetting name.
labelOverflow: Wrap; never truncate.
The on and off consequence must be clear from the label and context.
Translatable: Label
Intrinsic control within a parent settings row.
No internal breakpoint
Accountable owner
Design systems form foundations owner
Canonical source: src/components/Toggle.tsx
These measurements and semantic tokens define the supported visual contract. Local overrides should preserve the same hierarchy and interaction cues.
Target minimum height
44px
Track
40 × 24px
Thumb
16 × 16px
Thumb position
3px off / 25px on
Label gap
10px
--color-action-primaryOn track fill and border.
--color-on-actionThumb fill.
--color-surface2Off track fill.
--color-control-border / --color-control-border-strongOff track and hover boundary.
--color-focusTrack focus outline.
--motion-fastTrack color and thumb movement.
A component is not complete until its passive, interactive, disabled, and exceptional states remain understandable in both themes.
Semantics, accessible naming, keyboard behavior, focus and announcements are implementation requirements, not optional documentation.
Use the public package API and preserve the controlled-state, native-attribute, and ref contracts described below.
import { Toggle } from '@ai-created/ui';Server Component compatible
<Toggle checked={enabled} onChange={setEnabled} label="Enable notifications" />These props and helpers are compatibility contracts. Changes require migration guidance and release notes.
| Prop | Type | Default | Contract |
|---|---|---|---|
| checked | boolean | required | Controlled switch state. |
| onChange | (checked: boolean) => void | required | Called when toggled. |
| label | string | required | Visible label. |
| disabled | boolean | false | Disables the switch. |
| className | string | undefined | Additional classes. |
These rules keep the component recognizable across products without preventing deliberate composition.
The component should be verified as rendered UI, an interaction model, an accessibility surface, and a theme-aware visual artifact.