{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "opentui/color-picker",
  "title": "Color Picker",
  "description": "Color picker with palette, hex, and RGB input",
  "dependencies": [
    "@opentui/react"
  ],
  "registryDependencies": [
    "https://termcn.dev/r/opentui/use-theme.json"
  ],
  "files": [
    {
      "path": "registry/opentui/ui/color-picker.tsx",
      "content": "/* @jsxImportSource @opentui/react */\nimport { useKeyboard } from \"@opentui/react\";\nimport { useState } from \"react\";\n\nimport { useTheme } from \"@/hooks/use-theme\";\n\nconst DEFAULT_PALETTE = [\n  \"#000000\",\n  \"#800000\",\n  \"#008000\",\n  \"#808000\",\n  \"#000080\",\n  \"#800080\",\n  \"#008080\",\n  \"#c0c0c0\",\n  \"#808080\",\n  \"#ff0000\",\n  \"#00ff00\",\n  \"#ffff00\",\n  \"#0000ff\",\n  \"#ff00ff\",\n  \"#00ffff\",\n  \"#ffffff\",\n];\n\nconst COLS = 8;\n\nexport interface ColorPickerProps {\n  value?: string;\n  onChange?: (color: string) => void;\n  onSubmit?: (color: string) => void;\n  label?: string;\n  palette?: string[];\n  autoFocus?: boolean;\n  id?: string;\n}\n\nexport const ColorPicker = ({\n  value: controlledValue,\n  onChange,\n  onSubmit,\n  label,\n  palette = DEFAULT_PALETTE,\n  autoFocus: _autoFocus = false,\n  id: _id,\n}: ColorPickerProps) => {\n  const theme = useTheme();\n  const [isFocused] = useState(true);\n  const [paletteRow, setPaletteRow] = useState(0);\n  const [paletteCol, setPaletteCol] = useState(0);\n  const [hexInput, setHexInput] = useState(\"\");\n  const [mode, setMode] = useState<\"palette\" | \"hex\">(\"palette\");\n  const [internalValue, setInternalValue] = useState(palette[0] ?? \"#000000\");\n\n  const rows = Math.ceil(palette.length / COLS);\n  const currentPaletteColor =\n    palette[paletteRow * COLS + paletteCol] ?? palette[0] ?? \"#000000\";\n  const currentColor = controlledValue ?? internalValue;\n\n  const applyColor = (color: string) => {\n    if (onChange) {\n      onChange(color);\n    } else {\n      setInternalValue(color);\n    }\n  };\n\n  useKeyboard((key) => {\n    if (!isFocused) {\n      return;\n    }\n    if (key.name === \"tab\") {\n      setMode((m) => (m === \"palette\" ? \"hex\" : \"palette\"));\n      return;\n    }\n    if (mode === \"palette\") {\n      if (key.name === \"up\") {\n        setPaletteRow((r) => Math.max(0, r - 1));\n      } else if (key.name === \"down\") {\n        setPaletteRow((r) => Math.min(rows - 1, r + 1));\n      } else if (key.name === \"left\") {\n        setPaletteCol((c) => Math.max(0, c - 1));\n      } else if (key.name === \"right\") {\n        setPaletteCol((c) => Math.min(COLS - 1, c + 1));\n      } else if (key.name === \"return\") {\n        applyColor(currentPaletteColor);\n        onSubmit?.(currentPaletteColor);\n      }\n    } else if (key.name === \"backspace\" || key.name === \"delete\") {\n      setHexInput((h) => h.slice(0, -1));\n    } else if (key.name === \"return\") {\n      const hex = hexInput.startsWith(\"#\") ? hexInput : `#${hexInput}`;\n      if (/^#[0-9a-fA-F]{6}$/.test(hex)) {\n        applyColor(hex);\n        onSubmit?.(hex);\n      }\n    } else if (/^[0-9a-fA-F#]$/.test(key.name) && hexInput.length < 7) {\n      setHexInput((h) => h + key.name);\n    }\n  });\n\n  return (\n    <box flexDirection=\"column\">\n      {label && (\n        <text>\n          <b>{label}</b>\n        </text>\n      )}\n\n      <box flexDirection=\"column\">\n        {Array.from({ length: rows }, (_, r) => (\n          <box key={r}>\n            {Array.from({ length: COLS }, (_c, c) => {\n              const idx = r * COLS + c;\n              if (idx >= palette.length) {\n                return null;\n              }\n              const paletteColor = palette[idx];\n              const isActive =\n                mode === \"palette\" && r === paletteRow && c === paletteCol;\n              return (\n                <box key={c} marginRight={0}>\n                  <text\n                    bg={paletteColor}\n                    fg={isActive ? \"#ffffff\" : paletteColor}\n                  >\n                    {isActive ? <b>[]</b> : \"  \"}\n                  </text>\n                </box>\n              );\n            })}\n          </box>\n        ))}\n      </box>\n\n      <box marginTop={1} gap={1}>\n        <text fg={theme.colors.mutedForeground}>Selected:</text>\n        <text bg={currentColor} fg={currentColor}>\n          {\"  \"}\n        </text>\n        <text fg={theme.colors.foreground}>{currentColor}</text>\n      </box>\n\n      <box\n        borderStyle=\"rounded\"\n        borderColor={\n          mode === \"hex\" ? theme.colors.focusRing : theme.colors.border\n        }\n        paddingLeft={1}\n        paddingRight={1}\n        marginTop={1}\n      >\n        <text fg={theme.colors.mutedForeground}>#</text>\n        <text fg={theme.colors.foreground}>{hexInput || \"------\"}</text>\n        {mode === \"hex\" && isFocused && (\n          <text fg={theme.colors.focusRing}>█</text>\n        )}\n      </box>\n\n      <text fg=\"#666\">\n        {mode === \"palette\"\n          ? \"↑↓←→: navigate · Enter: select · Tab: hex input\"\n          : \"Type hex · Enter: apply · Tab: palette\"}\n      </text>\n    </box>\n  );\n};\n",
      "type": "registry:ui",
      "target": "components/ui/color-picker.tsx"
    }
  ],
  "categories": [
    "selection"
  ],
  "type": "registry:ui"
}