# @salmonui/charts/barcode API reference

> 20 exported symbols of @salmonui/charts/barcode: 2 components, 1 function, 6 interfaces, 10 types and 1 constant.

Canonical: https://salmonui.dev/docs/reference/charts/barcode

```ts
import { … } from '@salmonui/charts/barcode';
```

## Components

### Barcode

Kind: component

Page: https://salmonui.dev/docs/reference/charts/barcode/Barcode

```ts
function Barcode(props: BarcodeProps): ReactNode;
```

Props: [`BarcodeProps`](https://salmonui.dev/docs/reference/charts/barcode/BarcodeProps) (its members are the props)

### QRCode

Kind: component

Page: https://salmonui.dev/docs/reference/charts/barcode/QRCode

```ts
function QRCode(props: QRCodeProps): ReactNode;
```

Props: [`QRCodeProps`](https://salmonui.dev/docs/reference/charts/barcode/QRCodeProps) (its members are the props)

## Interfaces

### BarcodeApi

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeApi

```ts
interface BarcodeApi {
    readonly element: SVGSVGElement | null;
    toSVGString(): string;
    toBlob(format?: BarcodeImageFormat, options?: Omit<BarcodeExportOptions, 'format' | 'fileName'>): Promise<Blob>;
    toDataURL(format?: BarcodeImageFormat, options?: Omit<BarcodeExportOptions, 'format' | 'fileName'>): Promise<string>;
    export(options?: BarcodeExportOptions): Promise<void>;
}
```

Instance reached through `ref` on `Barcode` and `QRCode`.

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `element` | `readonly element: SVGSVGElement \| null;` |  | The root `<svg>` (null before mount). |
| `toSVGString` | `toSVGString(): string;` |  | Standalone SVG markup; works without a DOM (server, tests). |
| `toBlob` | `toBlob(format?: BarcodeImageFormat, options?: Omit<BarcodeExportOptions, 'format' \| 'fileName'>): Promise<Blob>;` |  |  |
| `toDataURL` | `toDataURL(format?: BarcodeImageFormat, options?: Omit<BarcodeExportOptions, 'format' \| 'fileName'>): Promise<string>;` |  |  |
| `export` | `export(options?: BarcodeExportOptions): Promise<void>;` |  | Downloads the symbol; settles after the download started. |

### BarcodeExportOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeExportOptions

```ts
interface BarcodeExportOptions {
    readonly format?: BarcodeImageFormat | undefined;
    readonly fileName?: string | undefined;
    readonly scale?: number | undefined;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `format` | `readonly format?: BarcodeImageFormat \| undefined;` | optional |  |
| `fileName` | `readonly fileName?: string \| undefined;` | optional | Default `barcode.<format>`. |
| `scale` | `readonly scale?: number \| undefined;` | optional | Raster scale on top of the device pixel ratio. Default 1. |

### BarcodeInvalidEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeInvalidEvent

```ts
interface BarcodeInvalidEvent {
    readonly reason: string;
}
```

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `reason` | `readonly reason: string;` |  |  |

### BarcodeProps

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeProps

```ts
interface BarcodeProps extends SvgPassthrough {
    readonly type: BarcodeType;
    readonly value: string;
    readonly checksum?: boolean | undefined;
    readonly codeSet?: 'a' | 'b' | 'c' | undefined;
    readonly encoding?: BarcodeDataMatrixEncoding | undefined;
    readonly size?: string | undefined;
    readonly gs1?: boolean | undefined;
    readonly text?: boolean | string | undefined;
    readonly textPosition?: TextPosition | undefined;
    readonly textAlign?: TextAlign | undefined;
    readonly moduleSize?: number | undefined;
    readonly width?: number | undefined;
    readonly height?: number | undefined;
    readonly quietZone?: boolean | undefined;
    readonly color?: string | undefined;
    readonly background?: string | undefined;
    readonly bearerBar?: BearerBar | undefined;
    readonly label?: string | undefined;
    readonly invalidLabel?: string | undefined;
    readonly onInvalid?: ((event: BarcodeInvalidEvent) => void) | undefined;
    readonly ref?: Ref<BarcodeApi> | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
}
```

Members (23):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `type` | `readonly type: BarcodeType;` |  |  |
| `value` | `readonly value: string;` |  | The data to encode. GS1 types take element strings: `(01)09501101530003(10)ABC`. |
| `checksum` | `readonly checksum?: boolean \| undefined;` | optional | Code 39 mod-43 check character (default off); Code 11 C / K check digits (default on). |
| `codeSet` | `readonly codeSet?: 'a' \| 'b' \| 'c' \| undefined;` | optional | Code 128: force one code set instead of automatic switching. |
| `encoding` | `readonly encoding?: BarcodeDataMatrixEncoding \| undefined;` | optional | Data Matrix encodation (default `'auto'`). |
| `size` | `readonly size?: string \| undefined;` | optional | Data Matrix symbol size: `'auto'` (smallest square), `'auto-rectangular'`, or `'<rows>x<cols>'`. |
| `gs1` | `readonly gs1?: boolean \| undefined;` | optional | Data Matrix: GS1 element string with FNC1. |
| `text` | `readonly text?: boolean \| string \| undefined;` | optional | Human-readable text: `true` (default for 1D) shows the encoded value, a string replaces it, `false` hides it. |
| `textPosition` | `readonly textPosition?: TextPosition \| undefined;` | optional |  |
| `textAlign` | `readonly textAlign?: TextAlign \| undefined;` | optional |  |
| `moduleSize` | `readonly moduleSize?: number \| undefined;` | optional | Module (narrow bar) width in px. Default 2 (1D), 4 (Data Matrix). |
| `width` | `readonly width?: number \| undefined;` | optional | Total width in px (overrides `moduleSize`). |
| `height` | `readonly height?: number \| undefined;` | optional | Total height in px (1D). |
| `quietZone` | `readonly quietZone?: boolean \| undefined;` | optional | Keep the quiet zone (default true). |
| `color` | `readonly color?: string \| undefined;` | optional | Bar color: a data color, default `#000000` (scanners need dark on light in every color scheme). |
| `background` | `readonly background?: string \| undefined;` | optional | Background color: a data color, default `#ffffff`. |
| `bearerBar` | `readonly bearerBar?: BearerBar \| undefined;` | optional | ITF-14 bearer bars (default `'frame'` for `itf14`, `'none'` otherwise). |
| `label` | `readonly label?: string \| undefined;` | optional | Accessible name; default the encoded value. |
| `invalidLabel` | `readonly invalidLabel?: string \| undefined;` | optional | Accessible name when the value cannot be encoded (`{reason}` is replaced). Default `Invalid barcode: {reason}`. |
| `onInvalid` | `readonly onInvalid?: ((event: BarcodeInvalidEvent) => void) \| undefined;` | optional |  |
| `ref` | `readonly ref?: Ref<BarcodeApi> \| undefined;` | optional |  |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |

### QRCodeProps

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/barcode/QRCodeProps

```ts
interface QRCodeProps extends SvgPassthrough {
    readonly value: string;
    readonly errorCorrection?: QRErrorCorrection | undefined;
    readonly version?: 'auto' | number | undefined;
    readonly mode?: QRMode | undefined;
    readonly gs1?: boolean | undefined;
    readonly mask?: number | undefined;
    readonly logo?: ReactNode;
    readonly moduleSize?: number | undefined;
    readonly width?: number | undefined;
    readonly quietZone?: boolean | undefined;
    readonly text?: boolean | string | undefined;
    readonly color?: string | undefined;
    readonly background?: string | undefined;
    readonly label?: string | undefined;
    readonly invalidLabel?: string | undefined;
    readonly onInvalid?: ((event: BarcodeInvalidEvent) => void) | undefined;
    readonly ref?: Ref<QRCodeApi> | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
}
```

Members (19):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value: string;` |  |  |
| `errorCorrection` | `readonly errorCorrection?: QRErrorCorrection \| undefined;` | optional | Default `'m'`, or `'h'` with a `logo`. |
| `version` | `readonly version?: 'auto' \| number \| undefined;` | optional | `'auto'` (default): the smallest version 1..40 that fits. |
| `mode` | `readonly mode?: QRMode \| undefined;` | optional | Default `'auto'`: numeric, alphanumeric or byte (UTF-8), whichever encodes the whole value. |
| `gs1` | `readonly gs1?: boolean \| undefined;` | optional | GS1 QR Code: `value` is an element string `(01)…(10)…`. |
| `mask` | `readonly mask?: number \| undefined;` | optional | Mask 0..7 (default: the lowest ISO penalty). |
| `logo` | `readonly logo?: ReactNode;` | optional | Centered over a cleared area (about 22 % of the symbol width); raises the default error correction to `'h'`. |
| `moduleSize` | `readonly moduleSize?: number \| undefined;` | optional | Module size in px (default 4). |
| `width` | `readonly width?: number \| undefined;` | optional | Total width (and height) in px; overrides `moduleSize`. |
| `quietZone` | `readonly quietZone?: boolean \| undefined;` | optional |  |
| `text` | `readonly text?: boolean \| string \| undefined;` | optional | Optional caption under the symbol: `true` shows the value. |
| `color` | `readonly color?: string \| undefined;` | optional | Module color: a data color, default `#000000`. |
| `background` | `readonly background?: string \| undefined;` | optional |  |
| `label` | `readonly label?: string \| undefined;` | optional | Accessible name; default the encoded value. |
| `invalidLabel` | `readonly invalidLabel?: string \| undefined;` | optional |  |
| `onInvalid` | `readonly onInvalid?: ((event: BarcodeInvalidEvent) => void) \| undefined;` | optional |  |
| `ref` | `readonly ref?: Ref<QRCodeApi> \| undefined;` | optional |  |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |

## Types

### BarcodeBearerBar

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeBearerBar

```ts
type BearerBar = 'frame' | 'horizontal' | 'none';
```

### BarcodeDataMatrixEncoding

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeDataMatrixEncoding

```ts
type BarcodeDataMatrixEncoding = DataMatrixEncoding;
```

### BarcodeImageFormat

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeImageFormat

```ts
type BarcodeImageFormat = 'png' | 'jpeg' | 'svg';
```

### BarcodeTextAlign

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeTextAlign

```ts
type TextAlign = 'start' | 'center' | 'end';
```

### BarcodeTextPosition

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeTextPosition

```ts
type TextPosition = 'top' | 'bottom';
```

### BarcodeType

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/BarcodeType

```ts
type BarcodeType = 'code39' | 'code39Extended' | 'code11' | 'codabar' | 'code32' | 'code93' | 'code93Extended' | 'code128' | 'gs1Code128' | 'ean8' | 'ean13' | 'upcA' | 'upcE' | 'itf14' | 'dataMatrix';
```

### QRCodeApi

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/QRCodeApi

```ts
type QRCodeApi = BarcodeApi;
```

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `element` | `element: SVGSVGElement \| null;` | inherited | The root `<svg>` (null before mount). |
| `toSVGString` | `toSVGString: () => string;` | inherited | Standalone SVG markup; works without a DOM (server, tests). |
| `toBlob` | `toBlob: (format?: BarcodeImageFormat \| undefined, options?: Omit<BarcodeExportOptions, "fileName" \| "format"> \| undefined) => Promise<...>;` | inherited |  |
| `toDataURL` | `toDataURL: (format?: BarcodeImageFormat \| undefined, options?: Omit<BarcodeExportOptions, "fileName" \| "format"> \| undefined) => Promise<...>;` | inherited |  |
| `export` | `export: (options?: BarcodeExportOptions \| undefined) => Promise<void>;` | inherited | Downloads the symbol; settles after the download started. |

### QRErrorCorrection

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/QRErrorCorrection

```ts
type QRErrorCorrection = 'l' | 'm' | 'q' | 'h';
```

### QRMode

Kind: type

Page: https://salmonui.dev/docs/reference/charts/barcode/QRMode

```ts
type QRMode = 'auto' | 'numeric' | 'alphanumeric' | 'byte';
```

## Constants

### QR_LOGO_FRACTION

Kind: const

Page: https://salmonui.dev/docs/reference/charts/barcode/QR_LOGO_FRACTION

```ts
const QR_LOGO_FRACTION = 0.22;
```

Fraction of the symbol width cleared for a logo (well inside level H's 30 % recovery).

## Re-exported entry points

- [@salmonui/charts/chart/export](https://salmonui.dev/docs/reference/charts/chart-export.md): 3 symbols: 1 function, 1 interface and 1 type
  `ExportVisualizationsOptions`, `ExportableVisualization`, `exportVisualizations`
