UNPKG

@gravity-ui/uikit

Version:

Gravity UI base styling and components

26 lines (25 loc) 848 B
/** * Copies text to the browser's clipboard. * Uses the modern `navigator.clipboard` API, with a fallback to `document.execCommand` when unavailable. * * @param {string} text Text to copy to the clipboard * @returns {Promise<void>} Promise that resolves on successful copy or rejects on error * @throws {Error} Throws an error if neither `navigator.clipboard` nor `document` is available * * @example * ```typescript * // Copy simple text * copyText('Hello, World!') * .then(() => console.log('Text copied')) * .catch(error => console.error('Copy error:', error)); * * // Using with async/await * try { * await copyText('Text to copy'); * console.log('Successfully copied'); * } catch (error) { * console.error('Failed to copy:', error); * } * ``` */ export declare function copyText(text: string): Promise<void>;