it-tools/src/components/InputCopyable.vue

37 lines
895 B
Vue
Raw Normal View History

2022-04-16 01:15:23 +02:00
<template>
<c-input-text v-model:value="value">
2022-04-16 01:15:23 +02:00
<template #suffix>
<n-tooltip trigger="hover">
<template #trigger>
<c-button circle variant="text" size="small" @click="onCopyClicked">
<icon-mdi-content-copy />
</c-button>
2022-04-16 01:15:23 +02:00
</template>
{{ tooltipText }}
</n-tooltip>
2022-04-22 23:31:40 +02:00
</template>
</c-input-text>
2022-04-16 01:15:23 +02:00
</template>
<script setup lang="ts">
2022-04-22 23:31:40 +02:00
import { useVModel, useClipboard } from '@vueuse/core';
2022-04-16 01:15:23 +02:00
import { ref } from 'vue';
2022-04-22 23:31:40 +02:00
const props = defineProps<{ value: string }>();
const emit = defineEmits(['update:value']);
2022-04-16 01:15:23 +02:00
2022-04-22 23:31:40 +02:00
const value = useVModel(props, 'value', emit);
const tooltipText = ref('Copy to clipboard');
2022-04-16 01:15:23 +02:00
2022-04-22 23:31:40 +02:00
const { copy } = useClipboard({ source: value });
2022-04-16 01:15:23 +02:00
function onCopyClicked() {
2022-04-22 23:31:40 +02:00
copy();
tooltipText.value = 'Copied !';
2022-04-16 01:15:23 +02:00
2022-04-22 23:31:40 +02:00
setTimeout(() => {
tooltipText.value = 'Copy to clipboard';
}, 2000);
2022-04-16 01:15:23 +02:00
}
</script>