Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 1.38 KB

switch.md

File metadata and controls

36 lines (25 loc) · 1.38 KB

Switch

Turns a setting on or off at once.

Example

import { Field, Switch } from "@usememos/ui";

<Field.Root>
  <Field.Label>
    <Switch checked={publicByDefault} onCheckedChange={save} /> Make new notes public
  </Field.Label>
</Field.Root>

Props

interface SwitchProps extends BaseSwitch.Root.Props {
  size?: Size; // 16, 18, 20px tall
}

Wraps Base UI's Switch root with its thumb built in: checked, defaultChecked, onCheckedChange, disabled, name pass through.

Rules

  • Name it with a Field.Label around it, or aria-label.
  • Use it where each change saves at once (settings pages). In a form with a Save button, use Checkbox.

Style

  • A pill well with a round knob and a quiet edge at rest; the well fills with primary when on. The track keeps its quiet boundary and fill on hover. Keyboard focus uses a fine 1px contrasting boundary.
  • Height = checkbox box + 2px; width = height × 1.7.
  • The knob is flat text, inset 2px; on-primary when on. Only its position slides with ease-settle when the state changes, without growing on press; all colors change immediately. Under reduced motion it has no transition. Disabled switches keep the knob position, but use a quiet edge and a text-disabled knob. The track keeps the same dimensions and margins for mouse and touch input.