# @isa/shared/barcode
Angular library for generating Code 128 barcodes using [JsBarcode](https://github.com/lindell/JsBarcode).
Provides both a **component** (easier to use) and a **directive** (more flexible) for rendering barcodes.
## Features
- ✅ Standalone Angular component & directive
- ✅ Code 128 barcode format support
- ✅ Signal-based reactive inputs
- ✅ SVG-based rendering (vector graphics)
- ✅ Highly customizable (colors, size, margins, fonts)
- ✅ Automatic re-rendering on input changes
- ✅ Built-in logging with `@isa/core/logging`
- ✅ Comprehensive Vitest test coverage
## Installation
### Component (Recommended)
The component provides the easiest way to add barcodes:
```typescript
import { BarcodeComponent } from '@isa/shared/barcode';
@Component({
selector: 'app-my-component',
standalone: true,
imports: [BarcodeComponent],
template: `
`,
})
export class MyComponent {
productEan = '9783161484100';
}
```
### Directive (Advanced)
Use the directive when you need to apply the barcode to an existing SVG element:
```typescript
import { BarcodeDirective } from '@isa/shared/barcode';
@Component({
selector: 'app-my-component',
standalone: true,
imports: [BarcodeDirective],
template: `
`,
})
export class MyComponent {
productEan = '9783161484100';
}
```
## Basic Usage
### Component - Minimal Example
```html
```
### Directive - Minimal Example
```html
```
### Component - With Custom Options
```html
```
### Directive - With Custom Options
```html
```
### TypeScript Example
```typescript
import { Component, signal } from '@angular/core';
import { BarcodeComponent } from '@isa/shared/barcode';
@Component({
selector: 'app-product-label',
standalone: true,
imports: [BarcodeComponent],
template: `
Product Label
`,
})
export class ProductLabelComponent {
ean = signal('4006381333634');
}
```
## API Reference
### Inputs
| Input | Type | Default | Description |
|-------|------|---------|-------------|
| `value` | `string` | *(required)* | The barcode value to encode |
| `format` | `string` | `'CODE128'` | Barcode format (supports CODE128, CODE39, EAN13, etc.) |
| `width` | `number` | `2` | Width of a single bar in pixels |
| `height` | `number` | `100` | Height of the barcode in pixels |
| `displayValue` | `boolean` | `true` | Whether to display the human-readable text below the barcode |
| `lineColor` | `string` | `'#000000'` | Color of the barcode bars and text |
| `background` | `string` | `'#ffffff'` | Background color |
| `fontSize` | `number` | `20` | Font size for the human-readable text |
| `margin` | `number` | `10` | Margin around the barcode in pixels |
### Selector
```typescript
selector: 'svg[sharedBarcode]'
```
The directive must be applied to an `