{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "comp-35",
  "type": "registry:component",
  "registryDependencies": [
    "https://coss.com/origin/r/input.json",
    "https://coss.com/origin/r/label.json"
  ],
  "files": [
    {
      "path": "registry/default/components/comp-35.tsx",
      "content": "\"use client\";\n\nimport { useId } from \"react\";\n\nimport { useCharacterLimit } from \"@/registry/default/hooks/use-character-limit\";\nimport { Input } from \"@/registry/default/ui/input\";\nimport { Label } from \"@/registry/default/ui/label\";\n\nexport default function Component() {\n  const id = useId();\n  const maxLength = 8;\n  const {\n    value,\n    characterCount,\n    handleChange,\n    maxLength: limit,\n  } = useCharacterLimit({ maxLength });\n\n  return (\n    <div className=\"*:not-first:mt-2\">\n      <Label htmlFor={id}>Input with characters left</Label>\n      <Input\n        aria-describedby={`${id}-description`}\n        id={id}\n        maxLength={maxLength}\n        onChange={handleChange}\n        type=\"text\"\n        value={value}\n      />\n      <p\n        aria-live=\"polite\"\n        className=\"mt-2 text-muted-foreground text-xs\"\n        id={`${id}-description`}\n        role=\"status\"\n      >\n        <span className=\"tabular-nums\">{limit - characterCount}</span>{\" \"}\n        characters left\n      </p>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    },
    {
      "path": "registry/default/hooks/use-character-limit.ts",
      "content": "\"use client\";\n\nimport { type ChangeEvent, useState } from \"react\";\n\ntype UseCharacterLimitProps = {\n  maxLength: number;\n  initialValue?: string;\n};\n\nexport function useCharacterLimit({\n  maxLength,\n  initialValue = \"\",\n}: UseCharacterLimitProps) {\n  const [value, setValue] = useState(initialValue);\n  const [characterCount, setCharacterCount] = useState(initialValue.length);\n\n  const handleChange = (\n    e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,\n  ) => {\n    const newValue = e.target.value;\n    if (newValue.length <= maxLength) {\n      setValue(newValue);\n      setCharacterCount(newValue.length);\n    }\n  };\n\n  return {\n    characterCount,\n    handleChange,\n    maxLength,\n    value,\n  };\n}\n",
      "type": "registry:hook"
    }
  ],
  "meta": {
    "tags": [
      "input",
      "label"
    ]
  }
}