{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "color-scheme-toggle",
  "title": "ColorSchemeToggle",
  "description": "The dark mode control: it switches the app between light, dark and the system's scheme, and keeps the choice.",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-color-scheme",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages",
    "@ouro/menu",
    "@ouro/segmented-control"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.tsx",
      "content": "\"use client\";\n\nimport { useState, type JSX, type Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useColorScheme, type ColorScheme } from \"@/registry/ouro/lib/ouro/color-scheme\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { Menu } from \"@/registry/ouro/components/ouro/menu/menu\";\nimport { SegmentedControl } from \"@/registry/ouro/components/ouro/segmented-control/segmented-control\";\n\n/**\n * The words for each scheme, for apps in other languages.\n *\n * @claim \"The words for each scheme, for\" registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx verify:fileLine(registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx, /labels=\\{\\{\\slight:\\s\"Hell\",\\sdark:\\s\"Dunkel\"/)\n */\nexport interface ColorSchemeLabels {\n  /** @default \"Light\" */\n  light?: string | undefined;\n  /** @default \"Dark\" */\n  dark?: string | undefined;\n  /** @default \"System\" */\n  system?: string | undefined;\n}\n\n/** Props for {@link ColorSchemeToggle}. */\nexport interface ColorSchemeToggleProps {\n  /**\n   * `menu` is an icon button, the sun or the moon of the scheme the page shows, that opens\n   * a menu of Light, Dark and System, for a header. `segmented` shows the three side by\n   * side, for a settings page.\n   * @default \"menu\"\n   * @claim \"`segmented` shows the three side by\" registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx verify:testExists(registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx::ColorSchemeToggle > shows the three side by side as a segmented control)\n   */\n  variant?: \"menu\" | \"segmented\" | (string & { 'Use \"menu\" (an icon button for a header) or \"segmented\" (for settings)': never }) | undefined;\n  /** Names the control for screen readers: the button's name, or the segmented control's label. @default \"Color scheme\" */\n  label?: string | undefined;\n  /**\n   * The words for each scheme.\n   *\n   * @claim \"The words for each scheme\" registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx verify:fileLine(registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx, /labels=\\{\\{\\slight:\\s\"Hell\",\\sdark:\\s\"Dunkel\"/)\n   */\n  labels?: ColorSchemeLabels | undefined;\n  /** Layout only: margins, grid placement (`ms-auto`). Appearance classes warn in development. */\n  className?: string | undefined;\n  /** Reaches the menu button, or the segmented control's group. */\n  ref?: Ref<HTMLElement> | undefined;\n\n  /** Not a prop. The toggle keeps the scheme itself, through `ColorSchemeProvider`; read it with `useColorScheme()`. */\n  value?: { 'The toggle keeps the scheme; read it with useColorScheme()': never };\n  /** Not a prop. The toggle applies the choice itself; to react to it, read `useColorScheme().resolved`. */\n  onChange?: { 'The toggle applies the choice; read useColorScheme().resolved to react to it': never };\n  /** Not a prop. Ouro UI says color scheme: `<ColorSchemeToggle />` with `ColorSchemeProvider` around the app. */\n  theme?: { 'Use <ColorSchemeToggle /> inside <ColorSchemeProvider>': never };\n}\n\nconst variants = [\"menu\", \"segmented\"] as const;\nconst order: readonly ColorScheme[] = [\"light\", \"dark\", \"system\"];\n\n/** The sun of a light page and the moon of a dark one, as lucide-react draws them. */\nfunction SchemeIcon({ dark }: { dark: boolean }): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-5\">\n      {dark ? (\n        <path d=\"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z\" />\n      ) : (\n        <>\n          <circle cx=\"12\" cy=\"12\" r=\"4\" />\n          <path d=\"M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41\" />\n        </>\n      )}\n    </svg>\n  );\n}\n\n/**\n * The dark mode control: it switches the app between light, dark and the system's scheme,\n * and keeps the choice. `variant=\"menu\"`, the default, is an icon button for a header: the sun\n * or the moon of the scheme the page shows, opening a menu of Light, Dark and System, the\n * current one checked. `variant=\"segmented\"` shows the three side by side, for a settings\n * page. Either way the choice applies at once, as the `.dark` class on `<html>` that\n * shadcn themes switch on, and is kept in `localStorage`.\n *\n * It works on its own, but the choice then shows only once the toggle changes it: wrap the\n * app in `ColorSchemeProvider` (`import { ColorSchemeProvider } from \"@/lib/ouro/color-scheme\"`),\n * which applies the kept choice on every page and follows the system's setting live, and put\n * `colorSchemeScript()` (from `@/lib/ouro/color-scheme-script`) in `<head>` so a reload never\n * flashes the wrong scheme; `ColorSchemeProvider`'s page shows both for React Router, Next.js\n * and Vite. For a control of your own, `useColorScheme()` gives the scheme and its setter.\n *\n * Use `Switch` with `useColorScheme()` instead for a plain dark-mode on/off, and\n * `SegmentedControl` for other choices of how a view looks.\n *\n * @group Actions\n * @see https://ui.ouroboros.bot/docs/color-scheme-toggle\n *\n * @example\n * <Navbar label=\"Main\" items={items} actions={<ColorSchemeToggle />} />\n * <ColorSchemeToggle variant=\"segmented\" label=\"Appearance\" />\n * @claim \"It works on its own, but\" registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx verify:testExists(registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx::ColorSchemeToggle > applies and keeps the choice, and shows the moon on a dark page)\n * @claim \"It works on its own, but\" registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx verify:testExists(registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx::ColorSchemeToggle > follows the system while the choice is System)\n * @claim \"` shows the three side by side, for\" registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx verify:testExists(registry/ouro/components/ouro/color-scheme-toggle/color-scheme-toggle.test.tsx::ColorSchemeToggle > shows the three side by side as a segmented control)\n */\nexport function ColorSchemeToggle(props: ColorSchemeToggleProps): JSX.Element {\n  const {\n    variant: variantProp = \"menu\",\n    label = \"Color scheme\",\n    labels,\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    value,\n    onChange,\n    theme,\n  } = props;\n  const variant = (variants as readonly string[]).includes(variantProp) ? (variantProp as (typeof variants)[number]) : \"menu\";\n  const { scheme, resolved, setScheme } = useColorScheme();\n  useAppearanceClassNameCheck(\n    \"ColorSchemeToggle\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; ColorSchemeToggle sets its own look from the theme`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"ColorSchemeToggle\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          variant !== variantProp && [`variant=\"${String(variantProp)}\" is not a variant; use \"menu\" or \"segmented\"`, '<ColorSchemeToggle variant=\"segmented\" />'],\n          value !== undefined && [\"value is not a prop; the toggle keeps the scheme\", \"const { scheme } = useColorScheme()\"],\n          onChange !== undefined && [\"onChange is not a prop; the toggle applies the choice\", \"const { resolved } = useColorScheme()\"],\n          theme !== undefined && [\"theme is not a prop\", \"<ColorSchemeToggle />\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const words: Record<ColorScheme, string> = { light: labels?.light ?? \"Light\", dark: labels?.dark ?? \"Dark\", system: labels?.system ?? \"System\" };\n  const options = order.map((option) => ({ value: option, label: words[option] }));\n  // The menu closes on a choice, as a menu of settings does on the Mac; the page has already switched behind it.\n  const [open, setOpen] = useState(false);\n  const choose = (next: string) => {\n    setScheme(next as ColorScheme);\n    setOpen(false);\n  };\n\n  return (\n    <div data-ouro=\"color-scheme-toggle\" data-variant={variant} className={cn(\"inline-flex\", className)}>\n      {variant === \"segmented\" ? (\n        <SegmentedControl ref={ref as Ref<HTMLDivElement>} label={label} hideLabel items={options} value={scheme} onValueChange={choose} />\n      ) : (\n        <Menu\n          open={open}\n          onOpenChange={setOpen}\n          trigger={\n            <Button\n              ref={ref as Ref<HTMLButtonElement>}\n              data-ouro-control=\"color-scheme-toggle\"\n              data-ouro-part=\"trigger\"\n              data-scheme={resolved}\n              variant=\"plain\"\n              tone=\"secondary\"\n              aria-label={label}\n              className=\"w-11 px-0\"\n            >\n              <SchemeIcon dark={resolved === \"dark\"} />\n            </Button>\n          }\n          items={[{ type: \"radio\", label, value: scheme, onValueChange: choose, options }]}\n        />\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/color-scheme-toggle/color-scheme-toggle.tsx"
    }
  ],
  "docs": "The dark mode control: it switches the app between light, dark and the system's scheme, and keeps the choice. Import: import { ColorSchemeToggle } from \"@/components/ouro/color-scheme-toggle/color-scheme-toggle\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, kbd, menu, segmented-control, 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/color-scheme-toggle.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}