{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-auto-resize-textarea",
  "type": "registry:hook",
  "title": "useAutoResizeTextarea",
  "description": "Grows a textarea with its content (KokonutUI, MIT).",
  "files": [
    {
      "path": "registry/hooks/use-auto-resize-textarea.ts",
      "type": "registry:hook",
      "content": "/* use-auto-resize-textarea — KokonutUI (MIT). https://github.com/kokonut-labs/kokonutui\n   Grows a <textarea> with its content, clamped between minHeight and maxHeight. */\nimport { useCallback, useEffect, useRef } from \"react\";\n\ninterface UseAutoResizeTextareaProps {\n  minHeight: number;\n  maxHeight?: number;\n}\n\nexport function useAutoResizeTextarea({\n  minHeight,\n  maxHeight,\n}: UseAutoResizeTextareaProps) {\n  const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n  const adjustHeight = useCallback(\n    (reset?: boolean) => {\n      const textarea = textareaRef.current;\n      if (!textarea) return;\n\n      if (reset) {\n        textarea.style.height = `${minHeight}px`;\n        return;\n      }\n\n      // Temporarily shrink to read the true scrollHeight.\n      textarea.style.height = `${minHeight}px`;\n\n      const newHeight = Math.max(\n        minHeight,\n        Math.min(textarea.scrollHeight, maxHeight ?? Number.POSITIVE_INFINITY)\n      );\n\n      textarea.style.height = `${newHeight}px`;\n    },\n    [minHeight, maxHeight]\n  );\n\n  useEffect(() => {\n    const textarea = textareaRef.current;\n    if (textarea) {\n      textarea.style.height = `${minHeight}px`;\n    }\n  }, [minHeight]);\n\n  useEffect(() => {\n    const handleResize = () => adjustHeight();\n    window.addEventListener(\"resize\", handleResize);\n    return () => window.removeEventListener(\"resize\", handleResize);\n  }, [adjustHeight]);\n\n  return { textareaRef, adjustHeight };\n}\n"
    }
  ]
}
