it-tools/src/components/SpanCopyable.vue

18 lines
542 B
Vue
Raw Normal View History

2023-03-28 23:31:11 +02:00
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
2023-03-28 23:31:11 +02:00
const props = withDefaults(defineProps<{ value?: string }>(), { value: '' });
const { value } = toRefs(props);
2023-03-28 23:31:11 +02:00
const initialText = 'Copy to clipboard';
const { copy, isJustCopied } = useCopy({ source: value, createToast: false });
const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : initialText);
2023-03-28 23:31:11 +02:00
</script>
<template>
<c-tooltip :tooltip="tooltipText">
<span cursor-pointer font-mono @click="copy()">{{ value }}</span>
</c-tooltip>
</template>