mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
feat(shared,crm): add Code 128 barcode generation library Implements new @isa/shared/barcode library with directive and component for generating Code 128 barcodes using JsBarcode. Features: - Standalone Angular directive (svg[sharedBarcode]) - Standalone Angular component (<shared-barcode>) - Signal-based reactive inputs - SVG-based vector rendering - Customizable colors, size, margins, fonts - Comprehensive Vitest test coverage (39 tests) - Storybook stories for both directive and component - Integrated into customer loyalty card component Changes: - Created @isa/shared/barcode library with directive and component - Added JsBarcode dependency (v3.12.1) - Integrated barcode into customer loyalty card display - Added Storybook stories for interactive documentation - Fixed ui-switch story component reference - Updated library reference documentation Refs #5496 Related work items: #5496
215 lines
3.9 KiB
TypeScript
215 lines
3.9 KiB
TypeScript
import {
|
|
argsToTemplate,
|
|
type Meta,
|
|
type StoryObj,
|
|
moduleMetadata,
|
|
} from '@storybook/angular';
|
|
import { BarcodeDirective } from '@isa/shared/barcode';
|
|
|
|
type BarcodeInputs = {
|
|
value: string;
|
|
format: string;
|
|
width: number;
|
|
height: number;
|
|
displayValue: boolean;
|
|
lineColor: string;
|
|
background: string;
|
|
fontSize: number;
|
|
margin: number;
|
|
};
|
|
|
|
const meta: Meta<BarcodeInputs> = {
|
|
title: 'shared/barcode/Barcode',
|
|
|
|
decorators: [
|
|
moduleMetadata({
|
|
imports: [BarcodeDirective],
|
|
}),
|
|
],
|
|
argTypes: {
|
|
value: {
|
|
control: {
|
|
type: 'text',
|
|
},
|
|
description: 'The barcode value to encode',
|
|
},
|
|
format: {
|
|
control: {
|
|
type: 'select',
|
|
},
|
|
options: ['CODE128', 'CODE39', 'EAN13', 'EAN8', 'UPC'],
|
|
description: 'Barcode format',
|
|
},
|
|
width: {
|
|
control: {
|
|
type: 'number',
|
|
min: 1,
|
|
max: 10,
|
|
},
|
|
description: 'Width of a single bar in pixels',
|
|
},
|
|
height: {
|
|
control: {
|
|
type: 'number',
|
|
min: 20,
|
|
max: 300,
|
|
},
|
|
description: 'Height of the barcode in pixels',
|
|
},
|
|
displayValue: {
|
|
control: {
|
|
type: 'boolean',
|
|
},
|
|
description: 'Whether to display the human-readable text',
|
|
},
|
|
lineColor: {
|
|
control: {
|
|
type: 'color',
|
|
},
|
|
description: 'Color of the barcode bars and text',
|
|
},
|
|
background: {
|
|
control: {
|
|
type: 'color',
|
|
},
|
|
description: 'Background color',
|
|
},
|
|
fontSize: {
|
|
control: {
|
|
type: 'number',
|
|
min: 10,
|
|
max: 40,
|
|
},
|
|
description: 'Font size for the human-readable text',
|
|
},
|
|
margin: {
|
|
control: {
|
|
type: 'number',
|
|
min: 0,
|
|
max: 50,
|
|
},
|
|
description: 'Margin around the barcode in pixels',
|
|
},
|
|
},
|
|
render: (args) => ({
|
|
props: args,
|
|
template: `<svg sharedBarcode ${argsToTemplate(args)}></svg>`,
|
|
}),
|
|
};
|
|
|
|
export default meta;
|
|
|
|
type Story = StoryObj<BarcodeDirective>;
|
|
|
|
export const Default: Story = {
|
|
args: {
|
|
value: '123456789012',
|
|
format: 'CODE128',
|
|
width: 2,
|
|
height: 100,
|
|
displayValue: true,
|
|
lineColor: '#000000',
|
|
background: '#ffffff',
|
|
fontSize: 20,
|
|
margin: 10,
|
|
},
|
|
};
|
|
|
|
export const ProductEAN: Story = {
|
|
args: {
|
|
value: '9783161484100',
|
|
format: 'CODE128',
|
|
width: 2,
|
|
height: 100,
|
|
displayValue: true,
|
|
lineColor: '#000000',
|
|
background: '#ffffff',
|
|
fontSize: 20,
|
|
margin: 10,
|
|
},
|
|
};
|
|
|
|
export const CompactNoText: Story = {
|
|
args: {
|
|
value: '987654321',
|
|
format: 'CODE128',
|
|
width: 1,
|
|
height: 60,
|
|
displayValue: false,
|
|
lineColor: '#000000',
|
|
background: '#ffffff',
|
|
fontSize: 20,
|
|
margin: 5,
|
|
},
|
|
};
|
|
|
|
export const LargeBarcode: Story = {
|
|
args: {
|
|
value: 'WAREHOUSE2024',
|
|
format: 'CODE128',
|
|
width: 4,
|
|
height: 200,
|
|
displayValue: true,
|
|
lineColor: '#000000',
|
|
background: '#ffffff',
|
|
fontSize: 28,
|
|
margin: 20,
|
|
},
|
|
};
|
|
|
|
export const ColoredBarcode: Story = {
|
|
args: {
|
|
value: 'PRODUCT001',
|
|
format: 'CODE128',
|
|
width: 2,
|
|
height: 100,
|
|
displayValue: true,
|
|
lineColor: '#0066CC',
|
|
background: '#F0F8FF',
|
|
fontSize: 20,
|
|
margin: 10,
|
|
},
|
|
};
|
|
|
|
export const RedBarcode: Story = {
|
|
args: {
|
|
value: 'URGENT2024',
|
|
format: 'CODE128',
|
|
width: 3,
|
|
height: 120,
|
|
displayValue: true,
|
|
lineColor: '#CC0000',
|
|
background: '#FFEEEE',
|
|
fontSize: 22,
|
|
margin: 15,
|
|
},
|
|
};
|
|
|
|
export const MinimalMargin: Story = {
|
|
args: {
|
|
value: '1234567890',
|
|
format: 'CODE128',
|
|
width: 2,
|
|
height: 80,
|
|
displayValue: true,
|
|
lineColor: '#000000',
|
|
background: '#ffffff',
|
|
fontSize: 16,
|
|
margin: 0,
|
|
},
|
|
};
|
|
|
|
export const SmallFont: Story = {
|
|
args: {
|
|
value: '555123456789',
|
|
format: 'CODE128',
|
|
width: 2,
|
|
height: 100,
|
|
displayValue: true,
|
|
lineColor: '#000000',
|
|
background: '#ffffff',
|
|
fontSize: 12,
|
|
margin: 10,
|
|
},
|
|
};
|