2023-03-28 23:31:11 +02:00
|
|
|
<script setup lang="ts">
|
2023-08-22 01:00:20 +02:00
|
|
|
import { useCopy } from '@/composable/copy';
|
2023-03-28 23:31:11 +02:00
|
|
|
|
2023-04-19 20:30:45 +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';
|
|
|
|
|
2023-08-22 01:00:20 +02:00
|
|
|
const { copy, isJustCopied } = useCopy({ source: value, createToast: false });
|
|
|
|
const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : initialText);
|
2023-03-28 23:31:11 +02:00
|
|
|
</script>
|
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<template>
|
|
|
|
<n-tooltip trigger="hover">
|
|
|
|
<template #trigger>
|
2023-08-22 01:00:20 +02:00
|
|
|
<span class="value" @click="copy()">{{ value }}</span>
|
2023-05-28 23:13:24 +02:00
|
|
|
</template>
|
|
|
|
{{ tooltipText }}
|
|
|
|
</n-tooltip>
|
|
|
|
</template>
|
|
|
|
|
2023-03-28 23:31:11 +02:00
|
|
|
<style scoped lang="less">
|
2023-04-19 20:30:45 +02:00
|
|
|
.value {
|
2023-03-28 23:31:11 +02:00
|
|
|
cursor: pointer;
|
2023-04-19 20:30:45 +02:00
|
|
|
font-family: monospace;
|
2023-03-28 23:31:11 +02:00
|
|
|
}
|
|
|
|
</style>
|