it-tools/src/components/SpanCopyable.vue

28 lines
681 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>
<n-tooltip trigger="hover">
<template #trigger>
<span class="value" @click="copy()">{{ value }}</span>
</template>
{{ tooltipText }}
</n-tooltip>
</template>
2023-03-28 23:31:11 +02:00
<style scoped lang="less">
.value {
2023-03-28 23:31:11 +02:00
cursor: pointer;
font-family: monospace;
2023-03-28 23:31:11 +02:00
}
</style>