Barcode
Barcode component (web SVG form): the text is encoded into a module bit array by the self-contained pure-JS encoder in @lh-ui/share/core/barcode (encodeBarcode), and barcodeToSvgPath turns it into a bar-module path rendered inside an <svg> (same shape as the Qrcode component). The encoder is self-contained pure JS with zero third-party dependencies: CODE128 (automatic A/B/C subset selection plus a mod 103 check digit) and EAN-13 (12-digit input gets its check digit computed; 13-digit input is validated).
Bar height, quiet zone, foreground / background colors and the human-readable number are all supported. An empty value or an un-encodable input (non-ASCII for CODE128, a mismatched EAN-13 check digit) degrades to an empty state (no svg rendered, console.warn logged) so encoding errors never bubble up to the rendering layer.
Basic Usage
value is the content to encode; type selects the symbology (default CODE128):
<script setup lang="ts">
import { LhBarcode } from '@lh-ui/vue3'
</script>
<template>
<!-- Basic usage -->
<LhBarcode value="LH-UI-2026" show-text />
<LhBarcode value="690123456789" type="EAN13" show-text />
</template><script>
import { LhBarcode } from '@lh-ui/vue3'
export default {
components: { LhBarcode },
}
</script>
<template>
<!-- Basic usage -->
<LhBarcode value="LH-UI-2026" show-text />
<LhBarcode value="690123456789" type="EAN13" show-text />
</template>EAN-13: a 12-digit input gets its check digit appended (e.g. 690123456789 becomes 6901234567892); a 13-digit input whose check digit does not match throws and degrades to the empty state.
Height and Quiet Zone
height is the bar height in px (default 64); margin is the left/right quiet zone in modules (default 10, the floor for reliable scanning); showText renders the human-readable digits in a monospace face below the bars:
<script setup lang="ts">
import { LhBarcode } from '@lh-ui/vue3'
</script>
<template>
<!-- Height and quiet zone -->
<LhBarcode value="ABC-12345" :height="48" :margin="4" show-text />
<LhBarcode value="ABC-12345" :height="80" :margin="16" show-text />
</template><script>
import { LhBarcode } from '@lh-ui/vue3'
export default {
components: { LhBarcode },
}
</script>
<template>
<!-- Height and quiet zone -->
<LhBarcode value="ABC-12345" :height="48" :margin="4" show-text />
<LhBarcode value="ABC-12345" :height="80" :margin="16" show-text />
</template>Custom Colors
color overrides the bar foreground (falls back to the --lh-text-primary token); bgColor draws a background rect (transparent when omitted, using the stylesheet token):
<script setup lang="ts">
import { LhBarcode } from '@lh-ui/vue3'
</script>
<template>
<!-- Colors -->
<LhBarcode value="8866-2026" color="#2B4C7C" show-text />
<LhBarcode value="8866-2026" color="#D9393B" bg-color="#FFF7E8" show-text />
</template><script>
import { LhBarcode } from '@lh-ui/vue3'
export default {
components: { LhBarcode },
}
</script>
<template>
<!-- Colors -->
<LhBarcode value="8866-2026" color="#2B4C7C" show-text />
<LhBarcode value="8866-2026" color="#D9393B" bg-color="#FFF7E8" show-text />
</template>API
Barcode Props
| Prop | Description | Type | Default |
|---|---|---|---|
| value | Content to encode (EAN13 takes 12 or 13 digits) | string | '' |
| type | Symbology | 'CODE128' | 'EAN13' | 'CODE128' |
| height | Bar height (px) | number | 64 |
| margin | Left/right quiet zone (modules) | number | 10 |
| color | Foreground color (bars) | string | — |
| bgColor | Background color (spaces) | string | — |
| showText | Human-readable digits under the bars | boolean | false |
| label | Accessible name (defaults to "barcode") | string | — |
| sx | sx quick-layout props | LhSxProps | — |
Accessibility
- The root carries
role="img"with an accessible name defaulting to "barcode", overridable vialabel - The empty state (empty
valueor encoding failure) renders no svg and leaves no residual nodes in the DOM - Encoding failures are logged via
console.warnand degrade to the empty state instead of throwing
The encoder is self-contained pure JS (CODE128 / EAN-13 standard data), zero third-party dependencies.

