Skip to content

Commit

Permalink
feat(Copied): using replication in non-https environments (#56)
Browse files Browse the repository at this point in the history
Co-authored-by: gaopw5 <gaopw5@chinaunicom.cn>
  • Loading branch information
Gao-pw and gaopw5 authored Aug 6, 2024
1 parent cd4d825 commit 8375038
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion core/src/comps/Copied.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,28 @@ export const Copied = <T extends object, K extends TagType>(props: CopiedProps<T
}
onCopied && onCopied(copyText, value);
setCopied(true);
navigator.clipboard

const _clipboard = navigator.clipboard || {
writeText(text: string) {
return new Promise((reslove, reject) => {
const textarea = document.createElement('textarea');
textarea.style.position = 'absolute';
textarea.style.opacity = '0';
textarea.style.left = '-99999999px';
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
if (!document.execCommand('copy')) {
reject();
} else {
reslove();
}
textarea.remove();
});
},
};

_clipboard
.writeText(copyText)
.then(() => {
const timer = setTimeout(() => {
Expand Down

0 comments on commit 8375038

Please sign in to comment.