it-tools/src/components/InputCopyable.vue

44 lines
1,020 B
Vue
Raw Normal View History

2022-04-16 01:15:23 +02:00
<template>
<n-input v-model:value="value">
<template #suffix>
<n-tooltip trigger="hover">
<template #trigger>
<c-button circle variant="text" @click="onCopyClicked">
2022-04-16 01:15:23 +02:00
<n-icon :component="ContentCopyFilled" />
</c-button>
2022-04-16 01:15:23 +02:00
</template>
{{ tooltipText }}
</n-tooltip>
2022-04-22 23:31:40 +02:00
</template>
2022-04-16 01:15:23 +02:00
</n-input>
</template>
<script setup lang="ts">
2022-04-22 23:31:40 +02:00
import { useVModel, useClipboard } from '@vueuse/core';
import { ContentCopyFilled } from '@vicons/material';
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>
<style scoped>
::v-deep(.n-input-wrapper) {
2022-04-22 23:31:40 +02:00
padding-right: 5px;
2022-04-16 01:15:23 +02:00
}
2022-04-22 23:31:40 +02:00
</style>