{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "use-copy-to-clipboard", "description": "A custom hook to copy text to the clipboard.", "files": [ { "path": "src/registry/new-york/hooks/use-copy-to-clipboard.ts", "content": "import { useCallback, useState } from \"react\";\n\n/**\n * Custom hook to copy text to clipboard.\n * @returns {Object} An object containing the copy function, copied state, and error state.\n */\n\ninterface UseCopyToClipboardResult {\n copy: (text: string) => Promise;\n copied: boolean;\n error: string | null;\n}\n\nexport function useCopyToClipboard(): UseCopyToClipboardResult {\n const [copied, setCopied] = useState(false);\n const [error, setError] = useState(null);\n\n const copy = useCallback(async (text: string): Promise => {\n if (!navigator?.clipboard) {\n setError(\"Clipboard API not supported\");\n return false;\n }\n\n try {\n await navigator.clipboard.writeText(text);\n setCopied(true);\n setError(null);\n\n setTimeout(() => setCopied(false), 2000);\n return true;\n } catch {\n setError(\"Failed to copy\");\n setCopied(false);\n return false;\n }\n }, []);\n\n return { copy, copied, error };\n}\n", "type": "registry:hook" } ], "type": "registry:hook" }