diff options
author | 2023-08-22 01:00:20 +0200 | |
---|---|---|
committer | 2023-08-21 23:00:20 +0000 | |
commit | 6f93cba3dad3bff0e727e4edf78f830311c0c3da (patch) | |
tree | c6bb4a2f02309979c7f19ac426a6737d4f3cb55f /src/components/SpanCopyable.vue | |
parent | 76b2761d62f459442989c6a55518408b68f0ad34 (diff) | |
download | it-tools-6f93cba3dad3bff0e727e4edf78f830311c0c3da.tar.gz it-tools-6f93cba3dad3bff0e727e4edf78f830311c0c3da.tar.zst it-tools-6f93cba3dad3bff0e727e4edf78f830311c0c3da.zip |
feat(copy): support legacy copy to clipboard for older browser (#581)
Diffstat (limited to 'src/components/SpanCopyable.vue')
-rw-r--r-- | src/components/SpanCopyable.vue | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/components/SpanCopyable.vue b/src/components/SpanCopyable.vue index 17b1a59..7ab3a1d 100644 --- a/src/components/SpanCopyable.vue +++ b/src/components/SpanCopyable.vue @@ -1,26 +1,19 @@ <script setup lang="ts"> -import { useClipboard } from '@vueuse/core'; +import { useCopy } from '@/composable/copy'; const props = withDefaults(defineProps<{ value?: string }>(), { value: '' }); const { value } = toRefs(props); const initialText = 'Copy to clipboard'; -const tooltipText = ref(initialText); -const { copy } = useClipboard({ source: value }); - -function handleClick() { - copy(); - tooltipText.value = 'Copied!'; - - setTimeout(() => (tooltipText.value = initialText), 1000); -} +const { copy, isJustCopied } = useCopy({ source: value, createToast: false }); +const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : initialText); </script> <template> <n-tooltip trigger="hover"> <template #trigger> - <span class="value" @click="handleClick">{{ value }}</span> + <span class="value" @click="copy()">{{ value }}</span> </template> {{ tooltipText }} </n-tooltip> |