@wordpress/compose
Version:
WordPress higher-order components (HOCs).
28 lines • 1.16 kB
TypeScript
import type { RefCallback } from 'react';
/**
* Copies text to the clipboard using the Clipboard API when available,
* with a fallback for non-secure contexts (e.g. HTTP) and older browsers.
*
* @param text The text to copy.
* @param trigger The element that triggered the copy.
* @return Resolves to true if successful, false otherwise.
*/
export declare function copyToClipboard(text: string, trigger: Element | null): Promise<boolean>;
/**
* Clears the current selection and restores focus to the trigger element.
*
* @param trigger The element that triggered the copy.
*/
export declare function clearSelection(trigger: Element): void;
/**
* Copies the given text to the clipboard when the element is clicked.
*
* @template T
* @param text The text to copy. Use a function if not
* already available and expensive to compute.
* @param onSuccess Called when to text is copied.
*
* @return A ref to assign to the target element.
*/
export default function useCopyToClipboard<T extends HTMLElement>(text: string | (() => string), onSuccess?: () => void): RefCallback<T>;
//# sourceMappingURL=index.d.ts.map