{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "switch",
  "title": "Switch",
  "description": "A labeled on/off switch on the Field contract, with the label to its right: pass `label`, and `checked` with `onCheckedChange` (or `defaultChecked`).",
  "dependencies": [
    "@base-ui/react@^1.8.0"
  ],
  "registryDependencies": [
    "@ouro/field",
    "@ouro/lib-control-ref",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-touch-target",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-field"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/switch/switch-styles.ts",
      "content": "export { thumbClass, trackClass };\n\n// Class strings for Switch, apart from the component so its file exports only components\n// (React Fast Refresh). Class strings are literal so the app's Tailwind finds them when it\n// compiles.\n\n/**\n * The track: 40x24 on touch screens, beside a 24px label line, stepping down to 36x20 beside\n * a 20px line from the `sm` breakpoint with a fine pointer, so a landscape phone keeps the\n * phone size. Off, it is an outline: a `muted-foreground` border that keeps 3:1 against the\n * page (WCAG 1.4.11) around the page color. On, it fills with the primary color, so on and\n * off differ by fill, not only by hue. Its hit area is 44px on touch screens.\n * `--ouro-switch-thumb` is the thumb's size at each density.\n *\n * @internal\n * @claim \"Off, it is an outline: a\" registry/ouro/components/ouro/switch/switch.test.tsx verify:testExists(registry/ouro/components/ouro/switch/switch.test.tsx::Switch look and motion > tells on from off without hue, with an off outline at 3:1 against the page, in light and dark)\n * @claim \"Its hit area is 44px on\" registry/ouro/components/ouro/switch/switch.touch.test.tsx verify:testExists(registry/ouro/components/ouro/switch/switch.touch.test.tsx::gives the switch a 44px hit area, though it is 24px tall)\n * @claim \"The track: 40x24 on touch screens\" registry/ouro/components/ouro/switch/switch.touch.test.tsx verify:testExists(registry/ouro/components/ouro/switch/switch.touch.test.tsx::keeps the phone size and 16px label on a landscape phone, past the sm breakpoint)\n * @claim \"Off, it is an outline\" https://www.w3.org/TR/WCAG22/#non-text-contrast verify:urlOk(https://www.w3.org/TR/WCAG22/#non-text-contrast)\n * @claim \"`--ouro-switch-thumb` is the thumb's size at\" registry/ouro/components/ouro/switch/switch-styles.ts verify:fileLine(registry/ouro/components/ouro/switch/switch-styles.ts, /\\[--ouro-switch-thumb:calc\\(var\\(--spacing\\)\\*5\\)\\]\\ssm:pointer-fine:\\[--ouro-switch-thumb:calc\\(var\\(--spacing\\)\\*4\\)\\]/)\n */\nconst trackClass =\n  \"group relative m-0 box-border inline-flex h-6 w-10 shrink-0 items-center p-0 sm:pointer-fine:h-5 sm:pointer-fine:w-9 \" +\n  \"[--ouro-switch-thumb:calc(var(--spacing)*5)] sm:pointer-fine:[--ouro-switch-thumb:calc(var(--spacing)*4)] \" +\n  \"[--corner-shape:round] [corner-shape:round] rounded-full border-2 border-solid border-muted-foreground bg-transparent data-checked:border-primary data-checked:bg-primary \" +\n  \"transition-[background-color,border-color] duration-(--ouro-duration-fast) ease-[ease] \" +\n  \"cursor-default select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"aria-invalid:ring-2 aria-invalid:ring-destructive \" +\n  \"data-disabled:cursor-not-allowed data-disabled:opacity-50\";\n\n/**\n * The thumb slides 16px in the press duration when the switch turns on or off. While the\n * pointer is down it stretches 4px toward the way it will travel: toward the inline end when\n * off, toward the start when on (right and left in a left-to-right page). With reduced motion it\n * neither slides nor stretches.\n * It is Liquid Glass: a light tint of white, a thin rim and hairline and the theme's small\n * shadow; with reduced transparency or more contrast it\n * is a solid surface. The track's fill tells on from off.\n *\n * @internal\n * @claim \"The thumb slides 16px in the\" registry/ouro/components/ouro/switch/switch.test.tsx verify:testExists(registry/ouro/components/ouro/switch/switch.test.tsx::Switch look and motion > fills the track with the primary color and moves the thumb to the end when on)\n * @claim \"While the pointer is down it\" registry/ouro/components/ouro/switch/switch.test.tsx verify:testExists(registry/ouro/components/ouro/switch/switch.test.tsx::Switch look and motion > widens the thumb toward its travel while the pointer is down)\n * @claim \"The thumb slides 16px in the\" registry/ouro/components/ouro/switch/switch.test.tsx verify:testExists(registry/ouro/components/ouro/switch/switch.test.tsx::Switch look and motion > stretches by scaling and slides on translate, never by animating its width, with one timing for both)\n */\nconst thumbClass =\n  \"pointer-events-none block size-(--ouro-switch-thumb) [--corner-shape:round] [corner-shape:round] rounded-full \" +\n  // The Quiet switch's lens: the glass tint over the track with a rim inside, a hairline outside and the theme's small shadow.\n  // No backdrop filter, which made every large repaint slower in WebKit without a GPU (ourostack/ouro-ui#728): the thumb only\n  // ever lies over its own track, so the lens is drawn. Off, the tint shows the page through the outlined track, with the\n  // outline's colour fading in from the near edge as the filter's blur drew it; on, the tint is mixed into the primary fill,\n  // saturated by the matrix saturate(1.6) applies.\n  \"bg-[color-mix(in_oklab,var(--ouro-glass)_var(--ouro-glass-tint),transparent)] \" +\n  \"[box-shadow:inset_0_0_0_.75px_var(--ouro-glass-rim),0_0_0_.5px_var(--ouro-glass-edge),var(--shadow-sm)] \" +\n  \"bg-[image:linear-gradient(to_right,color-mix(in_oklab,var(--muted-foreground)_14%,transparent),transparent_85%)] \" +\n  \"rtl:bg-[image:linear-gradient(to_left,color-mix(in_oklab,var(--muted-foreground)_14%,transparent),transparent_85%)] \" +\n  \"data-checked:bg-none data-checked:bg-[color-mix(in_srgb,var(--ouro-glass)_calc(var(--ouro-glass-tint)*2),var(--primary))] \" +\n  \"supports-[color:color(from_red_srgb_r_g_b)]:data-checked:bg-[color-mix(in_srgb,var(--ouro-glass)_calc(var(--ouro-glass-tint)*2),color(from_var(--primary)_srgb_clamp(0,1.4722*r_-_0.429*g_-_0.0432*b,1)_clamp(0,-0.1278*r_+_1.171*g_-_0.0432*b,1)_clamp(0,-0.1278*r_-_0.429*g_+_1.5568*b,1)))] \" +\n  \"[@media(prefers-reduced-transparency:reduce)]:bg-(--ouro-glass-solid) [@media(prefers-reduced-transparency:reduce)]:bg-none \" +\n  \"contrast-more:bg-(--ouro-glass-solid) contrast-more:bg-none \" +\n  \"forced-colors:bg-[ButtonText] forced-colors:data-checked:bg-[HighlightText] forced-colors:bg-none \" +\n  // Translate and origin have no logical form, so a right-to-left page reverses them: the thumb\n  // starts at the inline start and slides toward the inline end either way.\n  \"translate-x-0 data-checked:translate-x-4 rtl:data-checked:-translate-x-4 \" +\n  \"origin-left rtl:origin-right \" +\n  \"motion-safe:[transition:translate_var(--ouro-duration-press)_var(--ouro-ease-out),scale_var(--ouro-duration-press)_var(--ouro-ease-out)] \" +\n  \"motion-safe:group-active:not-data-disabled:scale-x-[1.2] \" +\n  \"motion-safe:group-active:not-data-disabled:data-checked:translate-x-3 rtl:motion-safe:group-active:not-data-disabled:data-checked:-translate-x-3\";\n",
      "type": "registry:ui",
      "target": "@components/ouro/switch/switch-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/switch/switch.tsx",
      "content": "\"use client\";\n\nimport { Switch as BaseSwitch } from \"@base-ui/react/switch\";\nimport type { JSX, ReactNode, Ref } from \"react\";\nimport { Field } from \"@/registry/ouro/components/ouro/field/field\";\nimport { contractWarnings } from \"@/registry/ouro/components/ouro/field/field-styles\";\nimport { devThrow } from \"@/registry/ouro/lib/ouro/dev\";\nimport { controlRef } from \"@/registry/ouro/lib/ouro/control-ref\";\nimport { TouchTarget } from \"@/registry/ouro/lib/ouro/touch-target\";\nimport { FieldOwnerContext, useField, type ReadonlyErrorMessages } from \"@/registry/ouro/lib/ouro/use-field\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { thumbClass, trackClass } from \"@/registry/ouro/components/ouro/switch/switch-styles\";\n\n/** Props for {@link Switch}. */\nexport interface SwitchProps {\n  /**\n   * The setting it turns on, shown to the right of the switch and read as its name.\n   * Required: every control needs a name. To hide it visually, keep it and add `hideLabel`.\n   * @claim \"Required: every control needs a name\" registry/ouro/components/ouro/switch/switch.test-d.ts verify:fileLine(registry/ouro/components/ouro/switch/switch.test-d.ts, /expectTypeOf<\\{\\schecked:\\strue\\s\\}>\\(\\)\\.not\\.toExtend<SwitchProps>/)\n   */\n  label: string;\n  /** Hides the label visually; screen readers still read it as the switch's name. */\n  hideLabel?: boolean | undefined;\n  /** Supporting text under the label, read after it through `aria-describedby`. */\n  description?: ReactNode | undefined;\n  /**\n   * What is wrong, from your server action or client check, shown under the label; the\n   * switch gets `aria-invalid`. A message is text or a React node (one with a link); an empty string or array means valid.\n   */\n  error?: ReadonlyErrorMessages | undefined;\n  /** The switch must be on to submit the form: it gets `required` and `aria-required`, and the label a marker. */\n  required?: boolean | undefined;\n  /** Disables the switch and fades it. */\n  disabled?: boolean | undefined;\n  /** The form field name it submits under when on. */\n  name?: string | undefined;\n  /** What it submits when on (`on` without one). */\n  value?: string | undefined;\n  /** Whether it is on, for a controlled switch; pair it with `onCheckedChange`. */\n  checked?: boolean | undefined;\n  /** Whether it starts on, for an uncontrolled switch. */\n  defaultChecked?: boolean | undefined;\n  /** Called with the new state when it turns on or off. */\n  onCheckedChange?: ((checked: boolean) => void) | undefined;\n  /** Shows the state but ignores clicks and keys, unlike `disabled`, which also fades it. */\n  readOnly?: boolean | undefined;\n  /**\n   * Layout only: margins, width, grid placement (`mt-4`, `col-span-2`). Appearance classes\n   * warn in development; style switches in your theme.\n   */\n  className?: string | undefined;\n  /** The track element, a `<button role=\"switch\">`, which the label names with `for`. */\n  ref?: Ref<HTMLElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `onCheckedChange`, which gets the new state: `onCheckedChange={setOn}`. */\n  onChange?: { 'Use onCheckedChange={setChecked}': never };\n  /** Not a prop. Ouro UI uses `checked`: `<Switch checked={on}>`. */\n  isChecked?: { 'Use <Switch checked={on}>': never };\n  /** Not a prop. A switch's starting state is `defaultChecked`: `<Switch defaultChecked>`. */\n  defaultValue?: { 'Use <Switch defaultChecked>': never };\n  /** Not a prop. Ouro UI uses `error`: `<Switch error=\"Required.\">`. */\n  errorMessage?: { 'Use <Switch error=\"Required.\">': never };\n  /** Not a prop. Ouro UI uses `description`: `<Switch description=\"...\">`. */\n  helperText?: { 'Use <Switch description=\"...\">': never };\n  /** Not a prop. `error` marks the switch invalid: `<Switch error=\"What is wrong\">`. */\n  isInvalid?: { 'Use <Switch error=\"What is wrong\">': never };\n  /** Not a prop. `error` marks the switch invalid: `<Switch error=\"What is wrong\">`. */\n  invalid?: { 'Use <Switch error=\"What is wrong\">': never };\n  /** Not a prop. Ouro UI uses `required`: `<Switch required>`. */\n  isRequired?: { 'Use <Switch required>': never };\n  /** Not a prop. Ouro UI uses `disabled`: `<Switch disabled>`. */\n  isDisabled?: { 'Use <Switch disabled>': never };\n}\n\n/** Field's messages and root name Switch, and put the switch before its label. */\nconst owner = { name: \"Switch\", data: \"switch\", layout: \"inline\" } as const;\n/** Marks the hidden input Base UI submits the switch with. */\nconst markInput = controlRef(\"switch\", \"hidden-input\");\n\n/** The track and thumb, inside the Field: they take their name, description and error ids from the field. */\nfunction SwitchTrack(props: {\n  value: string | undefined;\n  checked: boolean | undefined;\n  defaultChecked: boolean | undefined;\n  onCheckedChange: ((checked: boolean) => void) | undefined;\n  readOnly: boolean | undefined;\n  ref: Ref<HTMLElement> | undefined;\n}): JSX.Element {\n  const { onCheckedChange, ...rest } = props;\n  const field = useField()!;\n  return (\n    <BaseSwitch.Root\n      {...rest}\n      // A real button, so the label's `for` names it and not the hidden input: its label finds one control.\n      nativeButton\n      render={<button />}\n      inputRef={markInput}\n      data-ouro-control=\"switch\"\n      data-ouro-part=\"track\"\n      onCheckedChange={onCheckedChange && ((checked) => onCheckedChange(checked))}\n      required={field.required}\n      // Set here, not left to Base UI's effects, so the server HTML names and describes the switch.\n      aria-labelledby={field.labelId}\n      aria-describedby={field.describedBy}\n      aria-invalid={field.invalid || undefined}\n      className={trackClass}\n    >\n      <TouchTarget />\n      <BaseSwitch.Thumb data-ouro-switch-thumb=\"\" className={thumbClass} />\n    </BaseSwitch.Root>\n  );\n}\n\n/**\n * A labeled on/off switch on the Field contract, with the label to its right: pass `label`,\n * and `checked` with `onCheckedChange` (or `defaultChecked`). Clicking the label or pressing\n * Space flips it; the thumb slides and stretches while pressed. With\n * `name`, a switch that is on submits `name=value` with its form.\n *\n * Use it for a setting that takes effect at once. Use `Checkbox` instead for a choice that\n * applies when a form is submitted, such as accepting terms.\n *\n * @group Forms\n * @see https://ui.ouroboros.bot/docs/switch\n *\n * @example\n * <Switch label=\"Wi-Fi\" checked={wifi} onCheckedChange={setWifi} />\n * <Switch label=\"Nightly backups\" name=\"backups\" description=\"At 2 a.m.\" defaultChecked />\n */\nexport function Switch(props: SwitchProps): JSX.Element {\n  const {\n    label,\n    hideLabel,\n    description,\n    error,\n    required,\n    disabled,\n    name,\n    value,\n    checked,\n    defaultChecked,\n    onCheckedChange,\n    readOnly,\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    onChange,\n    isChecked,\n    defaultValue,\n    errorMessage,\n    helperText,\n    isInvalid,\n    invalid,\n    isRequired,\n    isDisabled,\n  } = props;\n  const group = useField()?.group;\n  if (group !== undefined) {\n    const choice = group === \"RadioGroup\" ? \"Radio\" : \"Checkbox\";\n    devThrow(\n      \"Switch\",\n      `a ${group} takes ${choice} choices`,\n      process.env.NODE_ENV !== \"production\"\n        ? `<${choice} value=\"${String(label).toLowerCase()}\" label=\"${label}\" />, or put the Switch outside the group`\n        : /* istanbul ignore next @preserve -- production only */ \"\",\n    );\n  }\n\n  useDevWarnings(\n    \"Switch\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          ...contractWarnings(\"Switch\", { errorMessage, helperText, isInvalid, invalid, isRequired, isDisabled }),\n          onChange !== undefined && [\"onChange is not a prop; onCheckedChange gets the new state\", \"<Switch onCheckedChange={(checked) => setOn(checked)}>\"],\n          isChecked !== undefined && [\"isChecked is not a prop\", `<Switch checked={${String(isChecked)}}>`],\n          defaultValue !== undefined && [\"defaultValue is not a prop; a switch starts on with defaultChecked\", \"<Switch defaultChecked>\"],\n          checked !== undefined && !onCheckedChange && !readOnly && [\"checked without onCheckedChange never changes\", \"<Switch checked={on} onCheckedChange={setOn}>, or defaultChecked\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  return (\n    <FieldOwnerContext.Provider value={owner}>\n      <Field\n        label={label}\n        hideLabel={hideLabel}\n        description={description}\n        error={error}\n        required={required}\n        disabled={disabled}\n        name={name}\n        className={className}\n      >\n        <SwitchTrack value={value} checked={checked} defaultChecked={defaultChecked} onCheckedChange={onCheckedChange} readOnly={readOnly} ref={ref} />\n      </Field>\n    </FieldOwnerContext.Provider>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/switch/switch.tsx"
    }
  ],
  "docs": "A labeled on/off switch on the Field contract, with the label to its right: pass `label`, and `checked` with `onCheckedChange` (or `defaultChecked`). Import: import { Switch } from \"@/components/ouro/switch/switch\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: field, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/switch.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}