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! ⚡

77 lines • 2.28 kB
/** * Options for the `useClipboard` hook. */ export interface UseClipboardOptions { /** * The duration in milliseconds after which the `copied` state resets to `false`. * * @defaultValue 2000 */ timeout?: number; } /** * Return type for the `useClipboard` hook. */ export interface UseClipboardReturn { /** * Whether the text was successfully copied to the clipboard. */ copied: boolean; /** * Copies the provided text to the clipboard. * * @param text - The text to copy. * @returns A promise that resolves when the copy operation completes. */ copy: (text: string) => Promise<void>; /** * The error that occurred during the copy operation, or `null` if no error occurred. */ error: Error | null; } /** * Copies text to the clipboard with success/error state management. * * @remarks * This hook provides a simple interface for copying text to the clipboard using * the Clipboard API. It manages the `copied` state that automatically resets * after a configurable timeout, and handles errors gracefully when the Clipboard * API is unavailable or the operation fails. * * The hook is SSR-safe and will handle the case where `navigator.clipboard` is * not available (e.g., in non-secure contexts or older browsers). * * @param options - Configuration options for the hook. * @returns An object containing the copied state, copy function, and any error. * * @example * ```tsx * function CopyButton({textToCopy}: {textToCopy: string}) { * const {copied, copy, error} = useClipboard({timeout: 3000}); * * return ( * <div> * <button onClick={() => copy(textToCopy)}> * {copied ? "Copied!" : "Copy to clipboard"} * </button> * {error && <span>Failed to copy: {error.message}</span>} * </div> * ); * } * ``` * * @example * ```tsx * function ShareLink({url}: {url: string}) { * const {copied, copy} = useClipboard(); * * return ( * <button onClick={() => copy(url)} disabled={copied}> * {copied ? "✓ Copied" : "Share link"} * </button> * ); * } * ``` */ export declare function useClipboard(options?: UseClipboardOptions): UseClipboardReturn; //# sourceMappingURL=useClipboard.d.ts.map