# Toggle

Native pressed button with controlled or local selection.

[All components](https://rickylabs.github.io/netscript/design-system/components/) · [Theme builder](https://rickylabs.github.io/netscript/create/) · [Implementation source](https://github.com/rickylabs/netscript/blob/main/packages/fresh-ui/registry/components/ui/toggle.tsx)

## Live preview

[Open live toggle preview](https://rickylabs.github.io/netscript/assets/fresh-ui/preview/?component=toggle&theme=studio-utility)

## Install

```bash
netscript ui:add toggle
```

## Usage and examples

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

```tsx
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 |  |

```typescript
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](https://www.w3.org/WAI/ARIA/apg/patterns/button/)

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