aboutsummaryrefslogtreecommitdiff
path: root/src/components/InputCopyable.vue
blob: 0c6890978df231066393a041ede4de6e9b88ecb2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<script setup lang="ts">
import { useClipboard, useVModel } from '@vueuse/core';

const props = defineProps<{ value: string }>();
const emit = defineEmits(['update:value']);

const value = useVModel(props, 'value', emit);
const tooltipText = ref('Copy to clipboard');

const { copy } = useClipboard({ source: value });

function onCopyClicked() {
  copy();
  tooltipText.value = 'Copied !';

  setTimeout(() => {
    tooltipText.value = 'Copy to clipboard';
  }, 2000);
}
</script>

<template>
  <c-input-text v-model:value="value">
    <template #suffix>
      <n-tooltip trigger="hover">
        <template #trigger>
          <c-button circle variant="text" size="small" @click="onCopyClicked">
            <icon-mdi-content-copy />
          </c-button>
        </template>
        {{ tooltipText }}
      </n-tooltip>
    </template>
  </c-input-text>
</template>