UNPKG

@arolariu/components

Version:

🎨 70+ beautiful, accessible React components built on Base UI. TypeScript-first, CSS Modules styling, tree-shakeable, SSR-ready. Perfect for modern web apps, design systems & rapid prototyping. Zero config, maximum flexibility! ⚡

43 lines (42 loc) • 1.53 kB
"use client"; import * as __rspack_external_react from "react"; function useClipboard(options = {}) { const { timeout = 2000 } = options; const [copied, setCopied] = __rspack_external_react.useState(false); const [error, setError] = __rspack_external_react.useState(null); const timeoutRef = __rspack_external_react.useRef(null); const scheduleReset = __rspack_external_react.useCallback(()=>{ if (null !== timeoutRef.current) clearTimeout(timeoutRef.current); timeoutRef.current = setTimeout(()=>{ setCopied(false); timeoutRef.current = null; }, timeout); }, [ timeout ]); const copy = __rspack_external_react.useCallback(async (text)=>{ setError(null); try { if (globalThis.navigator?.clipboard === void 0) throw new Error("Clipboard API is not available"); await globalThis.navigator.clipboard.writeText(text); setCopied(true); scheduleReset(); } catch (error_) { const errorMessage = error_ instanceof Error ? error_ : new Error("Failed to copy to clipboard"); setError(errorMessage); setCopied(false); } }, [ scheduleReset ]); __rspack_external_react.useEffect(()=>()=>{ if (null !== timeoutRef.current) clearTimeout(timeoutRef.current); }, []); return { copied, copy, error }; } export { useClipboard }; //# sourceMappingURL=useClipboard.js.map