{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-theme-switcher",
  "type": "registry:ui",
  "title": "react-tw/theme-switcher.tsx",
  "description": "Light / dark / system as an icon content switcher, as `<ui-theme-switcher>` (no Carbon counterpart; Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-position",
    "@kanok-ui/core-theme",
    "@kanok-ui/tw-content-switcher",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme"
  ],
  "files": [
    {
      "path": "src/react-tw/theme-switcher.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/theme-switcher.tsx",
      "content": "import type { ComponentProps, ReactNode } from 'react';\nimport type { Placement } from '../core/position.ts';\nimport { THEME_MODES, isThemeMode, prefersDark, themeOf, themePair, type ThemeChangeDetail, type ThemeMode } from '../core/theme.ts';\nimport { useThemeMode, type UseThemeModeOptions } from '@purpurabog/ui/headless';\nimport { ContentSwitcher, ContentSwitcherItem, type ContentSwitcherSize } from './content-switcher.tsx';\nimport { useTranslation } from './lib/i18n.ts';\n\nexport type { CarbonTheme, ThemeChangeDetail, ThemeMode } from '../core/theme.ts';\n/** The light / dark / system choice without the switcher (one page-wide store, shared with the headless layer). */\nexport { useThemeMode, type UseThemeModeOptions } from '@purpurabog/ui/headless';\n\nexport interface ThemeSwitcherProps extends UseThemeModeOptions, Omit<ComponentProps<'div'>, 'onChange' | 'children' | 'defaultValue'> {\n    /** The person picked a mode (with `value`, show it by passing it back). */\n    onChange?: (change: ThemeChangeDetail) => void;\n    size?: ContentSwitcherSize;\n    lowContrast?: boolean;\n    /** Where the icons' tooltips show (default top). */\n    tooltipPlacement?: Placement;\n    /** Names the group; default the translation of \"Theme\". */\n    'aria-label'?: string;\n    /** The language of the built-in names. */\n    lang?: string;\n}\n\n/** Carbon icons Light, Asleep (16) and Screen (32, drawn at 16). */\nconst ICONS: Record<ThemeMode, ReactNode> = {\n    light: (\n        <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n            <path d=\"M7.5 1h1v2.5h-1z\" />\n            <path d=\"M10.8 3.4h2.5v1h-2.5z\" transform=\"rotate(-45 12.041 3.923)\" />\n            <path d=\"M12.5 7.5H15v1h-2.5z\" />\n            <path d=\"M11.6 10.8h1v2.5h-1z\" transform=\"rotate(-45 12.075 12.04)\" />\n            <path d=\"M7.5 12.5h1V15h-1z\" />\n            <path d=\"M2.7 11.6h2.5v1H2.7z\" transform=\"rotate(-45 3.96 12.078)\" />\n            <path d=\"M1 7.5h2.5v1H1z\" />\n            <path d=\"M3.4 2.7h1v2.5h-1z\" transform=\"rotate(-45 3.925 3.961)\" />\n            <path d=\"M8 6c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2m0-1C6.3 5 5 6.3 5 8s1.3 3 3 3 3-1.3 3-3-1.3-3-3-3z\" />\n        </svg>\n    ),\n    dark: (\n        <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n            <path d=\"M7.2 2.3c-1 4.4 1.7 8.7 6.1 9.8h.2c-1.1 1.2-2.7 1.8-4.3 1.8h-.2C5.6 13.8 3 11 3.2 7.7c0-2.4 1.6-4.6 4-5.4M8 1C4.1 1.6 1.5 5.3 2.1 9.1c.6 3.3 3.4 5.8 6.8 5.9h.3c2.3 0 4.4-1.1 5.8-3 .2-.2.1-.6-.1-.7-.1-.1-.2-.1-.3-.1-3.9-.3-6.7-3.8-6.4-7.6.1-.6.2-1.2.4-1.8.1-.3 0-.6-.3-.7C8.1 1 8.1 1 8 1z\" />\n        </svg>\n    ),\n    system: (\n        <svg viewBox=\"0 0 32 32\" aria-hidden=\"true\">\n            <path d=\"M28 4H4a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h8v4H8v2h16v-2h-4v-4h8a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2ZM18 28h-4v-4h4Zm10-6H4V6h24Z\" />\n        </svg>\n    ),\n};\n\n/**\n * Light / dark / system as an icon content switcher, as `<ui-theme-switcher>` (no Carbon counterpart;\n * see useThemeMode for where the choice goes).\n */\nexport function ThemeSwitcher({ value, defaultValue, lightTheme, darkTheme, storageKey, onChange, size = 'md', lowContrast, tooltipPlacement = 'top', lang, ...rest }: Readonly<ThemeSwitcherProps>) {\n    const t = useTranslation(lang).common;\n    const [mode, setMode] = useThemeMode({ value, defaultValue, lightTheme, darkTheme, storageKey });\n    const names: Record<ThemeMode, string> = { light: t.themeLight, dark: t.themeDark, system: t.themeSystem };\n    return (\n        <ContentSwitcher\n            aria-label={t.theme}\n            {...rest}\n            size={size}\n            lowContrast={lowContrast}\n            selectedIndex={THEME_MODES.indexOf(mode)}\n            onChange={({ name }) => {\n                if (!isThemeMode(name)) return;\n                // with `value` the app shows it by passing it back; until then the theme stays\n                const theme = value ? themeOf(name, prefersDark(), themePair(lightTheme, darkTheme)) : setMode(name);\n                onChange?.({ mode: name, theme });\n            }}\n        >\n            {THEME_MODES.map((m) => (\n                <ContentSwitcherItem key={m} name={m} label={names[m]} iconOnly icon={ICONS[m]} tooltipPlacement={tooltipPlacement} />\n            ))}\n        </ContentSwitcher>\n    );\n}\n"
    }
  ]
}
