mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 06:55:06 -04:00
14 lines
554 B
TypeScript
14 lines
554 B
TypeScript
import { type MaybeRef, get, useClipboard } from '@vueuse/core';
|
|
import { useMessage } from 'naive-ui';
|
|
|
|
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 {
|
|
async copy(content?: string, { notificationMessage }: { notificationMessage?: string } = {}) {
|
|
await copy();
|
|
message.success(notificationMessage ?? text);
|
|
},
|
|
};
|
|
}
|