{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "use-click-outside", "description": "A custom hook to detect clicks outside a specified element.", "files": [ { "path": "src/registry/new-york/hooks/use-click-outside.ts", "content": "import { useEffect, useRef } from \"react\";\n\n/**\n * Custom hook to detect clicks outside the element.\n * @param callback - Function to call when a click outside the element is detected.\n * @returns A ref to attach to the element you want to monitor for outside clicks.\n */\n\nexport function useClickOutside(callback: () => void) {\n const ref = useRef(null);\n\n useEffect(() => {\n function handleClick(e: MouseEvent) {\n if (ref.current && !ref.current.contains(e.target as Node)) {\n callback();\n }\n }\n document.addEventListener(\"mousedown\", handleClick);\n return () => document.removeEventListener(\"mousedown\", handleClick);\n }, [callback]);\n\n return ref;\n}\n", "type": "registry:hook" } ], "type": "registry:hook" }