mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-23 00:06:15 -04:00
feat(ux): copyable input
This commit is contained in:
parent
7a7372df19
commit
1859a9a174
5 changed files with 79 additions and 26 deletions
49
src/components/InputCopyable.vue
Normal file
49
src/components/InputCopyable.vue
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue