const copyToClipboard = (textToCopy: string) => {
if (navigator.clipboard && window.isSecureContext) {
return navigator.clipboard.writeText(textToCopy);
} else {
let textArea = document.createElement('textarea');
textArea.value = textToCopy;
textArea.style.position = 'absolute';
textArea.style.opacity = '0';
textArea.style.left = '-9999px';
textArea.style.bottom = '9999px';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
return new Promise(function (res, rej) {
document.execCommand('copy') ? res(true) : rej();
textArea.remove();
});
}
};