|
1 | | -import type { ObjectTypeDefinition } from '../types/ObjectType'; |
2 | | -import { useT } from '../lib/useT'; |
3 | | -import { inputCls, labelCls } from '../components/Properties/styles'; |
4 | | -import { fieldPos, fdField } from './zplHelpers'; |
5 | | -import { commitHeightTransform } from './transformHelpers'; |
6 | | -import { filterContent, type ContentSpec } from './contentSpec'; |
7 | | -import { type ZplRotation } from './rotation'; |
8 | | -import { RotationSelect } from '../components/Properties/RotationSelect'; |
9 | | -import { NumberInput } from '../components/Properties/NumberInput'; |
| 1 | +import { createBarcode1D } from './barcode1d'; |
| 2 | +import type { ContentSpec } from './contentSpec'; |
| 3 | +export type { Barcode1DProps as Code39Props } from './barcode1d'; |
10 | 4 |
|
11 | 5 | const code39Spec: ContentSpec = { charset: '0-9A-Za-z\\-. $/+%' }; |
12 | 6 |
|
13 | | -export interface Code39Props { |
14 | | - content: string; |
15 | | - height: number; |
16 | | - moduleWidth: number; |
17 | | - printInterpretation: boolean; |
18 | | - checkDigit: boolean; |
19 | | - rotation: ZplRotation; |
20 | | -} |
21 | | - |
22 | | -export const code39: ObjectTypeDefinition<Code39Props> = { |
| 7 | +export const code39 = createBarcode1D({ |
23 | 8 | label: 'Code 39', |
24 | 9 | icon: '|·|', |
| 10 | + defaultContent: 'CODE39', |
| 11 | + hasCheckDigit: true, |
| 12 | + locale: (t) => t.registry.code39, |
25 | 13 | group: 'code-1d', |
26 | | - defaultProps: { |
27 | | - content: 'CODE39', |
28 | | - height: 100, |
29 | | - moduleWidth: 2, |
30 | | - printInterpretation: true, |
31 | | - checkDigit: false, |
32 | | - rotation: 'N', |
33 | | - }, |
34 | | - defaultSize: { width: 300, height: 120 }, |
35 | | - |
36 | | - commitTransform: commitHeightTransform, |
37 | | - |
38 | | - toZPL: (obj) => { |
39 | | - const p = obj.props; |
| 14 | + contentSpec: code39Spec, |
| 15 | + zplCommand: (p) => { |
40 | 16 | const interp = p.printInterpretation ? 'Y' : 'N'; |
41 | 17 | const check = p.checkDigit ? 'Y' : 'N'; |
42 | | - return [ |
43 | | - `^BY${p.moduleWidth}`, |
44 | | - fieldPos(obj), |
45 | | - `^B3${p.rotation},${check},${p.height},${interp},N`, |
46 | | - fdField(p.content), |
47 | | - ].filter(Boolean).join(''); |
48 | | - }, |
49 | | - |
50 | | - PropertiesPanel: ({ obj, onChange }) => { |
51 | | - const t = useT(); |
52 | | - const p = obj.props; |
53 | | - return ( |
54 | | - <div className="flex flex-col gap-3"> |
55 | | - <div className="flex flex-col gap-1"> |
56 | | - <label className={labelCls}>{t.registry.code39.content}</label> |
57 | | - <input |
58 | | - className={inputCls} |
59 | | - value={p.content} |
60 | | - onChange={(e) => onChange({ content: filterContent(e.target.value, code39Spec) })} |
61 | | - /> |
62 | | - </div> |
63 | | - |
64 | | - <NumberInput |
65 | | - label={t.registry.code39.height} |
66 | | - value={p.height} |
67 | | - min={1} |
68 | | - onChange={(height) => onChange({ height })} |
69 | | - /> |
70 | | - |
71 | | - <NumberInput |
72 | | - label={t.registry.code39.moduleWidth} |
73 | | - value={p.moduleWidth} |
74 | | - min={1} |
75 | | - max={10} |
76 | | - onChange={(moduleWidth) => onChange({ moduleWidth })} |
77 | | - /> |
78 | | - |
79 | | - <div className="flex flex-col gap-2"> |
80 | | - <label className="flex items-center gap-2 cursor-pointer"> |
81 | | - <input |
82 | | - type="checkbox" |
83 | | - className="accent-accent" |
84 | | - checked={p.printInterpretation} |
85 | | - onChange={(e) => onChange({ printInterpretation: e.target.checked })} |
86 | | - /> |
87 | | - <span className={labelCls}>{t.registry.code39.printInterpretation}</span> |
88 | | - </label> |
89 | | - <label className="flex items-center gap-2 cursor-pointer"> |
90 | | - <input |
91 | | - type="checkbox" |
92 | | - className="accent-accent" |
93 | | - checked={p.checkDigit} |
94 | | - onChange={(e) => onChange({ checkDigit: e.target.checked })} |
95 | | - /> |
96 | | - <span className={labelCls}>{t.registry.code39.checkDigit}</span> |
97 | | - </label> |
98 | | - </div> |
99 | | - |
100 | | - <RotationSelect value={p.rotation} onChange={(rotation) => onChange({ rotation })} /> |
101 | | - </div> |
102 | | - ); |
| 18 | + return `^B3${p.rotation},${check},${p.height},${interp},N`; |
103 | 19 | }, |
104 | | -}; |
| 20 | +}); |
0 commit comments