Skip to main content
NetScriptdocs Search docs ⌘K v0.0.9
Browse documentation

Toggle

Native pressed button with controlled or local selection.

All components · Theme builder · Implementation source

Live preview

Open live toggle preview

Install

Shell
netscript ui:add toggle

Usage and examples

The preview runs this JSX with the installed components. Import any composed primitives from your UI directory.

TypeScript
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.

OwnerPropTypeOptionalDescription
TogglePropsclassstringYes
TogglePropsvariant"default" | "outline"Yes
TogglePropssize"sm" | "md" | "lg"Yes
TogglePropsselectedbooleanYes
TogglePropsdefaultSelectedbooleanYes
TogglePropsonSelectedChange(selected: boolean) => voidYes
TogglePropsstate"rest" | "hover" | "focus" | "disabled"Yes
TogglePropslabelbooleanYes
TogglePropsiconStartbooleanYes
TogglePropsiconEndbooleanYes
TogglePropsiconStartGlyphComponentChildrenYes
TogglePropsiconEndGlyphComponentChildrenYes
TypeScript
ToggleProps extends Omit<JSX.ButtonHTMLAttributes<HTMLButtonElement>, "class" | "size">

Keyboard

KeyAction
Enter/SpaceToggle 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.

Search all documentation

Type a term to search the documentation.