{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-tag-input",
  "title": "Tag Input",
  "description": "Input field that converts typed text into removable tags or pills.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/badge",
    "@lema-ds/skeleton",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-tag-input.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { XIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { Badge } from \"@/components/ui/badge\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\n\n// ── Types ──\n\nexport interface TagInputProps\n  extends\n    Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\">,\n    VariantProps<typeof tagInputContainerVariants> {\n  value: string[]\n  onChange: (tags: string[]) => void\n  maxTags?: number\n  allowDuplicates?: boolean\n  separator?: string | RegExp | (string | RegExp)[]\n  placeholder?: string\n  loading?: boolean\n  disabled?: boolean\n  invalid?: boolean\n  locale?: UILocale\n}\n\n// ── Variants ──\n\nexport const tagInputContainerVariants = cva(\n  \"flex w-full flex-wrap items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-sm ring-offset-background transition-colors focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:outline-none\",\n  {\n    variants: {\n      size: {\n        sm: \"min-h-8 gap-1 px-2 py-1\",\n        md: \"min-h-9 gap-1.5 px-3 py-1.5\",\n        lg: \"min-h-10 gap-2 px-3 py-2\",\n      },\n      disabled: {\n        true: \"cursor-not-allowed opacity-50\",\n      },\n      invalid: {\n        true: \"border-destructive focus-within:ring-destructive\",\n      },\n    },\n    defaultVariants: {\n      size: \"md\",\n      disabled: false,\n      invalid: false,\n    },\n  }\n)\n\nexport const tagInputBadgeVariants = cva(\n  \"flex items-center gap-1 rounded-sm bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n  {\n    variants: {\n      size: {\n        sm: \"px-1.5 py-0.5 text-xs\",\n        md: \"px-2 py-0.5 text-sm\",\n        lg: \"px-2.5 py-1 text-base\",\n      },\n    },\n    defaultVariants: {\n      size: \"md\",\n    },\n  }\n)\n\nexport const tagInputInputVariants = cva(\n  \"flex-1 bg-transparent outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed\",\n  {\n    variants: {\n      size: {\n        sm: \"text-xs\",\n        md: \"text-sm\",\n        lg: \"text-base\",\n      },\n    },\n    defaultVariants: {\n      size: \"md\",\n    },\n  }\n)\n\n// ── Internal Helpers ──\n\nconst skeletonDims = {\n  sm: \"h-8 w-full\",\n  md: \"h-9 w-full\",\n  lg: \"h-10 w-full\",\n}\n\n// ── Component ──\n\nexport const TagInput = React.forwardRef<HTMLDivElement, TagInputProps>(\n  (\n    {\n      value,\n      onChange,\n      maxTags,\n      allowDuplicates = false,\n      separator = [\",\", \"Enter\"],\n      placeholder,\n      size = \"md\",\n      loading = false,\n      disabled = false,\n      invalid = false,\n      locale: localeProp,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const inputRef = React.useRef<HTMLInputElement>(null)\n    const [inputValue, setInputValue] = React.useState(\"\")\n    const i18n = UI_I18N[locale].tagInput\n\n    const handleContainerClick = () => {\n      if (!disabled) {\n        inputRef.current?.focus()\n      }\n    }\n\n    const addTag = React.useCallback(\n      (tagText: string) => {\n        const newTag = tagText.trim()\n        if (!newTag) return\n\n        if (maxTags !== undefined && value.length >= maxTags) {\n          return\n        }\n\n        if (!allowDuplicates && value.includes(newTag)) {\n          return\n        }\n\n        onChange([...value, newTag])\n        setInputValue(\"\")\n      },\n      [value, onChange, maxTags, allowDuplicates]\n    )\n\n    const removeTag = React.useCallback(\n      (indexToRemove: number) => {\n        onChange(value.filter((_, i) => i !== indexToRemove))\n      },\n      [value, onChange]\n    )\n\n    const handleKeyDown = React.useCallback(\n      (e: React.KeyboardEvent<HTMLInputElement>) => {\n        const separators = Array.isArray(separator) ? separator : [separator]\n        const isSeparator = separators.some((sep) => {\n          if (sep instanceof RegExp) {\n            return sep.test(e.key) || sep.test(inputValue) // simplified\n          }\n          return sep === e.key\n        })\n\n        if (isSeparator) {\n          e.preventDefault()\n          addTag(inputValue)\n          return\n        }\n\n        if (e.key === \"Backspace\" && inputValue === \"\" && value.length > 0) {\n          e.preventDefault()\n          removeTag(value.length - 1)\n        }\n      },\n      [inputValue, value, separator, addTag, removeTag]\n    )\n\n    const handleBlur = React.useCallback(() => {\n      addTag(inputValue)\n    }, [inputValue, addTag])\n\n    if (loading) {\n      return (\n        <Skeleton\n          data-slot=\"ds-tag-input-loading\"\n          className={cn(skeletonDims[size || \"md\"], className)}\n        />\n      )\n    }\n\n    const iconSize =\n      size === \"sm\" ? \"size-3\" : size === \"lg\" ? \"size-4\" : \"size-3.5\"\n\n    return (\n      <div\n        ref={ref}\n        data-slot=\"ds-tag-input\"\n        className={cn(\n          tagInputContainerVariants({ size, disabled, invalid }),\n          className\n        )}\n        onClick={handleContainerClick}\n        {...props}\n      >\n        {value.map((tag, index) => (\n          <Badge\n            key={`${tag}-${index}`}\n            variant=\"secondary\"\n            className={cn(tagInputBadgeVariants({ size }), \"h-fit\")}\n          >\n            <span className=\"max-w-50 truncate\">{tag}</span>\n            <button\n              type=\"button\"\n              className=\"ml-1 rounded-full ring-offset-background outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed\"\n              disabled={disabled}\n              onClick={(e) => {\n                e.stopPropagation()\n                removeTag(index)\n              }}\n              aria-label={`${i18n.removeTag} ${tag}`}\n            >\n              <XIcon\n                className={cn(iconSize, \"opacity-70 hover:opacity-100\")}\n                aria-hidden=\"true\"\n              />\n            </button>\n          </Badge>\n        ))}\n        <input\n          ref={inputRef}\n          type=\"text\"\n          className={cn(tagInputInputVariants({ size }))}\n          value={inputValue}\n          onChange={(e) => setInputValue(e.target.value)}\n          onKeyDown={handleKeyDown}\n          onBlur={handleBlur}\n          disabled={\n            disabled || (maxTags !== undefined && value.length >= maxTags)\n          }\n          placeholder={\n            maxTags !== undefined && value.length >= maxTags\n              ? i18n.maxReached\n              : value.length === 0\n                ? placeholder\n                : \"\"\n          }\n          aria-invalid={invalid}\n          aria-label={props[\"aria-label\"] || \"Tag input\"}\n        />\n      </div>\n    )\n  }\n)\nTagInput.displayName = \"TagInput\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
