You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.js 514B

1234567891011121314151617181920212223
  1. // @flow
  2. /**
  3. * Tries to copy a given text to the clipboard.
  4. *
  5. * @param {string} textToCopy - Text to be copied.
  6. * @returns {boolean}
  7. */
  8. export function copyText(textToCopy: string) {
  9. const fakeTextArea = document.createElement('textarea');
  10. // $FlowFixMe
  11. document.body.appendChild(fakeTextArea);
  12. fakeTextArea.value = textToCopy;
  13. fakeTextArea.select();
  14. const result = document.execCommand('copy');
  15. // $FlowFixMe
  16. document.body.removeChild(fakeTextArea);
  17. return result;
  18. }