{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-tags",
  "type": "registry:component",
  "title": "Tags Input",
  "description": "A tag field. Enter or comma adds a chip, Backspace removes the last one, and chips scale in and out. Supports a maximum count.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "tags",
    "chips",
    "input",
    "form",
    "multi value",
    "keywords"
  ],
  "docs": "https://hyperblur.dev/effects/input-tags",
  "files": [
    {
      "path": "registry/hyperblur/input-tags.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/input-tags.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface InputTagsProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\"> {\n  value?: string[];\n  defaultValue?: string[];\n  onValueChange?: (value: string[]) => void;\n  max?: number;\n  placeholder?: string;\n  validate?: (tag: string) => boolean;\n  label?: string;\n  name?: string;\n  disabled?: boolean;\n  accent?: string;\n}\n\nconst css = `\n.hb-qn7 {\n  box-sizing: border-box;\n  width: 100%;\n  font: inherit;\n  color: #ededed;\n}\n.hb-qn7 *, .hb-qn7 *::before, .hb-qn7 *::after { box-sizing: border-box; }\n.hb-qn7-box {\n  display: flex;\n  flex-wrap: wrap;\n  align-items: center;\n  gap: 6px;\n  min-height: 46px;\n  padding: 6px 10px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: #111;\n  cursor: text;\n  transition: border-color 0.2s ease, box-shadow 0.2s ease;\n}\n.hb-qn7-box:hover { border-color: #3a3a3a; }\n.hb-qn7-box:focus-within {\n  border-color: var(--hb-qn7-a);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-qn7-a) 18%, transparent);\n}\n.hb-qn7[data-disabled=\"true\"] .hb-qn7-box { opacity: 0.5; cursor: not-allowed; }\n.hb-qn7-chip {\n  display: inline-flex;\n  align-items: center;\n  gap: 2px;\n  max-width: 100%;\n  height: 28px;\n  padding: 0 4px 0 10px;\n  border: 1px solid color-mix(in srgb, var(--hb-qn7-a) 38%, #262626);\n  border-radius: 999px;\n  background: color-mix(in srgb, var(--hb-qn7-a) 14%, #151515);\n  font-size: 13px;\n  font-weight: 500;\n  line-height: 1;\n  color: #ededed;\n  animation: hb-qn7-in 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);\n}\n.hb-qn7-chip[data-leaving=\"true\"] { animation: hb-qn7-out 0.18s ease forwards; pointer-events: none; }\n.hb-qn7-chip[data-dupe=\"true\"] { animation: hb-qn7-dupe 0.4s ease; border-color: #ff5d6c; }\n.hb-qn7-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-qn7-x {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 20px;\n  height: 20px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  background: transparent;\n  color: #a1a1a1;\n  cursor: pointer;\n  transition: background 0.2s ease, color 0.2s ease;\n}\n.hb-qn7-x:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }\n.hb-qn7-x:focus-visible { outline: 2px solid var(--hb-qn7-a); outline-offset: 0; }\n.hb-qn7-x svg { width: 10px; height: 10px; display: block; }\n.hb-qn7-x path { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }\n.hb-qn7-in {\n  flex: 1;\n  min-width: 80px;\n  height: 28px;\n  margin: 0;\n  padding: 0 2px;\n  border: 0;\n  outline: 0;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 14px;\n}\n.hb-qn7-in::placeholder { color: #5f5f5f; }\n.hb-qn7-foot { display: flex; justify-content: space-between; gap: 12px; margin: 6px 4px 0; font-size: 12px; color: #6f6f6f; }\n.hb-qn7-count { margin-left: auto; font-variant-numeric: tabular-nums; transition: color 0.2s ease; }\n.hb-qn7-count[data-full=\"true\"] { color: var(--hb-qn7-a); }\n.hb-qn7-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }\n@keyframes hb-qn7-in {\n  0% { opacity: 0; transform: scale(0.55); }\n  100% { opacity: 1; transform: scale(1); }\n}\n@keyframes hb-qn7-out {\n  0% { opacity: 1; transform: scale(1); }\n  100% { opacity: 0; transform: scale(0.55); }\n}\n@keyframes hb-qn7-dupe {\n  0%, 100% { transform: translateX(0); }\n  25% { transform: translateX(-4px); }\n  75% { transform: translateX(4px); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qn7-box, .hb-qn7-x, .hb-qn7-count { transition: none; }\n  .hb-qn7-chip, .hb-qn7-chip[data-leaving=\"true\"], .hb-qn7-chip[data-dupe=\"true\"] { animation: none; }\n}\n`;\n\nexport function InputTags({\n  value,\n  defaultValue = [],\n  onValueChange,\n  max,\n  placeholder = \"Add a tag\",\n  validate,\n  label = \"Tags\",\n  name,\n  disabled = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: InputTagsProps) {\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState<string[]>(defaultValue);\n  const tags = controlled ? value : inner;\n  const tagsRef = React.useRef(tags);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const timers = React.useRef<number[]>([]);\n  const [draft, setDraft] = React.useState(\"\");\n  const [leaving, setLeaving] = React.useState<string[]>([]);\n  const [dupe, setDupe] = React.useState<string | null>(null);\n  const [announce, setAnnounce] = React.useState(\"\");\n  const full = max !== undefined && tags.length >= max;\n\n  React.useEffect(() => {\n    tagsRef.current = tags;\n  });\n\n  React.useEffect(() => {\n    const list = timers.current;\n    return () => {\n      list.forEach((id) => window.clearTimeout(id));\n    };\n  }, []);\n\n  function commit(next: string[]) {\n    tagsRef.current = next;\n    if (!controlled) setInner(next);\n    onValueChange?.(next);\n  }\n\n  function addMany(raw: string[]) {\n    const next = [...tagsRef.current];\n    let rejected: string | null = null;\n    for (const part of raw) {\n      const tag = part.trim();\n      if (!tag) continue;\n      if (next.includes(tag)) {\n        rejected = tag;\n        continue;\n      }\n      if (max !== undefined && next.length >= max) break;\n      if (validate && !validate(tag)) continue;\n      next.push(tag);\n    }\n    if (next.length !== tagsRef.current.length) {\n      const added = next.slice(tagsRef.current.length);\n      commit(next);\n      setAnnounce(`Added ${added.join(\", \")}`);\n    }\n    if (rejected) {\n      setDupe(rejected);\n      timers.current.push(window.setTimeout(() => setDupe(null), 450));\n    }\n  }\n\n  function remove(tag: string) {\n    if (leaving.includes(tag)) return;\n    setLeaving((list) => [...list, tag]);\n    const reduce = typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    timers.current.push(\n      window.setTimeout(\n        () => {\n          commit(tagsRef.current.filter((t) => t !== tag));\n          setLeaving((list) => list.filter((t) => t !== tag));\n          setAnnounce(`Removed ${tag}`);\n        },\n        reduce ? 0 : 180,\n      ),\n    );\n  }\n\n  function handleChange(e: React.ChangeEvent<HTMLInputElement>) {\n    const text = e.target.value;\n    if (!/[,\\n]/.test(text)) {\n      setDraft(text);\n      return;\n    }\n    const parts = text.split(/[,\\n]/);\n    const rest = parts.pop() ?? \"\";\n    addMany(parts);\n    setDraft(rest.trimStart());\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n    if (e.key === \"Enter\") {\n      e.preventDefault();\n      if (draft.trim()) {\n        addMany([draft]);\n        setDraft(\"\");\n      }\n      return;\n    }\n    if (e.key === \"Backspace\" && draft === \"\") {\n      const live = tagsRef.current.filter((t) => !leaving.includes(t));\n      const last = live[live.length - 1];\n      if (last !== undefined) remove(last);\n    }\n  }\n\n  function handleBlur() {\n    if (draft.trim()) {\n      addMany([draft]);\n      setDraft(\"\");\n    }\n  }\n\n  const vars = { \"--hb-qn7-a\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-input-tags\" precedence=\"default\">{css}</style>\n      <div className={`hb-qn7 ${className}`} style={vars} data-disabled={disabled} {...rest}>\n        <div\n          className=\"hb-qn7-box\"\n          role=\"group\"\n          aria-label={label}\n          onClick={(e) => {\n            if (e.target === e.currentTarget) inputRef.current?.focus();\n          }}\n        >\n          {tags.map((tag) => (\n            <span\n              key={tag}\n              className=\"hb-qn7-chip\"\n              data-leaving={leaving.includes(tag)}\n              data-dupe={dupe === tag}\n            >\n              <span className=\"hb-qn7-text\">{tag}</span>\n              <button\n                type=\"button\"\n                className=\"hb-qn7-x\"\n                aria-label={`Remove ${tag}`}\n                disabled={disabled}\n                onClick={() => {\n                  remove(tag);\n                  inputRef.current?.focus();\n                }}\n              >\n                <svg viewBox=\"0 0 10 10\" focusable=\"false\" aria-hidden=\"true\">\n                  <path d=\"M2 2l6 6M8 2L2 8\" />\n                </svg>\n              </button>\n            </span>\n          ))}\n          <input\n            ref={inputRef}\n            className=\"hb-qn7-in\"\n            value={draft}\n            disabled={disabled}\n            readOnly={full}\n            placeholder={full ? \"Limit reached\" : tags.length === 0 ? placeholder : \"\"}\n            aria-label={`${label}: type a tag and press Enter`}\n            autoComplete=\"off\"\n            onChange={handleChange}\n            onKeyDown={handleKeyDown}\n            onBlur={handleBlur}\n          />\n        </div>\n        {max !== undefined ? (\n          <div className=\"hb-qn7-foot\">\n            <span className=\"hb-qn7-count\" data-full={full}>\n              {tags.length}/{max}\n            </span>\n          </div>\n        ) : null}\n        {name ? <input type=\"hidden\" name={name} value={tags.join(\",\")} /> : null}\n        <span className=\"hb-qn7-sr\" role=\"status\" aria-live=\"polite\">\n          {announce}\n        </span>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}