{
  "name": "color-picker",
  "type": "registry:ui",
  "framework": "react",
  "title": "Color Picker",
  "description": "A palette of swatches with a custom colour tile, for role and accent colours.",
  "files": [
    {
      "path": "ui/color-picker.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/** One entry of the palette. */\nexport interface ColorSwatch {\n  /** Any CSS colour; a hex string if the custom tile should round-trip it. */\n  value: string\n  /** What a screen reader calls it. */\n  label: string\n}\n\n/*\n * A starting palette, not a token set: these are values a user picks and an\n * application stores, so they are data rather than part of the theme.\n */\nexport const defaultSwatches: readonly ColorSwatch[] = [\n  { value: \"#5865f2\", label: \"Indigo\" },\n  { value: \"#3ba55d\", label: \"Green\" },\n  { value: \"#1abc9c\", label: \"Teal\" },\n  { value: \"#3498db\", label: \"Blue\" },\n  { value: \"#9b59b6\", label: \"Purple\" },\n  { value: \"#eb459e\", label: \"Pink\" },\n  { value: \"#f0b232\", label: \"Amber\" },\n  { value: \"#e67e22\", label: \"Orange\" },\n  { value: \"#ed4245\", label: \"Red\" },\n  { value: \"#95a5a6\", label: \"Grey\" },\n]\n\nexport interface ColorPickerProps extends Omit<\n  React.HTMLAttributes<HTMLDivElement>,\n  \"onChange\" | \"defaultValue\"\n> {\n  /** Controlled colour. Leave undefined to let the component own it. */\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  swatches?: readonly ColorSwatch[]\n  /** Show the tile that opens the browser's own colour dialog. */\n  allowCustom?: boolean\n  /** Accessible name for the group. */\n  label?: string\n  /** Accessible name for the custom tile. */\n  customLabel?: string\n  /** Shared `name` for the radios. One is generated when it is not given. */\n  name?: string\n  disabled?: boolean\n}\n\nconst HEX = /^#[0-9a-f]{6}$/i\n\n/*\n * A short palette and one way out of it. The swatches are a real radio set,\n * so the arrow keys move between them and a form posts the chosen value; the\n * larger tile is the browser's own colour dialog for anything the palette\n * does not hold, and it wears the colour whenever the value is not a swatch.\n */\nconst ColorPicker = React.forwardRef<HTMLDivElement, ColorPickerProps>(\n  (\n    {\n      className,\n      value,\n      defaultValue,\n      onValueChange,\n      swatches = defaultSwatches,\n      allowCustom = true,\n      label = \"Colour\",\n      customLabel = \"Custom colour\",\n      name,\n      disabled = false,\n      ...props\n    },\n    ref\n  ) => {\n    const generated = React.useId()\n    const [internal, setInternal] = React.useState(\n      defaultValue ?? swatches[0]?.value ?? \"\"\n    )\n    const isControlled = value !== undefined\n    const current = (isControlled ? value : internal).toLowerCase()\n    const isCustom = !swatches.some(\n      (swatch) => swatch.value.toLowerCase() === current\n    )\n\n    const commit = (next: string) => {\n      if (!isControlled) setInternal(next)\n      onValueChange?.(next)\n    }\n\n    return (\n      <div\n        ref={ref}\n        role=\"group\"\n        aria-label={label}\n        className={cn(\n          \"inline-flex items-stretch gap-2.5\",\n          disabled && \"pointer-events-none opacity-50\",\n          className\n        )}\n        {...props}\n      >\n        {allowCustom ? (\n          <label\n            data-active={isCustom || undefined}\n            className=\"relative flex min-h-[54px] w-[66px] cursor-pointer items-start justify-end rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-input p-1 text-newt-on-accent focus-within:outline focus-within:outline-2 focus-within:outline-offset-2 focus-within:outline-newt-text-link data-[active]:border-newt-text-primary data-[active]:ring-1 data-[active]:ring-newt-text-primary\"\n            style={isCustom ? { backgroundColor: current } : undefined}\n          >\n            <input\n              type=\"color\"\n              aria-label={customLabel}\n              disabled={disabled}\n              value={HEX.test(current) ? current : \"#000000\"}\n              onChange={(event) => commit(event.target.value)}\n              className=\"absolute inset-0 h-full w-full cursor-pointer opacity-0\"\n            />\n            <svg\n              viewBox=\"0 0 16 16\"\n              aria-hidden=\"true\"\n              className=\"h-3.5 w-3.5 drop-shadow-[0_0_1px_rgb(0_0_0/0.7)]\"\n            >\n              <path\n                fill=\"currentColor\"\n                d=\"M13.4 2.6a2 2 0 0 0-2.8 0L9 4.2l-.3-.3a1 1 0 0 0-1.4 1.4l.3.3-4.3 4.3a1 1 0 0 0-.3.7V13h2.4a1 1 0 0 0 .7-.3l4.3-4.3.3.3a1 1 0 0 0 1.4-1.4l-.3-.3 1.6-1.6a2 2 0 0 0 0-2.8ZM5 11.6H4.4V11L8.6 6.8l.6.6L5 11.6Z\"\n              />\n            </svg>\n          </label>\n        ) : null}\n        <div className=\"grid grid-cols-[repeat(5,1.5rem)] content-center gap-1.5\">\n          {swatches.map((swatch) => (\n            <label\n              key={swatch.value}\n              className=\"group relative block cursor-pointer\"\n            >\n              <input\n                type=\"radio\"\n                name={name ?? generated}\n                value={swatch.value}\n                disabled={disabled}\n                checked={swatch.value.toLowerCase() === current}\n                onChange={() => commit(swatch.value)}\n                className=\"peer sr-only\"\n              />\n              <span\n                aria-hidden=\"true\"\n                className=\"flex h-6 w-6 items-center justify-center rounded-[var(--newt-radius-sm)] text-newt-on-accent transition-transform duration-fast ease-newt group-hover:scale-110 peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-newt-text-link\"\n                style={{ backgroundColor: swatch.value }}\n              >\n                <svg\n                  viewBox=\"0 0 16 16\"\n                  className=\"h-4 w-4 scale-0 drop-shadow-[0_0_1px_rgb(0_0_0/0.7)] transition-transform duration-fast ease-newt group-has-[:checked]:scale-100\"\n                >\n                  <path\n                    fill=\"currentColor\"\n                    d=\"M6.2 11.6 3.1 8.5a1 1 0 0 1 1.4-1.4l1.7 1.7 4.3-4.3a1 1 0 1 1 1.4 1.4l-5 5a1 1 0 0 1-1.4 0Z\"\n                  />\n                </svg>\n              </span>\n              <span className=\"sr-only\">{swatch.label}</span>\n            </label>\n          ))}\n        </div>\n      </div>\n    )\n  }\n)\nColorPicker.displayName = \"ColorPicker\"\n\nexport { ColorPicker }\n",
      "type": "registry:ui"
    }
  ]
}