aboutsummaryrefslogtreecommitdiff
path: root/src/components/InputCopyable.vue
blob: ed678954be108c09806fa1e3d66b2a9adbefd2f3 (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
<script setup lang="ts">
import { useVModel } from '@vueuse/core';
import { useCopy } from '@/composable/copy';

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

const value = useVModel(props, 'value', emit);
const { copy, isJustCopied } = useCopy({ source: value, createToast: false });
const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : 'Copy to clipboard');
</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="copy()">
            <icon-mdi-content-copy />
          </c-button>
        </template>
        {{ tooltipText }}
      </n-tooltip>
    </template>
  </c-input-text>
</template>