import { ComputedRef, Ref } from '../../node_modules/vue'; /** * Copies content to the clipboard. May run synchronously (HTML copy) or return * a promise (text copy); both shapes are awaited by {@link useHapticCopy}. */ export type HapticCopyAction = () => void | Promise; /** * Resolves a feedback message key into the string shown in the tooltip. The * default implementation returns the key untouched; consumers usually plug an * i18n translator in here. */ export type HapticCopyMessageResolver = (message: string) => string; /** * Optional callbacks fired across the copy lifecycle, mirroring the events a * host component typically re-emits to its parent. */ export interface UseHapticCopyOptions { /** * Performs the actual clipboard write. Defaults to a no-op so the composable * can be wired incrementally. */ copy?: HapticCopyAction; /** * Turns a message key into the displayed tooltip text. Defaults to identity. */ resolveMessage?: HapticCopyMessageResolver; /** * Delay, in milliseconds, before the success/failure feedback is hidden. * Accepts a getter so a reactive delay is read afresh on every copy. */ hideDelay?: number | (() => number); /** * Message key displayed when the copy succeeds. */ succeedMessage?: string; /** * Message key displayed when the copy fails. */ failedMessage?: string; /** * Called before the copy attempt starts. */ onAttempt?: () => void; /** * Called once the copy succeeds. */ onSuccess?: () => void; /** * Called with the thrown error when the copy fails. */ onError?: (error: unknown) => void; /** * Called when the feedback is hidden, either after the delay or on cleanup. */ onHide?: () => void; } /** * Reactive API returned by {@link useHapticCopy}. */ export interface UseHapticCopy { /** * Run the copy action, surface success/failure feedback, then hide it after * the configured delay. */ copy: () => Promise; /** * Text currently displayed in the feedback tooltip. */ tooltipContent: Ref; /** * Whether the feedback tooltip is requested to be shown. */ showTooltip: Ref; /** * Whether the transient "copied!" feedback is currently active, i.e. a hide * timer is pending. Drives the success/idle icon swap in host components. */ isVisible: ComputedRef; /** * Hide the feedback tooltip and clear any pending hide timer. */ close: () => Promise; } /** * Owns the transient "copied!" feedback shown after a clipboard write: the * tooltip message, its visibility, and the timer that resets it. The copy * itself is delegated to the {@link UseHapticCopyOptions.copy} action so the * composable stays agnostic of text vs HTML clipboard strategies. * * The single hide timer is always cleared before a new one is scheduled, so * repeated copies never stack overlapping resets, and it is cleared again on * unmount to avoid running after the host is gone. * * @param options - Copy action, message resolver, delay and lifecycle hooks * (see {@link UseHapticCopyOptions}). * @returns The {@link UseHapticCopy} API: the `copy` action, the reactive * `tooltipContent`, `showTooltip` and `isVisible` state, and the `close` * handler. * @example * const { copy, tooltipContent, isVisible } = useHapticCopy({ * copy: () => navigator.clipboard.writeText('hello'), * resolveMessage: (key) => translate(key), * onSuccess: () => { * // show a toast, log analytics, etc. * } * }) */ export declare function useHapticCopy(options?: UseHapticCopyOptions): UseHapticCopy; export default useHapticCopy;