Toggle
Native pressed button with controlled or local selection.
All components · Theme builder · Implementation source
Live preview
Install
netscript ui:add toggleUsage and examples
The preview runs this JSX with the installed components. Import any composed primitives from your UI directory.
import { useState } from 'preact/hooks';
import { Toggle } from '@app/components/ui/toggle.tsx';
export function Example() {
const [value, setValue] = useState('standard');
const [open, setOpen] = useState(false);
const [notice, report] = useState('');
return (<><div><Toggle aria-label="Pin order">Pin order</Toggle></div><p role="status">{notice}</p></>);
}Props
Generated from native deno doc --json --private over the shipped implementation. Compound component props retain their owning interface; native attributes pass through where declared.
| Owner | Prop | Type | Optional | Description |
|---|---|---|---|---|
ToggleProps | class | string | Yes | |
ToggleProps | variant | "default" | "outline" | Yes | |
ToggleProps | size | "sm" | "md" | "lg" | Yes | |
ToggleProps | selected | boolean | Yes | |
ToggleProps | defaultSelected | boolean | Yes | |
ToggleProps | onSelectedChange | (selected: boolean) => void | Yes | |
ToggleProps | state | "rest" | "hover" | "focus" | "disabled" | Yes | |
ToggleProps | label | boolean | Yes | |
ToggleProps | iconStart | boolean | Yes | |
ToggleProps | iconEnd | boolean | Yes | |
ToggleProps | iconStartGlyph | ComponentChildren | Yes | |
ToggleProps | iconEndGlyph | ComponentChildren | Yes |
ToggleProps extends Omit<JSX.ButtonHTMLAttributes<HTMLButtonElement>, "class" | "size">Keyboard
| Key | Action |
|---|---|
Enter/Space | Toggle aria-pressed |
Tokens
Semantic contract roles: border/default, radius/control, surface/selected, text/fg, text/muted.
CSS custom properties referenced directly: --ns-border, --ns-border-width, --ns-control-gap, --ns-control-height, --ns-control-height-sm, --ns-control-padding-x, --ns-fg, --ns-font-label, --ns-hover, --ns-leading-strong, --ns-muted-fg, --ns-radius-control, --ns-ring, --ns-selected, --ns-space-2, --ns-text-sm, --ns-text-strong, --ns-weight-strong.
Contract and compatibility
Accessibility pattern: WAI-ARIA guidance
- Native CSS pseudo-classes carry transient focus/hover; data-state also supports deliberate preview renders. Native button semantics preserve form behavior.
Design contract values marked planned are not implementation props. The props above describe what ships today.