Barcode
A 1D or 2D barcode drawn as SVG in the browser: Code 128, EAN-13, EAN-8, UPC-A, Code 39 and Data Matrix.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | — | The text to encode. |
format | BarcodeFormat | code128 | code128, ean13, ean8, upca, code39 or datamatrix. |
hide-text | boolean | false | Leaves out the value printed under a 1D code. |
Events
| Name | Type | Description |
|---|---|---|
barcode-error | CustomEvent<BarcodeErrorEventDetail> | The value cannot be encoded in the format. detail has the error and the value. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
code | The box around the code, quiet zone included. |
bars | The SVG of the bars or the modules. |
text | The value printed under a 1D code. |
placeholder | The frame drawn when there is no code. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-barcode--height | pixel | 72px | The height of the bars of a 1D code. |
--c2-barcode--quiet-zone | number | 10 | The margin either side of a 1D code, in modules. It never goes under what the format requires: 10 for Code 128 and Code 39, 11 left and 7 right for EAN-13, 7 for EAN-8, 9 for UPC-A. |
--c2-barcode--padding-block | pixel | 8px | Space above the code and below the text. |
--c2-barcode--border-radius | border-radius | 4px | |
--c2-barcode__module--width | pixel | 2px | The width of one narrow bar of a 1D code. |
--c2-barcode__module--size | pixel | 4px | The size of one cell of a Data Matrix. |
--c2-barcode__matrix--quiet-zone | number | 2 | The margin around a Data Matrix, in cells. |
--c2-barcode__bar--color | color | #18181b | |
--c2-barcode__background--color | color | #ffffff | |
--c2-barcode__text--color | color | #18181b | |
--c2-barcode__text--font-family | font-family | ui-monospace, SFMono-Regular, Menlo, Consolas, monospace | |
--c2-barcode__text--font-size | font-size | 13px | |
--c2-barcode__placeholder--width | pixel | 220px | |
--c2-barcode__placeholder--border | border | 1px dashed #bcbcc6 | |
--c2-barcode__placeholder--color | color | #71717a | |
--c2-barcode__placeholder--font-size | font-size | 12px | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under barcode, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Barcode, {0}: {1} | {0} format {1} value |
barcode | Barcode | — |
empty | No value | — |
unencodable | Can't encode this value | — |