Files
nocodb/packages/nc-gui/components/virtual-cell/barcode/JsBarcodeWrapper.vue
Ramesh Mane 99ecc40f9a Nc Refactor: Gallery view (#8674)
* fix(nc-gui): introduce header icon in gallery view card and update style

* fix(nc-gui): field modal width issue if it is rich text

* fix(nc-gui): hide longtext expanded icon on gallery & kanban view card hove

* fix(nc-gui): date field alignment issue

* fix(nc-gui): udpate kanban view card

* fix(nc-gui): udpate gallery & kanban view card display value style

* fix(nocodb): hide cover image in new gallery, kanban view if it is not pv column

* feat(nc-gui): change cover image object fit property change support

* fix(nc-gui): virtual cell card value alignment issue

* fix(nc-gui): gallery view card image navigation issue

* fix(nc-gui): gallerym, kanban card cover image dots navigation overflow issue

* fix(nocodb): use optional chaining to access nested variable

* chore(nc-gui): lint

* fix(nc-gui): long text max line shuld be 4 in card

* test: update open expanded form in gallery test

* fix(nc-gui): add empty card in gallery view if cards length is less than 4

* fix(nc-gui): update gallery view card min width

* fix(nocodb): small changes

* fix(nc-gui): review changes

* fix(nc-gui): add input shadow effect

* fix(nc-gui): update card image navigation buttons icon

* fix(nc-gui): udpate gallery view bg color

* fix(nc-gui): update email, url, phone cell height from card

* fix(nc-gui): update isEmptyRow function logic

* fix(nc-gui): some review changes

* fix(nc-gui): card display value color

* fix(nc-gui): udpate gallery view card min width

* fix(nc-gui): update card shadow & border on hover

* fix(nc-gui): update gallery loader card width

* fix(nc-gui): add min height for card image

* chore(nc-gui): lint

* fix(nc-gui): card rich text height

* fix(nc-gui): align record count in right side in gallery view

* fix(nc-gui): review changes

* fix(nc-gui): shared view show & hide field issue

* chore(nc-gui): lint

* fix(nc-gui): link record test fail issue
2024-06-10 16:38:56 +05:30

76 lines
2.0 KiB
Vue

<script lang="ts" setup>
import JsBarcode from 'jsbarcode'
import { downloadSvg as _downloadSvg } from '~/utils/svgToPng'
const props = defineProps({
barcodeValue: { type: String, required: true },
barcodeFormat: { type: String, required: true },
customStyle: { type: Object, required: false },
showDownload: { type: Boolean, required: false, default: false },
})
const emit = defineEmits(['onClickBarcode'])
const isGallery = inject(IsGalleryInj, ref(false))
const barcodeSvgRef = ref<SVGGraphicsElement>()
const errorForCurrentInput = ref(false)
const generate = () => {
try {
JsBarcode(barcodeSvgRef.value, String(props.barcodeValue), {
format: props.barcodeFormat,
})
if (props.customStyle) {
if (barcodeSvgRef.value) {
for (const key in props.customStyle) {
barcodeSvgRef.value.style.setProperty(key, props.customStyle[key])
}
}
}
errorForCurrentInput.value = false
} catch (e) {
console.log('e', e)
errorForCurrentInput.value = true
}
}
const downloadSvg = () => {
if (!barcodeSvgRef.value) return
_downloadSvg(barcodeSvgRef.value, `${props.barcodeValue}.png`)
}
const onBarcodeClick = (ev: MouseEvent) => {
ev.stopPropagation()
emit('onClickBarcode')
}
watch([() => props.barcodeValue, () => props.barcodeFormat, () => props.customStyle], generate)
onMounted(generate)
</script>
<template>
<div class="relative">
<svg
v-show="!errorForCurrentInput"
ref="barcodeSvgRef"
:class="{
'w-full': !isGallery,
'w-auto': isGallery,
}"
data-testid="barcode"
@click="onBarcodeClick"
></svg>
<slot v-if="errorForCurrentInput" name="barcodeRenderError" />
<NcTooltip class="!absolute bottom-0 right-0">
<template #title>
{{ $t('labels.clickToDownload') }}
</template>
<NcButton v-if="props.showDownload" size="small" type="secondary" @click="downloadSvg">
<GeneralIcon icon="download" class="w-4 h-4" />
</NcButton>
</NcTooltip>
</div>
</template>