{
  "name": "tag-input",
  "type": "ui:component",
  "title": "TagInput",
  "description": "Multi-chip tag entry field with Enter/comma creation, Backspace removal, and maxTags enforcement.",
  "dependencies": [
    "@lucide/icons"
  ],
  "registryDependencies": [
    "theme",
    "icon"
  ],
  "files": [
    {
      "path": "src/ui/tag-input.tsx",
      "target": "src/ui/tag-input.tsx",
      "sha256": "f692bd9ec02c6108d15dee7e5e6183dc050bc7ca87144de95305aa808b211db2",
      "content": "import './theme.css';\nimport { X } from '@lucide/icons';\nimport { scope, type Ctx } from '@fierst/aster';\nimport { Icon } from './icon';\n\nconst tagScope = scope`\n  :scope {\n    display: grid;\n    gap: 0.375rem;\n    font-family: var(--aster-font-sans);\n  }\n  .tag-label { font-size: 0.84rem; font-weight: 500; color: var(--aster-on-surface); }\n  .tag-box {\n    display: flex;\n    align-items: center;\n    flex-wrap: wrap;\n    gap: 0.35rem;\n    min-height: var(--aster-control-md);\n    padding: 0.3rem 0.55rem;\n    border-radius: var(--aster-radius-control);\n    border: 1px solid var(--aster-input-border);\n    background: var(--aster-surface);\n    box-shadow: var(--aster-shadow-xs);\n    transition: border-color var(--aster-dur-fast), box-shadow var(--aster-dur-fast);\n  }\n  .tag-box:focus-within { border-color: var(--aster-primary); box-shadow: var(--aster-focus-ring); }\n  .chip {\n    display: inline-flex;\n    align-items: center;\n    gap: 0.25rem;\n    padding: 0.14rem 0.45rem;\n    border-radius: var(--aster-radius-xs);\n    background: var(--aster-surface-muted);\n    border: 1px solid var(--aster-border);\n    color: var(--aster-on-surface);\n    font-size: 0.78rem;\n    font-weight: 500;\n  }\n  .chip-x {\n    border: none;\n    background: transparent;\n    color: var(--aster-on-surface-subtle);\n    padding: 0;\n    display: inline-grid;\n    place-items: center;\n    cursor: pointer;\n    border-radius: 2px;\n  }\n  .chip-x:hover { color: var(--aster-on-surface); }\n  .tag-input {\n    flex: 1;\n    min-width: 90px;\n    border: none;\n    outline: none;\n    background: transparent;\n    color: var(--aster-on-surface);\n    font: inherit;\n    font-size: 1rem;\n    padding: 0.15rem 0.2rem;\n  }\n  @media (min-width: 640px) {\n    .tag-input { font-size: 0.875rem; }\n  }\n  .tag-input::placeholder { color: var(--aster-on-surface-subtle); }\n  .tag-hint { font-size: 0.78rem; color: var(--aster-on-surface-muted); }\n`;\n\nlet tagSeq = 0;\n\nexport function* TagInput(\n  props: {\n    label?: string;\n    value?: readonly string[];\n    defaultValue?: readonly string[];\n    placeholder?: string;\n    hint?: string;\n    maxTags?: number;\n    disabled?: boolean;\n    onChange?: (tags: string[]) => void;\n    class?: string;\n  },\n  ctx: Ctx,\n) {\n  const uid = `aster-tag-${++tagSeq}`;\n  let internal = [...(props.defaultValue ?? [])];\n  let draft = '';\n\n  for (props of ctx) {\n    const isControlled = props.value !== undefined;\n    const tags = isControlled ? [...props.value!] : internal;\n    const maxTags = props.maxTags ?? 20;\n\n    const commit = (next: string[]) => {\n      if (!isControlled) internal = next;\n      props.onChange?.(next);\n    };\n\n    const addTag = (raw: string) => {\n      const cleaned = raw.trim();\n      if (!cleaned || tags.length >= maxTags) return;\n      if (!tags.includes(cleaned)) commit([...tags, cleaned]);\n      draft = '';\n    };\n\n    const removeTag = (val: string) => {\n      commit(tags.filter((t) => t !== val));\n    };\n\n    const onKeyDown = (e: KeyboardEvent) => {\n      if (e.key === 'Enter' || e.key === ',') {\n        e.preventDefault();\n        addTag(draft);\n      } else if (e.key === 'Backspace' && !draft && tags.length > 0) {\n        removeTag(tags[tags.length - 1]);\n      }\n    };\n\n    yield (\n      <div class={[tagScope, props.class].filter(Boolean).join(' ')}>\n        {props.label ? (\n          <label class=\"tag-label\" for={uid}>\n            {props.label}\n          </label>\n        ) : null}\n        <div class=\"tag-box\">\n          {tags.map((tag) => (\n            <span key={tag} class=\"chip\">\n              <span>{tag}</span>\n              {!props.disabled ? (\n                <button\n                  type=\"button\"\n                  class=\"chip-x\"\n                  aria-label={`Remove ${tag}`}\n                  onClick={() => removeTag(tag)}\n                >\n                  <Icon icon={X} size={12} />\n                </button>\n              ) : null}\n            </span>\n          ))}\n          <input\n            id={uid}\n            type=\"text\"\n            class=\"tag-input\"\n            disabled={props.disabled || tags.length >= maxTags}\n            bind:value={draft}\n            placeholder={tags.length === 0 ? (props.placeholder ?? 'Add tag and press Enter…') : ''}\n            onKeyDown={onKeyDown}\n            onBlur={() => draft.trim() && addTag(draft)}\n          />\n        </div>\n        {props.hint ? <span class=\"tag-hint\">{props.hint}</span> : null}\n      </div>\n    );\n  }\n}\n"
    }
  ]
}
