mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 14:56:17 -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,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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue