mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-06 06:17:11 -04:00
27 lines
619 B
JavaScript
27 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 };
|