{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "brand-color-settings-panel",
  "title": "Brand Color Settings Panel",
  "description": "A theme editor for a product's brand: primary and accent colors with a picker, hex field and presets, an 11-step scale generated from the primary, a live contrast check for text on the brand color, a corner radius slider, and a light and dark preview of real UI that updates as you edit. Copy the CSS variables or save the theme.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/brand-color-settings-panel/brand-color-settings-panel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface BrandTheme {\n  primary: string;\n  accent: string;\n  radius: number;\n}\n\nexport interface BrandColorSettingsPanelProps {\n  defaultValue?: BrandTheme;\n  onSave?: (theme: BrandTheme & { scale: Record<string, string> }) => Promise<void> | void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", card: \"#121212\", input: \"#0D0D0D\", border: \"rgba(255,255,255,0.09)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", green: \"#4ADE80\", amber: \"#FBBF24\", red: \"#F87171\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.42)\", card: \"#FFFFFF\", input: \"#FAFAF8\", border: \"rgba(10,10,10,0.1)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", green: \"#15803D\", amber: \"#B45309\", red: \"#DC2626\", ring: \"rgba(10,10,10,0.5)\" },\n};\n\nconst PRESETS = [\"#4F46E5\", \"#2563EB\", \"#0891B2\", \"#059669\", \"#CA8A04\", \"#EA580C\", \"#E11D48\", \"#9333EA\"];\nconst DEFAULT: BrandTheme = { primary: \"#4F46E5\", accent: \"#F59E0B\", radius: 10 };\nconst STEPS = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];\n// Target relative luminance per step, so every hue gets an evenly perceived scale.\nconst TARGET_LUM = [0.93, 0.85, 0.72, 0.55, 0.37, 0.23, 0.14, 0.088, 0.052, 0.03, 0.016];\n\n// Pure color math (no DOM), so server and client render the same.\nconst HEX = /^#[0-9a-f]{6}$/i;\nconst hexToRgb = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16)) as [number, number, number];\nconst rgbToHex = (r: number, g: number, b: number) => `#${[r, g, b].map((x) => Math.round(Math.min(255, Math.max(0, x))).toString(16).padStart(2, \"0\")).join(\"\")}`.toUpperCase();\nfunction rgbToHsl([r, g, b]: [number, number, number]) {\n  r /= 255;\n  g /= 255;\n  b /= 255;\n  const max = Math.max(r, g, b);\n  const min = Math.min(r, g, b);\n  const l = (max + min) / 2;\n  if (max === min) return [0, 0, l * 100];\n  const d = max - min;\n  const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n  const h = max === r ? (g - b) / d + (g < b ? 6 : 0) : max === g ? (b - r) / d + 2 : (r - g) / d + 4;\n  return [h * 60, s * 100, l * 100];\n}\nfunction hslToHex(h: number, s: number, l: number) {\n  s /= 100;\n  l /= 100;\n  const k = (n: number) => (n + h / 30) % 12;\n  const a = s * Math.min(l, 1 - l);\n  const f = (n: number) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));\n  return rgbToHex(f(0) * 255, f(8) * 255, f(4) * 255);\n}\nconst luminance = (hex: string) => {\n  const [r, g, b] = hexToRgb(hex).map((v) => {\n    const c = v / 255;\n    return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n  });\n  return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\nconst contrast = (a: string, b: string) => {\n  const [x, y] = [luminance(a), luminance(b)].sort((m, n) => n - m);\n  return (x + 0.05) / (y + 0.05);\n};\nfunction shade(h: number, s: number, target: number) {\n  let lo = 0;\n  let hi = 100;\n  for (let i = 0; i < 18; i++) {\n    const mid = (lo + hi) / 2;\n    if (luminance(hslToHex(h, s, mid)) < target) lo = mid;\n    else hi = mid;\n  }\n  return hslToHex(h, s, (lo + hi) / 2);\n}\nfunction scaleFor(hex: string) {\n  const [h, s] = rgbToHsl(hexToRgb(hex));\n  return Object.fromEntries(STEPS.map((step, i) => [String(step), shade(h, Math.min(100, s * (i < 2 ? 0.85 : i > 8 ? 0.8 : 1)), TARGET_LUM[i])]));\n}\n\nexport function BrandColorSettingsPanel({ defaultValue = DEFAULT, onSave, theme = \"dark\", className }: BrandColorSettingsPanelProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [saved, setSaved] = React.useState(defaultValue);\n  const [v, setV] = React.useState(defaultValue);\n  const [drafts, setDrafts] = React.useState({ primary: defaultValue.primary, accent: defaultValue.accent });\n  const [previewMode, setPreviewMode] = React.useState<\"light\" | \"dark\">(theme);\n  const [copied, setCopied] = React.useState(false);\n  const [status, setStatus] = React.useState<\"idle\" | \"saving\" | \"saved\">(\"idle\");\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  React.useEffect(() => {\n    if (!copied && status !== \"saved\") return;\n    const t = setTimeout(() => {\n      setCopied(false);\n      setStatus((s) => (s === \"saved\" ? \"idle\" : s));\n    }, 1800);\n    return () => clearTimeout(t);\n  }, [copied, status]);\n  React.useEffect(\n    () => () => {\n      if (timer.current) clearTimeout(timer.current);\n    },\n    [],\n  );\n\n  const scale = scaleFor(v.primary);\n  const onPrimary = contrast(\"#FFFFFF\", v.primary) >= contrast(\"#0A0A0A\", v.primary) ? \"#FFFFFF\" : \"#0A0A0A\";\n  const ratio = contrast(onPrimary, v.primary);\n  const grade = ratio >= 7 ? \"AAA\" : ratio >= 4.5 ? \"AA\" : ratio >= 3 ? \"AA large\" : \"Fail\";\n  const gradeColor = ratio >= 4.5 ? p.green : ratio >= 3 ? p.amber : p.red;\n  const onAccent = contrast(\"#FFFFFF\", v.accent) >= contrast(\"#0A0A0A\", v.accent) ? \"#FFFFFF\" : \"#0A0A0A\";\n  const dirty = v.primary !== saved.primary || v.accent !== saved.accent || v.radius !== saved.radius;\n  const css = [`--radius: ${v.radius}px;`, `--accent: ${v.accent.toUpperCase()};`, ...STEPS.map((s) => `--brand-${s}: ${scale[s]};`)].join(\"\\n\");\n  const baseLum = luminance(v.primary);\n  const baseStep = STEPS[TARGET_LUM.reduce((best, l, i) => (Math.abs(Math.log(l / baseLum)) < Math.abs(Math.log(TARGET_LUM[best] / baseLum)) ? i : best), 0)];\n\n  const setColor = (k: \"primary\" | \"accent\", hex: string) => {\n    setDrafts((d) => ({ ...d, [k]: hex.toUpperCase() }));\n    if (HEX.test(hex)) setV((s) => ({ ...s, [k]: hex.toUpperCase() }));\n  };\n  const save = () => {\n    if (!dirty || status === \"saving\") return;\n    setStatus(\"saving\");\n    const snap = { ...v };\n    const done = () => {\n      setSaved(snap);\n      setStatus(\"saved\");\n    };\n    const r = onSave?.({ ...snap, scale });\n    if (r instanceof Promise) r.then(done, () => setStatus(\"idle\"));\n    else timer.current = setTimeout(done, reduce ? 0 : 700);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const btn = cn(\"flex h-9 shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg px-3.5 text-[13px] font-medium disabled:cursor-not-allowed disabled:opacity-40\", focus);\n  const card = \"rounded-2xl border p-5\";\n  const pv = previewMode === \"dark\" ? { bg: \"#0F0F12\", surface: \"#18181C\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.6)\", border: \"rgba(255,255,255,0.09)\", soft: scale[\"900\"] } : { bg: \"#F7F7F5\", surface: \"#FFFFFF\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.58)\", border: \"rgba(10,10,10,0.09)\", soft: scale[\"50\"] };\n  const tint = previewMode === \"dark\" ? scale[\"300\"] : scale[\"700\"];\n  const R = v.radius;\n\n  const colorField = (k: \"primary\" | \"accent\", label: string, hint: string) => (\n    <div>\n      <p id={`${uid}-${k}-l`} className=\"m-0 text-[13px] font-medium\">\n        {label}\n      </p>\n      <p className=\"m-0 mt-0.5 text-[12.5px]\" style={{ color: p.faint }}>\n        {hint}\n      </p>\n      <div className=\"mt-3 flex items-center gap-2\">\n        <label className=\"relative h-10 w-10 shrink-0 cursor-pointer overflow-hidden rounded-lg border has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-offset-2\" style={{ background: v[k], borderColor: p.border, ...ring }}>\n          <input type=\"color\" value={v[k].toLowerCase()} onChange={(e) => setColor(k, e.target.value)} aria-label={`${label} picker`} className=\"absolute inset-0 h-full w-full cursor-pointer opacity-0\" />\n        </label>\n        <div className=\"relative\">\n          <input\n            value={drafts[k]}\n            onChange={(e) => setColor(k, e.target.value.startsWith(\"#\") ? e.target.value : `#${e.target.value}`)}\n            onBlur={() => setDrafts((d) => ({ ...d, [k]: v[k] }))}\n            aria-labelledby={`${uid}-${k}-l`}\n            aria-invalid={!HEX.test(drafts[k])}\n            spellCheck={false}\n            maxLength={7}\n            className={cn(\"h-10 w-[112px] rounded-lg border px-3 font-mono text-[13px] uppercase\", focus)}\n            style={{ borderColor: HEX.test(drafts[k]) ? p.border : p.red, background: p.input, color: p.text, ...ring }}\n          />\n        </div>\n      </div>\n      {k === \"primary\" && (\n        <div role=\"radiogroup\" aria-label=\"Preset colors\" className=\"mt-3 flex flex-wrap gap-1.5\">\n          {PRESETS.map((c) => (\n            <button key={c} type=\"button\" role=\"radio\" aria-checked={v.primary === c} aria-label={c} onClick={() => setColor(\"primary\", c)} className={cn(\"h-7 w-7 cursor-pointer rounded-full border-0\", focus)} style={{ background: c, boxShadow: v.primary === c ? `0 0 0 2px ${p.card}, 0 0 0 4px ${c}` : \"0 0 0 0 transparent\", ...ring }} />\n          ))}\n        </div>\n      )}\n    </div>\n  );\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-6xl px-4 py-10 @[640px]:px-6\">\n        <header className=\"mb-7 flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"m-0 text-[22px] font-semibold tracking-[-0.01em]\">Brand colors</h2>\n            <p className=\"m-0 mt-1 text-[13.5px]\" style={{ color: p.muted }}>\n              Used for buttons, links, charts and highlights across your workspace and client portal.\n            </p>\n          </div>\n          <div className=\"flex gap-2\">\n            <button\n              type=\"button\"\n              onClick={() => {\n                navigator.clipboard?.writeText(`:root {\\n${css}\\n}`).catch(() => {});\n                setCopied(true);\n              }}\n              className={cn(btn, \"border bg-transparent\")}\n              style={{ borderColor: p.border, color: copied ? p.green : p.text, ...ring }}\n            >\n              {copied ? \"✓ Copied\" : \"Copy CSS variables\"}\n            </button>\n            <button type=\"button\" onClick={save} disabled={!dirty || status === \"saving\"} className={cn(btn, \"min-w-[96px] border-0\")} style={{ background: p.on, color: p.onText, ...ring }}>\n              {status === \"saving\" ? \"Saving…\" : status === \"saved\" && !dirty ? \"✓ Saved\" : \"Save theme\"}\n            </button>\n          </div>\n        </header>\n\n        <div className=\"grid grid-cols-[minmax(0,1fr)] gap-5 @[900px]:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]\">\n          {/* Controls */}\n          <div className=\"flex min-w-0 flex-col gap-5\">\n            <div className={card} style={{ borderColor: p.border, background: p.card }}>\n              <div className=\"grid grid-cols-1 gap-6 @[560px]:grid-cols-2 @[900px]:grid-cols-1 @[1100px]:grid-cols-2\">\n                {colorField(\"primary\", \"Primary\", \"Buttons, links and focus rings\")}\n                {colorField(\"accent\", \"Accent\", \"Highlights, badges and charts\")}\n              </div>\n              <div className=\"mt-6\">\n                <div className=\"flex items-center justify-between\">\n                  <label htmlFor={`${uid}-r`} className=\"text-[13px] font-medium\">\n                    Corner radius\n                  </label>\n                  <span className=\"text-[12.5px] tabular-nums\" style={{ color: p.muted }}>\n                    {v.radius}px\n                  </span>\n                </div>\n                <input id={`${uid}-r`} type=\"range\" min={0} max={20} value={v.radius} onChange={(e) => setV((s) => ({ ...s, radius: Number(e.target.value) }))} className=\"mt-2 w-full cursor-pointer\" style={{ accentColor: v.primary }} />\n              </div>\n            </div>\n\n            <div className={card} style={{ borderColor: p.border, background: p.card }}>\n              <div className=\"flex items-center justify-between gap-3\">\n                <p className=\"m-0 text-[13px] font-medium\">Generated scale</p>\n                <span className=\"text-[12px]\" style={{ color: p.faint }}>\n                  Your color sits at {baseStep}\n                </span>\n              </div>\n              <ul className=\"m-0 mt-3 grid list-none grid-cols-11 gap-1 p-0\" aria-label=\"Brand color scale\">\n                {STEPS.map((s, i) => (\n                  <li key={s} className=\"flex min-w-0 flex-col items-center gap-1.5\">\n                    <motion.span className=\"block h-10 w-full rounded-md\" initial={false} animate={{ backgroundColor: scale[s] }} transition={{ duration: reduce ? 0 : 0.35, delay: reduce ? 0 : i * 0.015 }} style={{ boxShadow: s === baseStep ? `0 0 0 2px ${p.card}, 0 0 0 3.5px ${p.text}` : \"0 0 0 0 transparent\" }} title={`${s} ${scale[s]}`} />\n                    <span className=\"text-[10px] tabular-nums\" style={{ color: s === baseStep ? p.text : p.faint }}>\n                      {s}\n                    </span>\n                  </li>\n                ))}\n              </ul>\n            </div>\n\n            <div className={cn(card, \"flex items-center gap-4\")} style={{ borderColor: p.border, background: p.card }} aria-live=\"polite\">\n              <span className=\"grid h-12 w-16 shrink-0 place-items-center rounded-lg text-[15px] font-semibold\" style={{ background: v.primary, color: onPrimary }}>\n                Aa\n              </span>\n              <div className=\"min-w-0 flex-1\">\n                <p className=\"m-0 text-[13px] font-medium\">Text on primary</p>\n                <p className=\"m-0 mt-0.5 text-[12.5px]\" style={{ color: p.muted }}>\n                  {onPrimary === \"#FFFFFF\" ? \"White\" : \"Black\"} text · contrast {ratio.toFixed(2)}:1\n                </p>\n              </div>\n              <span className=\"rounded-full px-2.5 py-1 text-[12px] font-semibold\" style={{ background: `${gradeColor}22`, color: gradeColor }}>\n                {grade}\n              </span>\n            </div>\n          </div>\n\n          {/* Preview */}\n          <div className={cn(card, \"min-w-0\")} style={{ borderColor: p.border, background: p.card }}>\n            <div className=\"flex items-center justify-between gap-3\">\n              <p className=\"m-0 text-[13px] font-medium\">Preview</p>\n              <div role=\"radiogroup\" aria-label=\"Preview mode\" className=\"flex rounded-lg border p-0.5\" style={{ borderColor: p.border }}>\n                {([\"light\", \"dark\"] as const).map((m) => (\n                  <button key={m} type=\"button\" role=\"radio\" aria-checked={previewMode === m} onClick={() => setPreviewMode(m)} className={cn(\"relative h-7 cursor-pointer rounded-md border-0 bg-transparent px-3 text-[12px] font-medium capitalize\", focus)} style={{ color: previewMode === m ? p.onText : p.muted, ...ring }}>\n                    {previewMode === m && <motion.span layoutId={`${uid}-pm`} className=\"absolute inset-0 rounded-md\" style={{ background: p.on }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 38 }} />}\n                    <span className=\"relative\">{m}</span>\n                  </button>\n                ))}\n              </div>\n            </div>\n\n            <motion.div className=\"mt-4 overflow-hidden border\" initial={false} animate={{ backgroundColor: pv.bg, borderRadius: R + 6 }} transition={{ duration: reduce ? 0 : 0.3 }} style={{ borderColor: pv.border, color: pv.text }} aria-label=\"Theme preview\" role=\"img\">\n              <div className=\"flex items-center gap-2.5 border-b px-4 py-3\" style={{ borderColor: pv.border }}>\n                <span className=\"grid h-6 w-6 place-items-center text-[11px] font-bold\" style={{ background: v.primary, color: onPrimary, borderRadius: Math.max(4, R * 0.6) }}>\n                  N\n                </span>\n                <span className=\"text-[13px] font-semibold\">Nexora</span>\n                <span className=\"ml-auto text-[12px] font-medium\" style={{ color: tint }}>\n                  Upgrade →\n                </span>\n              </div>\n              <div className=\"flex flex-col gap-4 p-4\">\n                <div className=\"flex flex-wrap items-center gap-2\">\n                  <span className=\"px-3.5 py-2 text-[12.5px] font-medium\" style={{ background: v.primary, color: onPrimary, borderRadius: R }}>\n                    Create project\n                  </span>\n                  <span className=\"border px-3.5 py-2 text-[12.5px] font-medium\" style={{ borderColor: scale[\"400\"], color: tint, borderRadius: R }}>\n                    Invite team\n                  </span>\n                  <span className=\"px-2 py-0.5 text-[11px] font-semibold\" style={{ background: v.accent, color: onAccent, borderRadius: 999 }}>\n                    New\n                  </span>\n                </div>\n                <div className=\"border p-3.5\" style={{ background: pv.surface, borderColor: pv.border, borderRadius: R }}>\n                  <div className=\"flex items-center justify-between\">\n                    <span className=\"text-[12.5px] font-medium\">Monthly usage</span>\n                    <span className=\"text-[12px]\" style={{ color: pv.muted }}>\n                      68%\n                    </span>\n                  </div>\n                  <div className=\"mt-2 h-2 overflow-hidden\" style={{ background: pv.soft, borderRadius: R }}>\n                    <motion.div className=\"h-full\" initial={false} animate={{ width: \"68%\", backgroundColor: v.primary }} style={{ borderRadius: R }} />\n                  </div>\n                  <div className=\"mt-4 flex h-16 items-end gap-1.5\">\n                    {[40, 55, 35, 70, 60, 85, 75].map((h, i) => (\n                      <motion.span key={i} className=\"flex-1\" initial={false} animate={{ height: `${h}%`, backgroundColor: i === 5 ? v.accent : i % 2 ? scale[\"300\"] : scale[\"500\"] }} style={{ borderRadius: Math.min(R, 6) }} />\n                    ))}\n                  </div>\n                </div>\n                <div className=\"flex items-center gap-3\">\n                  <span className=\"flex-1 border px-3 py-2 text-[12.5px]\" style={{ borderColor: v.primary, boxShadow: `0 0 0 3px ${v.primary}33`, borderRadius: R, color: pv.muted, background: pv.surface }}>\n                    lena@nexora.io\n                  </span>\n                  <span className=\"relative h-5 w-9 shrink-0 rounded-full\" style={{ background: v.primary }}>\n                    <span className=\"absolute top-0.5 right-0.5 h-4 w-4 rounded-full bg-white\" />\n                  </span>\n                </div>\n                <p className=\"m-0 text-[12.5px]\" style={{ color: pv.muted }}>\n                  Read the{\" \"}\n                  <span className=\"font-medium underline underline-offset-2\" style={{ color: tint }}>\n                    getting started guide\n                  </span>{\" \"}\n                  or{\" \"}\n                  <span className=\"font-medium\" style={{ color: tint }}>\n                    talk to us\n                  </span>\n                  .\n                </p>\n              </div>\n            </motion.div>\n            <AnimatePresence>\n              {dirty && (\n                <motion.p key=\"d\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} className=\"m-0 mt-3 flex items-center justify-between text-[12.5px]\" style={{ color: p.muted }}>\n                  Unsaved changes\n                  <button type=\"button\" onClick={() => { setV(saved); setDrafts({ primary: saved.primary, accent: saved.accent }); }} className={cn(\"cursor-pointer rounded border-0 bg-transparent px-1 text-[12.5px] underline underline-offset-2\", focus)} style={{ color: p.text, ...ring }}>\n                    Reset\n                  </button>\n                </motion.p>\n              )}\n            </AnimatePresence>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default BrandColorSettingsPanel;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}