{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "components-theme-toggler",
  "type": "registry:component",
  "title": "Theme toggler",
  "description": "The control that switches light and dark",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-icons.json",
    "https://gpuixui.sudokw.com/gpuix-motion.json",
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/components/src/internal/button.tsx",
      "target": "@ui/gpuixui/components/internal/button.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { Props } from \"@gpuix/react\";\nimport type { ReactNode } from \"react\";\nimport {\n  Button as PrimitiveButton,\n  IconButton as PrimitiveIconButton,\n  actionOnColor as primitiveActionOnColor,\n  type ButtonVariant as PrimitiveVariant,\n} from \"../../primitives/button.js\";\nimport { cn } from \"../../tw/index.js\";\nimport * as Schema from \"effect/Schema\";\nimport type { Theme } from \"./theme.js\";\n\nconst ButtonVariants = Schema.Literals([\n  \"primary\",\n  \"secondary\",\n  \"ghost\",\n  \"danger\",\n  \"link\",\n]);\n\nexport type ButtonVariant = typeof ButtonVariants.Type;\n\nexport type ButtonSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface ButtonProps extends Props {\n  readonly variant?: ButtonVariant;\n\n  readonly size?: ButtonSize;\n\n  readonly disabled?: boolean;\n\n  readonly loading?: boolean;\n\n  readonly loadingLabel?: string;\n\n  readonly reducedMotion?: boolean;\n\n  readonly leading?: ReactNode;\n\n  readonly trailing?: ReactNode;\n}\n\nexport interface IconButtonProps extends Props {\n  readonly label: string;\n\n  readonly size?: ButtonSize;\n  readonly disabled?: boolean;\n}\n\ninterface Look {\n  readonly variant: PrimitiveVariant;\n  readonly className: string;\n}\n\nconst LOOKS: Readonly<Record<ButtonVariant, Look>> = {\n  primary: { variant: \"primary\", className: \"\" },\n  secondary: { variant: \"secondary\", className: \"border border-strong\" },\n  ghost: { variant: \"ghost\", className: \"\" },\n  danger: { variant: \"destructive\", className: \"\" },\n\n  link: { variant: \"link\", className: \"underline underline-offset-4\" },\n};\n\nconst lookOf = (variant: unknown): Look =>\n  LOOKS[Schema.is(ButtonVariants)(variant) ? variant : \"secondary\"];\n\nexport const actionOnColor = (theme: Theme, variant: ButtonVariant): string =>\n  primitiveActionOnColor(theme, lookOf(variant).variant);\n\nexport const Button = ({\n  variant = \"secondary\",\n  size = \"md\",\n  disabled = false,\n  onClick,\n  style,\n  \"aria-label\": ariaLabel,\n  ...rest\n}: ButtonProps) => {\n  const look = lookOf(variant);\n  return (\n    <PrimitiveButton\n      {...rest}\n      variant={look.variant}\n      size={size}\n      disabled={disabled}\n      label={ariaLabel}\n      className={cn(look.className)}\n      onActivate={onClick}\n      style={style}\n    />\n  );\n};\n\nexport const IconButton = ({\n  label,\n  size = \"md\",\n  disabled = false,\n  onClick,\n  style,\n  children,\n  ...rest\n}: IconButtonProps) => (\n  <PrimitiveIconButton\n    {...rest}\n    icon={children}\n    variant=\"ghost\"\n    size={size}\n    disabled={disabled}\n    label={label}\n    className=\"text-muted-foreground hover:text-foreground\"\n    onActivate={onClick}\n    style={style}\n  />\n);\n"
    },
    {
      "path": "packages/components/src/internal/presence.tsx",
      "target": "@ui/gpuixui/components/internal/presence.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { MotionProps } from \"@gpuix/react\";\nimport {\n  delayedTiming,\n  exitWindowMs,\n  fadeFrom,\n  fadeFromAnchor,\n  fadeFromSide,\n  fadeOnly,\n  presenceMotion as motionOfPresence,\n  presenceStyle,\n  transitionWindowMs,\n  type PresenceFrames,\n  type PresenceHitRule,\n  type PresenceSide,\n  type PresenceTiming,\n  type PresenceTransition,\n} from \"../../motion/presence.js\";\nimport {\n  MotionProvider,\n  useMotionPreference,\n  useSurfacePresence,\n  useSurfaceTiming,\n  type MotionProviderProps,\n  type SurfacePresence,\n} from \"../../motion/react/presence.js\";\nimport {\n  motionTiming,\n  type MotionLevel,\n  type MotionPreference,\n} from \"../../motion/timing.js\";\n\nexport { MotionProvider, useMotionPreference, type MotionProviderProps };\n\nexport type SurfaceFrames = PresenceFrames;\n\nexport type SurfaceTiming = PresenceTiming;\n\nexport type PanelSide = PresenceSide;\n\nexport {\n  delayedTiming,\n  exitWindowMs,\n  fadeFrom,\n  fadeFromAnchor,\n  fadeFromSide,\n  fadeOnly,\n  presenceStyle,\n  transitionWindowMs,\n};\nexport type { PresenceHitRule };\n\nexport { useSurfacePresence, useSurfaceTiming, type SurfacePresence };\n\nexport const moveTiming = (\n  level: MotionLevel,\n  preference: MotionPreference,\n): PresenceTransition => motionTiming(level, { phase: \"standard\", preference });\n\nexport const useMoveTiming = (level: MotionLevel): PresenceTransition =>\n  moveTiming(level, useMotionPreference());\n\nexport const presenceMotion = (\n  frames: SurfaceFrames,\n  presence: SurfacePresence,\n  timing: SurfaceTiming = presence.timing,\n): MotionProps => motionOfPresence(frames, presence.present, timing);\n\nexport const PresenceShield = ({ present }: { readonly present: boolean }) =>\n  present ? null : (\n    <div\n      testId=\"presence-shield\"\n      style={{ position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 }}\n    />\n  );\n\nexport const presenceTabStop = (\n  present: boolean,\n): { readonly tabIndex?: number } => (present ? {} : { tabIndex: -1 });\n"
    },
    {
      "path": "packages/components/src/internal/recipe.ts",
      "target": "@ui/gpuixui/components/internal/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { createRecipeCache } from \"../../tw/index.js\";\nimport type { Theme } from \"./theme.js\";\n\nexport const recipeStyle: (recipe: string, theme: Theme) => StyleDesc =\n  createRecipeCache(512);\n"
    },
    {
      "path": "packages/components/src/internal/theme.ts",
      "target": "@ui/gpuixui/components/internal/theme.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport * as Schema from \"effect/Schema\";\nimport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  brandTextOn,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  pointerWash,\n  selectionOn,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n  type BoxShadow,\n  type ElevationLevel,\n  type FindHighlightSource,\n  type NativeTextFill,\n  type PlatformName,\n  type PointerWashSurface,\n  type StatusTone,\n  type SyntaxColors,\n  type SyntaxRole,\n  type TextRole,\n  type Theme,\n  type ThemeColors,\n} from \"../../tokens/index.js\";\n\nexport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n};\nexport type {\n  BoxShadow,\n  ElevationLevel,\n  FindHighlightSource,\n  NativeTextFill,\n  PlatformName,\n  StatusTone,\n  SyntaxColors,\n  SyntaxRole,\n  TextRole,\n  Theme,\n};\nexport { ThemeProvider, useTheme } from \"../../tokens/react.js\";\n\nexport const keyboardRing = (theme: Theme, invalid = false): StyleDesc =>\n  controlFocusRing(theme, { invalid }) ?? {};\n\nexport interface ControlRingState {\n  readonly disabled?: boolean;\n\n  readonly invalid?: boolean;\n}\n\nexport const controlRing = (\n  theme: Theme,\n  state: ControlRingState = {},\n): StyleDesc => controlFocusRing(theme, state) ?? {};\n\nexport const pressWash = (theme: Theme, replaced: PointerWashSurface): string =>\n  pointerWash(theme, \"active\", replaced) ?? theme.colors.active;\n\nexport const selectionWash = (theme: Theme): StyleDesc => ({\n  selectionColor: theme.colors.selection,\n});\n\nexport const keepContent: StyleDesc = { keyboardFocusDim: false };\n\nexport const disabledFade = (\n  disabled: boolean,\n): { readonly opacity: number } | undefined =>\n  disabled ? { opacity: disabledOpacity } : undefined;\n\nconst Tones = Schema.Literals([\"info\", \"success\", \"warning\", \"danger\"]);\n\nexport type Tone = typeof Tones.Type;\n\nexport const toneOf = (value: unknown): Tone =>\n  Schema.is(Tones)(value) ? value : \"info\";\n\nexport interface ToneStyle {\n  readonly fg: string;\n  readonly bg: string;\n  readonly border: string;\n}\n\nconst TOKEN_TONE: Readonly<Record<Tone, StatusTone>> = {\n  info: \"info\",\n  success: \"success\",\n  warning: \"warning\",\n  danger: \"destructive\",\n};\n\nexport const tone = (theme: Theme, value: Tone): ToneStyle => {\n  const { background, border, foreground } = statusTone(\n    theme,\n    TOKEN_TONE[value],\n  );\n  return { bg: background, border, fg: foreground };\n};\n\nconst softRoles: Readonly<Record<Tone, keyof ThemeColors>> = {\n  info: \"infoSoft\",\n  success: \"successSoft\",\n  warning: \"warningSoft\",\n  danger: \"destructiveSoft\",\n};\n\nexport const messageLink = (theme: Theme, value: Tone): string =>\n  brandTextOn(theme, softRoles[value]);\n\nexport const messageSelection = (theme: Theme, value: Tone): string =>\n  selectionOn(theme, softRoles[value]);\n\nexport const toneSurface = (theme: Theme, value: Tone): StyleDesc => {\n  const { bg, border, fg } = tone(theme, value);\n  return {\n    backgroundColor: bg,\n    color: fg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: border,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/motion.tsx",
      "target": "@ui/gpuixui/components/motion.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport { motionLevelOf, type MotionLevel } from \"../motion/timing.js\";\n\nexport {\n  MotionProvider,\n  useMotionPreference,\n  type MotionProviderProps,\n} from \"./internal/presence.js\";\nexport type { MotionPreference } from \"../motion/timing.js\";\n\nexport type SurfaceLevel = MotionLevel | \"none\";\n\nexport const surfaceLevelOf = (value: unknown): SurfaceLevel =>\n  value === \"none\" ? \"none\" : motionLevelOf(value);\n"
    },
    {
      "path": "packages/components/src/theme-toggler.tsx",
      "target": "@ui/gpuixui/components/theme-toggler.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { Props } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport { Icon, iconPixels } from \"../icons/index.js\";\nimport { cn } from \"../tw/index.js\";\nimport { motionLevelOf } from \"../motion/timing.js\";\nimport { useMotionPreference, useMoveTiming } from \"./internal/presence.js\";\nimport { recipeStyle } from \"./internal/recipe.js\";\nimport { IconButton, type ButtonSize } from \"./internal/button.js\";\nimport { useTheme } from \"./internal/theme.js\";\nimport { surfaceLevelOf, type SurfaceLevel } from \"./motion.js\";\nimport { glyphFrame, incomingDelayShare } from \"./theme-toggler/glyph.js\";\nimport {\n  toggleIcon,\n  toggleLabel,\n  toggledMode,\n  type ThemeMode,\n} from \"./theme-toggler/logic.js\";\n\nexport interface ThemeTogglerState {\n  readonly mode: ThemeMode;\n  readonly reducedMotion: boolean;\n}\n\nexport interface ThemeTogglerProps extends Omit<\n  Props,\n  \"children\" | \"style\" | \"onChange\"\n> {\n  readonly mode: ThemeMode;\n\n  readonly onChange: (mode: ThemeMode) => void;\n\n  readonly lightLabel?: string;\n\n  readonly darkLabel?: string;\n\n  readonly size?: ButtonSize;\n\n  readonly level?: SurfaceLevel;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<ThemeTogglerState>;\n}\n\nexport const ThemeToggler = ({\n  mode,\n  onChange,\n  lightLabel,\n  darkLabel,\n  size = \"md\",\n  level: storedLevel = \"slow\",\n  className,\n  style,\n  testId,\n  ...rest\n}: ThemeTogglerProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const level = surfaceLevelOf(storedLevel);\n  const base = testId ?? \"theme-toggler\";\n  const flip = useMoveTiming(motionLevelOf(level));\n\n  const stagger = (flip.duration ?? 0) * incomingDelayShare;\n  const box = iconPixels(\"sm\");\n  const glyph = (\n    name: ReturnType<typeof toggleIcon>,\n    shown: boolean,\n    part: string,\n  ) => {\n    const frame = glyphFrame(box, shown);\n    return (\n      <Icon\n        name={name}\n        size=\"sm\"\n        color={theme.colors.foreground}\n        testId={`${base}-${part}`}\n        style={{ position: \"absolute\", ...frame }}\n        motion={\n          level === \"none\"\n            ? undefined\n            : {\n                initial: false,\n                animate: frame,\n                transition: shown ? { ...flip, delay: stagger } : flip,\n              }\n        }\n      />\n    );\n  };\n\n  return (\n    <IconButton\n      {...rest}\n      testId={base}\n      size={size}\n      label={toggleLabel(mode, { light: lightLabel, dark: darkLabel })}\n      onClick={() => onChange(toggledMode(mode))}\n      style={mergeStyles(\n        recipeStyle(cn(className), theme),\n        resolveStyle(style, {\n          mode,\n          reducedMotion: preference === \"reduced\",\n        }),\n      )}\n    >\n      <div\n        testId={`${base}-glyph`}\n        style={{ position: \"relative\", width: box, height: box }}\n      >\n        {glyph(\"sun\", mode === \"dark\", \"sun\")}\n        {glyph(\"moon\", mode === \"light\", \"moon\")}\n      </div>\n    </IconButton>\n  );\n};\n\nexport const themeTogglerMeta = {\n  name: \"Theme toggler\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"yes\",\n  limitations: [\n    \"the control reports the mode a press requests; the application owns the theme state, its storage and the provider it re-renders with\",\n    \"the crescent is not bitten out of the disc: with no transform or clip-path the sun shrinks into the centre while the crescent grows, so the two cross over rather than one shape morphing\",\n    \"the glyph paints one role, so the control's hover wash does not tint the vector (GPUix does not inherit colour into an `<svg>`)\",\n  ],\n  docs: \"docs/theme-toggler.mdx\",\n  example: \"examples/theme-toggler.example.tsx\",\n  testFile: \"src/behaviour/theme-toggler.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/components/src/theme-toggler/glyph.ts",
      "target": "@ui/gpuixui/components/theme-toggler/glyph.ts",
      "type": "registry:lib",
      "content": "import type { MotionStyle } from \"@gpuix/react\";\n\nexport const recededShare = 0.55;\n\nexport const incomingDelayShare = 0.15;\n\nexport const glyphFrame = (box: number, shown: boolean): MotionStyle => {\n  const side = shown ? box : box * recededShare;\n  const inset = (box - side) / 2;\n  return {\n    width: side,\n    height: side,\n    left: inset,\n    top: inset,\n    opacity: shown ? 1 : 0,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/theme-toggler/logic.ts",
      "target": "@ui/gpuixui/components/theme-toggler/logic.ts",
      "type": "registry:lib",
      "content": "import { Match } from \"effect\";\nimport type { IconName } from \"../../icons/index.js\";\nimport type { Theme } from \"../internal/theme.js\";\n\nexport type ThemeMode = Theme[\"mode\"];\n\nexport interface ToggleLabels {\n  readonly light?: string;\n  readonly dark?: string;\n}\n\nexport const toggleLabels = {\n  light: \"Switch to light theme\",\n  dark: \"Switch to dark theme\",\n} as const;\n\nexport const toggledMode = (mode: ThemeMode): ThemeMode =>\n  Match.value(mode).pipe(\n    Match.when(\"dark\", () => \"light\" as const),\n    Match.when(\"light\", () => \"dark\" as const),\n    Match.exhaustive,\n  );\n\nexport const toggleIcon = (mode: ThemeMode): IconName =>\n  Match.value(toggledMode(mode)).pipe(\n    Match.when(\"dark\", () => \"moon\" as const),\n    Match.when(\"light\", () => \"sun\" as const),\n    Match.exhaustive,\n  );\n\nexport const toggleLabel = (\n  mode: ThemeMode,\n  labels: ToggleLabels = {},\n): string =>\n  Match.value(toggledMode(mode)).pipe(\n    Match.when(\"light\", () => labels.light ?? toggleLabels.light),\n    Match.when(\"dark\", () => labels.dark ?? toggleLabels.dark),\n    Match.exhaustive,\n  );\n"
    }
  ],
  "docs": "[Theme toggler](https://gpuixui.sudokw.com/components/theme-toggler) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/components/theme-toggler",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}