import type { PrimitivePropsWithRef } from '../utils/primitive.js'; /** * The three states a {@link Clipboard} can be in, mirrored onto `data-state` on * every part: copied, idle, or error after a failed copy. */ export type ClipboardState = 'copied' | 'idle' | 'error'; /** * The handle a {@link Clipboard}'s forwarded ref carries: the root `
` with * `copy()` method assigned, preserving all standard HTMLDivElement methods. */ export interface ClipboardHandle extends HTMLDivElement { /** * Performs the copy a `ClipboardTrigger` would, from outside the component; a no-op while the root is `disabled`. */ copy(): void; } /** @internal Shared state distributed from {@link Clipboard} to its parts via context. */ export interface ClipboardContextValue { value: string; /** The root's current state, which every part mirrors onto its own `data-state`. */ state: ClipboardState; disabled: boolean; copy: () => void; } /** * Props for the {@link Clipboard} root, whose `onCopySuccess` (copy trigger fired) is distinct from React's `onCopy` (user selection copied). */ export interface ClipboardProps extends PrimitivePropsWithRef<'div'> { /** The text written to the system clipboard when a `ClipboardTrigger` is activated. */ value: string; /** * How long the `copied` state lasts, in milliseconds, before falling back to `idle`; pass `null` to keep it until the next copy. * @default 2000 — long enough to read the confirmation, short enough that a second copy still feels like it did something. */ timeout?: number | null | undefined; /** * Fires with the copied text after the write succeeds — never on failure, * safe for analytics or toasts. * @default undefined — no-op if omitted. */ onCopySuccess?: ((value: string) => void) | undefined; /** * Fires with the failure when both the async Clipboard API and the `execCommand` fallback fail; never thrown into render, never swallowed silently. * @default undefined — the error is reported nowhere if omitted, and the `copied` state simply never turns on. */ onCopyError?: ((error: unknown) => void) | undefined; /** * Disables the trigger and blocks copying entirely. * @default false */ disabled?: boolean | undefined; /** * The polite live-region message announced after a successful copy, the only feedback a screen-reader user gets; pass `''` to announce nothing. * @default 'Copied to clipboard' */ copiedLabel?: string | undefined; /** * The live-region message announced *assertively* when the copy fails; pass `''` to announce nothing while `data-state="error"` and `onCopyError` still fire. * @default 'Copy failed' */ errorLabel?: string | undefined; /** * The derived `ClipboardTrigger`'s accessible name; ignored when `children` is given. * @default 'Copy' */ label?: string | undefined; /** * Renders a derived, read-only `ClipboardInput` showing `value` ahead of the trigger; ignored when `children` is given. * @default false */ showInput?: boolean | undefined; /** * The derived `ClipboardInput`'s accessible name, a separate prop from `label`; rendered only while `showInput` is set. * @default 'Value to copy' */ inputLabel?: string | undefined; /** * Size rung the skin scales the control by, mirrored to `data-size`. * @default undefined — the skin's own default size. */ size?: 'md' | 'sm' | 'lg' | (string & {}) | undefined; } /** Props for the {@link ClipboardTrigger} button. */ export interface ClipboardTriggerProps extends PrimitivePropsWithRef<'button'> { /** * Disables just this trigger; a disabled root disables every trigger regardless of this prop. * @default false — the trigger follows the root's `disabled`. */ disabled?: boolean | undefined; } /** Props for a {@link ClipboardIndicator}, the mark shown in one copy state. */ export interface ClipboardIndicatorProps extends PrimitivePropsWithRef<'span'> { /** * Which state this indicator renders in — `'copied'` for the checkmark, `'idle'` for the copy icon, `'error'` for a failure glyph. * @default 'copied' — the confirmation, which is the one that needs mounting logic. */ match?: ClipboardState | undefined; } /** Props for the optional {@link ClipboardInput}. */ export interface ClipboardInputProps extends Omit, 'value' | 'defaultValue'> { }