{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-toggle-list",
  "title": "Settings Toggle List",
  "description": "A preferences page of grouped switches that save instantly: search with highlighted matches, settings that reveal a follow-up option when turned on, beta badges, a reload banner for settings that need it, a saved check on each change, an undo toast, a count of changes from default and reset per section.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/settings-toggle-list/settings-toggle-list.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\ninterface Setting {\n  id: string;\n  label: string;\n  hint: string;\n  default: boolean;\n  beta?: boolean;\n  restart?: boolean;\n  sub?: { id: string; label: string; options: string[]; default: string };\n}\n\nexport interface SettingsToggleListProps {\n  sections?: { id: string; title: string; settings: Setting[] }[];\n  onChange?: (id: string, value: boolean | string) => 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\", menu: \"#1A1A1A\", border: \"rgba(255,255,255,0.08)\", input: \"#0D0D0D\", track: \"rgba(255,255,255,0.12)\", mark: \"rgba(250,204,21,0.3)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", accent: \"#60A5FA\", green: \"#4ADE80\", amber: \"#FBBF24\", 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\", menu: \"#FFFFFF\", border: \"rgba(10,10,10,0.09)\", input: \"#FAFAF8\", track: \"rgba(10,10,10,0.14)\", mark: \"rgba(250,204,21,0.45)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", accent: \"#2563EB\", green: \"#15803D\", amber: \"#B45309\", ring: \"rgba(10,10,10,0.5)\" },\n};\nconst SECTIONS = [\n  {\n    id: \"general\",\n    title: \"General\",\n    settings: [\n      { id: \"autosave\", label: \"Auto-save\", hint: \"Save changes while you type\", default: true, sub: { id: \"autosave-every\", label: \"Save every\", options: [\"5 seconds\", \"30 seconds\", \"1 minute\"], default: \"30 seconds\" } },\n      { id: \"sounds\", label: \"Sounds\", hint: \"Play a sound for mentions and completed tasks\", default: false },\n      { id: \"compact\", label: \"Compact mode\", hint: \"Tighter spacing to fit more on screen\", default: false },\n      { id: \"week\", label: \"Week starts on Monday\", hint: \"Used in calendars and date pickers\", default: true },\n    ],\n  },\n  {\n    id: \"editor\",\n    title: \"Editor\",\n    settings: [\n      { id: \"spell\", label: \"Spell check\", hint: \"Underline misspelled words\", default: true },\n      { id: \"markdown\", label: \"Markdown shortcuts\", hint: \"Type # for headings and - for lists\", default: true },\n      { id: \"ai\", label: \"AI writing suggestions\", hint: \"Inline completions as you write\", default: false, beta: true, sub: { id: \"ai-tone\", label: \"Tone\", options: [\"Neutral\", \"Friendly\", \"Formal\"], default: \"Neutral\" } },\n    ],\n  },\n  {\n    id: \"privacy\",\n    title: \"Privacy\",\n    settings: [\n      { id: \"status\", label: \"Show when I'm online\", hint: \"Others see a green dot on your avatar\", default: true },\n      { id: \"read\", label: \"Read receipts\", hint: \"Let people know you've seen their message\", default: true },\n      { id: \"telemetry\", label: \"Share usage data\", hint: \"Anonymous stats that help us improve Nexora\", default: true, restart: true },\n    ],\n  },\n  {\n    id: \"labs\",\n    title: \"Labs\",\n    settings: [\n      { id: \"gpu\", label: \"Hardware acceleration\", hint: \"Use your graphics card for smoother charts\", default: false, beta: true, restart: true },\n      { id: \"cmdk\", label: \"New command menu\", hint: \"The redesigned ⌘K with actions and recent items\", default: false, beta: true },\n    ],\n  },\n];\n\nfunction highlight(text: string, q: string, mark: string) {\n  if (!q) return text;\n  const i = text.toLowerCase().indexOf(q);\n  if (i < 0) return text;\n  return (\n    <>\n      {text.slice(0, i)}\n      <mark className=\"rounded-[3px] px-px text-inherit\" style={{ background: mark }}>\n        {text.slice(i, i + q.length)}\n      </mark>\n      {text.slice(i + q.length)}\n    </>\n  );\n}\n\nexport function SettingsToggleList({ sections = SECTIONS, onChange, theme = \"dark\", className }: SettingsToggleListProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const all = sections.flatMap((s) => s.settings);\n  const defaults = React.useMemo(() => Object.fromEntries(sections.flatMap((s) => s.settings.flatMap((x) => [[x.id, x.default], ...(x.sub ? [[x.sub.id, x.sub.default]] : [])]))) as Record<string, boolean | string>, [sections]);\n  const [values, setValues] = React.useState<Record<string, boolean | string>>(() => ({ ...defaults, sounds: true, ai: true }));\n  const [applied, setApplied] = React.useState<Record<string, boolean | string>>(() => ({ ...defaults, sounds: true, ai: true }));\n  const [query, setQuery] = React.useState(\"\");\n  const [flash, setFlash] = React.useState<string | null>(null);\n  const [undo, setUndo] = React.useState<{ id: string; prev: boolean | string; label: string } | null>(null);\n\n  React.useEffect(() => {\n    if (!flash) return;\n    const t = setTimeout(() => setFlash(null), 1200);\n    return () => clearTimeout(t);\n  }, [flash]);\n  React.useEffect(() => {\n    if (!undo) return;\n    const t = setTimeout(() => setUndo(null), 4000);\n    return () => clearTimeout(t);\n  }, [undo]);\n\n  const set = (id: string, val: boolean | string, label: string) => {\n    setUndo({ id, prev: values[id], label });\n    setValues((v) => ({ ...v, [id]: val }));\n    setFlash(id);\n    onChange?.(id, val);\n  };\n  const q = query.trim().toLowerCase();\n  const changed = Object.keys(values).filter((k) => values[k] !== defaults[k]).length;\n  const pendingRestart = all.filter((x) => x.restart && values[x.id] !== applied[x.id]);\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\n  return (\n    <section className={cn(\"@container relative w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-2xl px-4 py-10 @[640px]:px-6\">\n        <div className=\"flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"m-0 text-[22px] font-semibold tracking-[-0.01em]\">Preferences</h2>\n            <p className=\"m-0 mt-1 text-[13px]\" style={{ color: p.muted }} aria-live=\"polite\">\n              Changes save as you go · {changed} changed from default\n            </p>\n          </div>\n          <div className=\"relative w-full @[560px]:w-56\">\n            <svg className=\"pointer-events-none absolute top-1/2 left-2.5 -translate-y-1/2\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.faint} strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <circle cx=\"11\" cy=\"11\" r=\"7\" />\n              <path d=\"m20 20-3.5-3.5\" />\n            </svg>\n            <input value={query} onChange={(e) => setQuery(e.target.value)} onKeyDown={(e) => e.key === \"Escape\" && setQuery(\"\")} placeholder=\"Search settings\" aria-label=\"Search settings\" className={cn(\"h-9 w-full rounded-lg border pr-3 pl-8 text-[13px]\", focus)} style={{ borderColor: p.border, background: p.card, color: p.text, ...ring }} />\n          </div>\n        </div>\n\n        <AnimatePresence initial={false}>\n          {pendingRestart.length > 0 && (\n            <motion.div key=\"restart\" initial={reduce ? false : { opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={reduce ? undefined : { opacity: 0, height: 0 }} className=\"overflow-hidden\" role=\"status\">\n              <div className=\"mt-4 flex items-center justify-between gap-3 rounded-xl border px-3.5 py-2.5 text-[13px]\" style={{ borderColor: `${p.amber}55`, background: `${p.amber}12` }}>\n                <span style={{ color: p.amber }}>\n                  Reload to apply {pendingRestart.length} {pendingRestart.length === 1 ? \"change\" : \"changes\"}: {pendingRestart.map((x) => x.label).join(\", \")}\n                </span>\n                <button type=\"button\" onClick={() => setApplied(values)} className={cn(\"h-7 shrink-0 cursor-pointer rounded-md border-0 px-2.5 text-[12px] font-medium\", focus)} style={{ background: p.amber, color: \"#0A0A0A\", ...ring }}>\n                  Reload\n                </button>\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n\n        <div className=\"mt-6 flex flex-col gap-6\">\n          {sections.map((s) => {\n            const list = s.settings.filter((x) => !q || x.label.toLowerCase().includes(q) || x.hint.toLowerCase().includes(q));\n            if (!list.length) return null;\n            const sectionChanged = s.settings.some((x) => values[x.id] !== defaults[x.id] || (x.sub && values[x.sub.id] !== defaults[x.sub.id]));\n            return (\n              <motion.div key={s.id} layout={!reduce ? \"position\" : false}>\n                <div className=\"mb-2 flex items-center justify-between px-1\">\n                  <h3 id={`${uid}-${s.id}`} className=\"m-0 text-[12px] font-medium tracking-[0.04em] uppercase\" style={{ color: p.faint }}>\n                    {s.title}\n                  </h3>\n                  {sectionChanged && (\n                    <button\n                      type=\"button\"\n                      onClick={() => {\n                        setValues((v) => ({ ...v, ...Object.fromEntries(s.settings.flatMap((x) => [[x.id, x.default], ...(x.sub ? [[x.sub.id, x.sub.default]] : [])])) }));\n                        setUndo(null);\n                      }}\n                      className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 text-[12px]\", focus)}\n                      style={{ color: p.muted, ...ring }}\n                    >\n                      Reset to defaults\n                    </button>\n                  )}\n                </div>\n                <ul className=\"m-0 list-none overflow-hidden rounded-2xl border p-0\" style={{ borderColor: p.border, background: p.card }} aria-labelledby={`${uid}-${s.id}`}>\n                  {list.map((x, i) => {\n                    const on = values[x.id] === true;\n                    return (\n                      <li key={x.id} className={cn(i > 0 && \"border-t\")} style={{ borderColor: p.border }}>\n                        <div className=\"flex items-center gap-4 px-4 py-3.5\">\n                          <div className=\"min-w-0 flex-1\">\n                            <p id={`${uid}-${x.id}`} className=\"m-0 flex flex-wrap items-center gap-1.5 text-[13.5px] font-medium\">\n                              {highlight(x.label, q, p.mark)}\n                              {x.beta && (\n                                <span className=\"rounded-full px-1.5 py-px text-[10.5px] font-medium\" style={{ background: `${p.accent}22`, color: p.accent }}>\n                                  Beta\n                                </span>\n                              )}\n                              {x.restart && (\n                                <span className=\"text-[11px] font-normal\" style={{ color: p.faint }}>\n                                  · needs reload\n                                </span>\n                              )}\n                              <AnimatePresence>\n                                {flash === x.id && (\n                                  <motion.span key=\"f\" initial={reduce ? false : { opacity: 0, x: -4 }} animate={{ opacity: 1, x: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"text-[11.5px] font-normal\" style={{ color: p.green }}>\n                                    ✓ Saved\n                                  </motion.span>\n                                )}\n                              </AnimatePresence>\n                            </p>\n                            <p id={`${uid}-${x.id}-h`} className=\"m-0 mt-0.5 text-[12.5px]\" style={{ color: p.muted }}>\n                              {highlight(x.hint, q, p.mark)}\n                            </p>\n                          </div>\n                          <button type=\"button\" role=\"switch\" aria-checked={on} aria-labelledby={`${uid}-${x.id}`} aria-describedby={`${uid}-${x.id}-h`} onClick={() => set(x.id, !on, x.label)} className={cn(\"relative h-6 w-11 shrink-0 cursor-pointer rounded-full border-0 transition-colors\", focus)} style={{ background: on ? p.green : p.track, ...ring }}>\n                            <motion.span className=\"absolute top-0.5 h-5 w-5 rounded-full bg-white shadow\" initial={false} animate={{ left: on ? 22 : 2 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 600, damping: 34 }} />\n                          </button>\n                        </div>\n                        <AnimatePresence initial={false}>\n                          {x.sub && on && (\n                            <motion.div key=\"sub\" initial={reduce ? false : { opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={reduce ? undefined : { opacity: 0, height: 0 }} className=\"overflow-hidden\">\n                              <div className=\"mx-4 mb-3.5 flex items-center justify-between gap-3 rounded-xl px-3 py-2 text-[12.5px]\" style={{ background: p.input }}>\n                                <label htmlFor={`${uid}-${x.sub.id}`} style={{ color: p.muted }}>\n                                  {x.sub.label}\n                                </label>\n                                <select id={`${uid}-${x.sub.id}`} value={values[x.sub.id] as string} onChange={(e) => set(x.sub!.id, e.target.value, `${x.label}: ${x.sub!.label}`)} className={cn(\"h-7 cursor-pointer rounded-md border px-1.5 text-[12px]\", focus)} style={{ borderColor: p.border, background: p.card, color: p.text, ...ring }}>\n                                  {x.sub.options.map((o) => (\n                                    <option key={o}>{o}</option>\n                                  ))}\n                                </select>\n                              </div>\n                            </motion.div>\n                          )}\n                        </AnimatePresence>\n                      </li>\n                    );\n                  })}\n                </ul>\n              </motion.div>\n            );\n          })}\n          {q && !sections.some((s) => s.settings.some((x) => x.label.toLowerCase().includes(q) || x.hint.toLowerCase().includes(q))) && (\n            <p className=\"m-0 py-10 text-center text-[13px]\" style={{ color: p.faint }}>\n              No settings match “{query}”\n            </p>\n          )}\n        </div>\n      </div>\n\n      <AnimatePresence>\n        {undo && (\n          <motion.div key={`${undo.id}-${String(values[undo.id])}`} initial={reduce ? false : { opacity: 0, y: 12 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: 12 }} className=\"sticky bottom-4 z-10 mx-auto mb-4 flex w-fit items-center gap-3 rounded-full border py-1.5 pr-1.5 pl-4 text-[12.5px] shadow-xl\" style={{ background: p.menu, borderColor: p.border }} role=\"status\">\n            <span>\n              {undo.label} {typeof values[undo.id] === \"boolean\" ? (values[undo.id] ? \"on\" : \"off\") : `set to ${values[undo.id]}`}\n            </span>\n            <button\n              type=\"button\"\n              onClick={() => {\n                setValues((v) => ({ ...v, [undo.id]: undo.prev }));\n                onChange?.(undo.id, undo.prev);\n                setUndo(null);\n              }}\n              className={cn(\"h-7 cursor-pointer rounded-full border-0 px-3 text-[12px] font-medium\", focus)}\n              style={{ background: p.on, color: p.onText, ...ring }}\n            >\n              Undo\n            </button>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nexport default SettingsToggleList;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}