(text?: string)
| 67 | } |
| 68 | |
| 69 | export function useCopyText(text?: string): [boolean, CopyNotifyFunction] { |
| 70 | const [copying, setCopying] = useState(false); |
| 71 | const { displayToast } = useToastNotification(); |
| 72 | |
| 73 | const copy: CopyNotifyFunction = async (props = {}) => { |
| 74 | await navigator.clipboard.writeText(props.textToCopy || text); |
| 75 | |
| 76 | if (!props.disableToast) { |
| 77 | displayToast(props.message || defaultMessage, props); |
| 78 | } |
| 79 | |
| 80 | setCopying(true); |
| 81 | setTimeout(() => { |
| 82 | setCopying(false); |
| 83 | }, 1000); |
| 84 | }; |
| 85 | |
| 86 | return [copying, copy]; |
| 87 | } |
no test coverage detected