(text: any)
| 66 | } |
| 67 | |
| 68 | const fallbackCopyTextToClipboard = (text: any) => { |
| 69 | const textArea = document.createElement('textarea'); |
| 70 | textArea.value = text; |
| 71 | document.body.appendChild(textArea); |
| 72 | textArea.focus(); |
| 73 | textArea.select(); |
| 74 | |
| 75 | try { |
| 76 | const successful = document.execCommand('copy'); |
| 77 | const msg = successful ? 'successful' : 'unsuccessful'; |
| 78 | console.log('Fallback: Copying text command was ' + msg); |
| 79 | } catch (err) { |
| 80 | console.error('Fallback: Oops, unable to copy', err); |
| 81 | } |
| 82 | |
| 83 | document.body.removeChild(textArea); |
| 84 | }; |
| 85 | export function copyToClipboard(text: string) { |
| 86 | if (!(navigator as any).clipboard) { |
| 87 | fallbackCopyTextToClipboard(text); |
no test coverage detected