mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-25 17:26:15 -04:00
feat(copy): support legacy copy to clipboard for older browser (#581)
This commit is contained in:
parent
76b2761d62
commit
6f93cba3da
11 changed files with 47 additions and 53 deletions
|
@ -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);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue