2023-03-28 23:31:11 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { useClipboard } from '@vueuse/core';
|
|
|
|
|
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';
|
|
|
|
const tooltipText = ref(initialText);
|
|
|
|
|
2023-04-19 20:30:45 +02:00
|
|
|
const { copy } = useClipboard({ source: value });
|
2023-03-28 23:31:11 +02:00
|
|
|
|
|
|
|
function handleClick() {
|
|
|
|
copy();
|
|
|
|
tooltipText.value = 'Copied!';
|
|
|
|
|
|
|
|
setTimeout(() => (tooltipText.value = initialText), 1000);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<template>
|
|
|
|
<n-tooltip trigger="hover">
|
|
|
|
<template #trigger>
|
|
|
|
<span class="value" @click="handleClick">{{ value }}</span>
|
|
|
|
</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>
|