aboutsummaryrefslogtreecommitdiff
path: root/src/components/InputCopyable.vue
blob: 3e4aa9461a7eba8e66a18973916670c30be3be92 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<template>
  <n-input v-model:value="value">
    <template #suffix>
      <n-tooltip trigger="hover">
        <template #trigger>
          <n-button
            quaternary
            circle
            @click="onCopyClicked"
          >
            <n-icon :component="ContentCopyFilled" />
          </n-button>
        </template>
        {{ tooltipText }}
      </n-tooltip>
    </template> 
  </n-input>
</template>

<script setup lang="ts">
import { useVModel } from '@vueuse/core'
import { ContentCopyFilled } from '@vicons/material'

import { useClipboard } from '@vueuse/core';
import { ref } from 'vue';

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>

<style scoped>
::v-deep(.n-input-wrapper) {
    padding-right: 5px;
}
</style>