refactor: use inline copy interaction via reusable composable

This commit is contained in:
Amit Joki
2025-01-11 23:39:49 +05:30
parent 691909ce3d
commit f6e7785cd5
3 changed files with 31 additions and 16 deletions

View File

@@ -44,15 +44,12 @@ const downloadSvg = () => {
_downloadSvg(barcodeSvgRef.value, `${props.barcodeValue}.png`)
}
const { isCopied, performCopy } = useIsCopied()
const copyAsPng = async () => {
if (!barcodeSvgRef.value) return
const success = await copySVGToClipboard(barcodeSvgRef.value)
if (success) {
message.success(t('msg.info.copiedToClipboard'))
} else {
message.error(t('msg.error.notSupported'))
}
if (!success) message.error(t('msg.error.notSupported'))
}
const onBarcodeClick = (ev: MouseEvent) => {
@@ -83,11 +80,12 @@ onMounted(generate)
<template #title>
{{ $t('labels.clickToCopy') }}
</template>
<NcButton size="small" type="secondary" @click="copyAsPng">
<NcButton size="small" type="secondary" @click="performCopy(copyAsPng)">
<template #icon>
<GeneralIcon icon="copy" class="w-4 h-4" />
<GeneralIcon v-if="isCopied" icon="check" class="h-4 w-4" />
<GeneralIcon v-else icon="copy" class="h-4 w-4" />
</template>
{{ $t('general.copy') }}
{{ isCopied ? $t('general.copied') : $t('general.copy') }}
</NcButton>
</NcTooltip>
<NcTooltip>