{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tag-input-with-coloured-category-chips","type":"registry:component","title":"Tag Input With Coloured Category Chips","description":"","dependencies":[],"files":[{"path":"components/we-inc/tag-input-with-coloured-category-chips.tsx","type":"registry:component","content":"import { useRef, useState, type FormEvent } from \"react\";\n\n// Each group has its own chip colours. Add a group here and it appears in the picker.\nconst GROUPS = {\n  client: { label: \"Client\", chip: \"bg-amber-100 text-amber-900 ring-amber-300\", dot: \"bg-amber-500\" },\n  stage: { label: \"Stage\", chip: \"bg-sky-100 text-sky-900 ring-sky-300\", dot: \"bg-sky-500\" },\n  owner: { label: \"Owner\", chip: \"bg-violet-100 text-violet-900 ring-violet-300\", dot: \"bg-violet-500\" },\n} as const;\ntype Group = keyof typeof GROUPS;\n\nexport default function TagInputWithColouredCategoryChips() {\n  const [tags, setTags] = useState<{ text: string; group: Group }[]>([\n    { text: \"Marlow Bakery\", group: \"client\" },\n    { text: \"In review\", group: \"stage\" },\n    { text: \"Priya\", group: \"owner\" },\n  ]);\n  const [text, setText] = useState(\"\");\n  const [group, setGroup] = useState<Group>(\"stage\");\n  const [note, setNote] = useState(\"\");\n  const field = useRef<HTMLInputElement>(null);\n\n  const add = (e: FormEvent) => {\n    e.preventDefault();\n    const t = text.trim();\n    if (!t) return;\n    if (tags.some((x) => x.text.toLowerCase() === t.toLowerCase())) { setNote(`${t} is already a label`); return; }\n    setTags([...tags, { text: t, group }]);\n    setText(\"\");\n    setNote(`Added ${t} to ${GROUPS[group].label}`);\n  };\n  const remove = (t: string) => {\n    setTags(tags.filter((x) => x.text !== t));\n    setNote(`Removed ${t}`);\n    field.current?.focus();\n  };\n\n  return (\n    <section className=\"bg-amber-50/60 px-4 py-16\">\n      <div className=\"mx-auto max-w-xl rounded-3xl bg-white p-6 shadow-[0_1px_0_rgba(0,0,0,0.04),0_12px_32px_-12px_rgba(120,53,15,0.18)] sm:p-8\">\n        <p className=\"text-xs font-semibold uppercase tracking-widest text-amber-800\">Task 214</p>\n        <h2 className=\"mt-1 text-lg font-semibold text-stone-900\">Photograph spring pastry menu</h2>\n\n        <ul className=\"mt-5 flex flex-wrap gap-2\" aria-label=\"Labels\">\n          {tags.map((t) => (\n            <li key={t.text} className={`flex h-8 items-center gap-2 rounded-full pl-3 pr-1 text-sm font-medium ring-1 ring-inset ${GROUPS[t.group].chip}`}>\n              <span className={`h-2 w-2 rounded-full ${GROUPS[t.group].dot}`} aria-hidden=\"true\" />\n              <span className=\"sr-only\">{GROUPS[t.group].label}: </span>{t.text}\n              <button type=\"button\" aria-label={`Remove ${t.text}`} onClick={() => remove(t.text)} className=\"grid h-6 w-6 place-items-center rounded-full hover:bg-black/5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-stone-800\">\n                <svg viewBox=\"0 0 20 20\" width=\"12\" height=\"12\" aria-hidden=\"true\"><path d=\"M5 5l10 10M15 5L5 15\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" /></svg>\n              </button>\n            </li>\n          ))}\n        </ul>\n\n        <form onSubmit={add} className=\"mt-5 flex flex-col gap-2 sm:flex-row\">\n          <label htmlFor=\"ticc-group\" className=\"sr-only\">Label group</label>\n          <select id=\"ticc-group\" value={group} onChange={(e) => setGroup(e.target.value as Group)} className=\"h-11 rounded-xl border border-stone-300 bg-white px-3 text-sm text-stone-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-amber-600\">\n            {(Object.keys(GROUPS) as Group[]).map((g) => <option key={g} value={g}>{GROUPS[g].label}</option>)}\n          </select>\n          <label htmlFor=\"ticc-field\" className=\"sr-only\">New label</label>\n          <input id=\"ticc-field\" ref={field} value={text} onChange={(e) => setText(e.target.value)} placeholder=\"Type a label and press Enter\" className=\"h-11 w-full rounded-xl sm:w-auto sm:flex-1 border border-stone-300 px-3 text-sm text-stone-900 placeholder:text-stone-500 focus:border-amber-600 focus:outline-none focus:ring-2 focus:ring-amber-200\" />\n          <button type=\"submit\" className=\"h-11 rounded-xl bg-stone-900 px-4 text-sm font-medium text-white hover:bg-stone-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-600 focus-visible:ring-offset-2\">Add label</button>\n        </form>\n        <p aria-live=\"polite\" className=\"mt-2 min-h-[1.25rem] text-xs text-stone-600\">{note}</p>\n      </div>\n    </section>\n  );\n}\n"}]}
