feat(copy): support legacy copy to clipboard for older browser (#581)
This commit is contained in:
1 parent
76b2761d62
commit
6f93cba3da
11 files changed
+47
-53
No files matched your search
+14
-4
@@ -1,11 +1,19 @@
|
||||
import { type MaybeRef, get, useClipboard } from '@vueuse/core';
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { useClipboard } from '@vueuse/core';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import type { MaybeRefOrGetter } from 'vue';
|
||||
|
||||
export function useCopy({ source, text = 'Copied to the clipboard', createToast = true }: { source?: MaybeRefOrGetter<string>; text?: string; createToast?: boolean } = {}) {
|
||||
const { copy, copied, ...rest } = useClipboard({
|
||||
source,
|
||||
legacy: true,
|
||||
});
|
||||
|
||||
export function useCopy({ source, text = 'Copied to the clipboard' }: { source?: MaybeRef<unknown>; text?: string } = {}) {
|
||||
const { copy } = useClipboard(source ? { source: computed(() => String(get(source))) } : {});
|
||||
const message = useMessage();
|
||||
|
||||
return {
|
||||
...rest,
|
||||
isJustCopied: copied,
|
||||
async copy(content?: string, { notificationMessage }: { notificationMessage?: string } = {}) {
|
||||
if (source) {
|
||||
await copy();
|
||||
@@ -14,7 +22,9 @@ export function useCopy({ source, text = 'Copied to the clipboard' }: { source?:
|
||||
await copy(content);
|
||||
}
|
||||
|
||||
message.success(notificationMessage ?? text);
|
||||
if (createToast) {
|
||||
message.success(notificationMessage ?? text);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user