feat(ux): copyable input

This commit is contained in:
Corentin Thomasset 2022-04-16 01:15:23 +02:00
parent 7a7372df19
commit 1859a9a174
No known key found for this signature in database
GPG key ID: DBD997E935996158
5 changed files with 79 additions and 26 deletions

View file

@ -0,0 +1,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>