{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tag-input",
  "type": "registry:item",
  "title": "Tag Input",
  "description": "A list of tags you type: Enter or comma adds one, Backspace in the empty field removes the last, × removes any. Suggestions come from `suggestions`. A form control.",
  "dependencies": [
    "@zubra/runtime@^5.13.1"
  ],
  "categories": [
    "input"
  ],
  "registryDependencies": [
    "https://zubra-js.github.io/zubra-ui/r/theme.json"
  ],
  "files": [
    {
      "path": "components/tag-input.js",
      "type": "registry:file",
      "target": "~/src/components/zubra/tag-input.js",
      "content": "// Generated by zubra from tag-input.zb. Do not edit.\nimport { $define, $r, $t } from \"@zubra/runtime\";\nimport { effect, formValue, host, id } from '@zubra/runtime';\nimport { state as __zubraState, computed as __zubraComputed } from \"@zubra/runtime\";\n\nexport const tag = \"tag-input\";\n\nexport default $define(tag, {\n  props: {\n    \"value\": { attribute: \"value\", default: [], required: false, model: true },\n    \"suggestions\": { attribute: \"suggestions\", default: [], required: false },\n    \"max\": { attribute: \"max\", default: 6, required: false },\n    \"disabled\": { attribute: \"disabled\", default: false, required: false },\n    \"label\": { attribute: \"label\", default: \"Tags\", required: false },\n  },\n  abi: 3,\n  shadow: false,\n  form: true,\n  slots: [],\n  events: [\"valuechange\"],\n  styled: true,\n  styles: \"@layer theme, base, components, utilities;\\n@layer components {\\n@scope (tag-input) to ([data-zb-slotted=\\\"tag-input\\\"]) {\\n  :scope { display: block; }\\n  .box { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; padding: 0.35rem 0.4rem; border: 1px solid var(--border, #d9dce3); border-radius: calc(var(--radius, 0.625rem) * 0.96); background: var(--card, #ffffff); }\\n  .box:focus-within { outline: 2px solid var(--primary, #4f5df5); outline-offset: 1px; }\\n  .tag { display: inline-flex; align-items: center; gap: 0.15rem; padding: 0.1rem 0.2rem 0.1rem 0.5rem; border-radius: calc(var(--radius, 0.625rem) * 0.64); background: var(--chip, var(--secondary, #f4f4f5)); color: var(--chip-ink, var(--secondary-foreground, #18181b)); font-size: 0.8125rem; font-weight: 600; }\\n  .tag button { display: inline-grid; place-items: center; min-width: 1.5rem; min-height: 1.5rem; border: 0; border-radius: calc(var(--radius, 0.625rem) * 0.48); background: none; color: inherit; padding: 0; cursor: pointer; font: inherit; font-size: 1rem; }\\n  .tag button:disabled { cursor: not-allowed; }\\n  :scope:is([disabled]) .box { opacity: 0.55; }\\n  .tag button:hover { background: color-mix(in oklab, currentColor 12%, transparent); }\\n  input { flex: 1; min-width: 7rem; border: 0; outline: 0; padding: 0.3rem; font: inherit; background: none; color: inherit; }\\n  .hint { margin: 0.3rem 0 0; font-size: 0.75rem; color: var(--muted-foreground, #667085); }\\n}\\n}\\n\",\n  template: \"\\n  <div class=\\\"box\\\">\\n    <!--[--><!--]-->\\n    <input>\\n    <datalist><!--[--><!--]--></datalist>\\n  </div>\\n  <p class=\\\"hint\\\" aria-live=\\\"polite\\\"></p>\\n\",\n  setup($p, $emit) {\nfunction __zubraAssign(signal, value) { signal.set(value); return value }\nfunction __zubraUpdate(signal, delta, prefix) { const old = signal.get(); signal.set(old + delta); return prefix ? old + delta : old }\n                                                              \n\n  // `disabled` set from code (el.disabled = true) also goes on the element as the attribute, which\n  // is where the browser looks: it leaves a disabled control out of the form. A disabled\n  // <fieldset> needs nothing here; the browser disables the controls inside it too.\n  const element = host()\n  effect(() => element.toggleAttribute('disabled', $p.disabled))\n\n  const listId = id()\n  const draft = __zubraState(\"\")\n  const input = __zubraState(null)\n  const offered = __zubraComputed(() => ($p.suggestions.filter((tag) => !$p.value.includes(tag))))\n\n  formValue(() => $p.value.join(\",\"))\n\n  function set(next) {\n    $p.value = next\n  }\n  function add(text) {\n    const tag = text.trim().toLowerCase().replace(/\\s+/g, \"-\")\n    __zubraAssign(draft, \"\")\n    if (tag && !$p.value.includes(tag) && $p.value.length < $p.max) set([...$p.value, tag])\n  }\n  // A pasted list (\"a, b, c\") is several tags.\n  function paste(event) {\n    const text = event.clipboardData.getData('text')\n    if (!/[,\\n]/.test(text)) return\n    event.preventDefault()\n    let next = $p.value\n    for (const part of text.split(/[,\\n]/)) {\n      const tag = part.trim().toLowerCase().replace(/\\s+/g, \"-\")\n      if (tag && !next.includes(tag) && next.length < $p.max) next = [...next, tag]\n    }\n    __zubraAssign(draft, \"\")\n    set(next)\n  }\n  function remove(tag) {\n    set($p.value.filter((item) => item !== tag))\n    // The × button goes away with its tag: keep focus in the field.\n    input.get()?.focus()\n  }\n  function key(event) {\n    if (event.key === 'Enter' || event.key === ',') {\n      event.preventDefault()\n      add(draft.get())\n    } else if (event.key === 'Backspace' && !draft.get() && $p.value.length) {\n      set($p.value.slice(0, -1))\n    }\n  }\n    return [\n      { path: [0, 0], each: () => $p.value, key: (tag, $index) => $r(tag), block: { template: \"\\n      <span class=\\\"tag\\\"><!----><button type=\\\"button\\\">×</button></span>\\n    \", parts: (tag, $index) => [{ path: [0, 0], anchor: () => $t($r(tag)) }, { path: [0, 1], attribute: \"aria-label\", value: () => (`Remove ${$r(tag)}`) }, { path: [0, 1], attribute: \"disabled\", boolean: true, value: () => $p.disabled }, { path: [0, 1], on: \"click\", handler: () => (() => remove($r(tag))) }] } },\n      { path: [0, 1], attribute: \"aria-label\", value: () => $p.label },\n      { path: [0, 1], attribute: \"list\", value: () => $r(listId) },\n      { path: [0, 1], attribute: \"placeholder\", value: () => (($p.value.length >= $p.max) ? \"\" : \"Add a tag…\") },\n      { path: [0, 1], ref: () => (($el) => (__zubraAssign(input, $el))) },\n      { path: [0, 1], attribute: \"readonly\", boolean: true, value: () => ($p.value.length >= $p.max) },\n      { path: [0, 1], attribute: \"disabled\", boolean: true, value: () => $p.disabled },\n      { path: [0, 1], attribute: \"value\", value: () => $r(draft) },\n      { path: [0, 1], on: \"input\", handler: () => ((event) => (__zubraAssign(draft, event.target.value))) },\n      { path: [0, 1], on: \"keydown\", handler: () => $r(key) },\n      { path: [0, 1], on: \"paste\", handler: () => $r(paste) },\n      { path: [0, 1], on: \"blur\", handler: () => (() => draft.get().trim() && add(draft.get())) },\n      { path: [0, 1], on: \"change\", handler: () => ((event) => offered.get().includes(event.target.value) && add(event.target.value)) },\n      { path: [0, 2], attribute: \"id\", value: () => $r(listId) },\n      { path: [0, 2, 0], each: () => $r(offered), key: (tag, $index) => $r(tag), block: { template: \"<option></option>\", parts: (tag, $index) => [{ path: [0], attribute: \"value\", value: () => $r(tag) }] } },\n      { path: [1], text: () => $t(($p.value.length >= $p.max ? `That's the most tags (${$p.max}). Remove one to add another.` : `Press Enter after each tag. ${$p.value.length} of ${$p.max}.`)) },\n    ];\n  },\n});\n"
    }
  ]
}
