mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 22:07:10 -04:00
26 lines
619 B
JavaScript
26 lines
619 B
JavaScript
import { useClipboard } from '@vueuse/core';
|
|
import { useMessage } from 'naive-ui';
|
|
|
|
function useCopy({ source, text = "Copied to the clipboard", createToast = true } = {}) {
|
|
const { copy, copied, ...rest } = useClipboard({
|
|
source,
|
|
legacy: true
|
|
});
|
|
const message = useMessage();
|
|
return {
|
|
...rest,
|
|
isJustCopied: copied,
|
|
async copy(content, { notificationMessage } = {}) {
|
|
if (source) {
|
|
await copy();
|
|
} else {
|
|
await copy(content);
|
|
}
|
|
if (createToast) {
|
|
message.success(notificationMessage ?? text);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
export { useCopy as u };
|