esvn-react-barcode-print 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # @becoxy/react-barcode-print
2
+
3
+ Thư viện React Modal in mã vạch (Barcode CODE128) và mã QR đa khổ giấy (2 tem, 3 tem, A4 65 tem, A5 40 tem, Tùy chọn) với giao diện xem trước trực quan (Print Preview Modal).
4
+
5
+ ## 1. Cài đặt
6
+
7
+ ```bash
8
+ yarn add @becoxy/react-barcode-print
9
+ # hoặc
10
+ npm install @becoxy/react-barcode-print
11
+ ```
12
+
13
+ ### Peer Dependencies
14
+ Đảm bảo dự án của bạn đã cài các thư viện sau:
15
+ ```bash
16
+ yarn add react react-dom reactstrap react-hook-form becoxy-icons sweetalert2 sweetalert2-react-content
17
+ ```
18
+
19
+ ## 2. Cách sử dụng
20
+
21
+ ```tsx
22
+ import React, { useState } from 'react'
23
+ import { ModalBarcodePrint, IBarcodePrintItem } from '@becoxy/react-barcode-print'
24
+ import TableEdit from 'react-table-edit'
25
+
26
+ const MyProductPage = () => {
27
+ const [isOpenPrint, setIsOpenPrint] = useState(false)
28
+ const [dataSelected, setDataSelected] = useState<IBarcodePrintItem[]>([])
29
+ const [dataList, setDataList] = useState<any[]>([])
30
+
31
+ return (
32
+ <div>
33
+ <button onClick={() => setIsOpenPrint(true)}>In mã vạch</button>
34
+
35
+ <ModalBarcodePrint
36
+ isOpen={isOpenPrint}
37
+ toggle={() => setIsOpenPrint(false)}
38
+ title="In tem mã vạch sản phẩm"
39
+ dataSelected={dataSelected}
40
+ setDataSelected={setDataSelected}
41
+ renderTable={({ selectedItems, setSelectedItems }) => (
42
+ <TableEdit
43
+ dataSource={dataList}
44
+ selectedItem={selectedItems}
45
+ setSelectedItem={setSelectedItems}
46
+ columns={[
47
+ { field: 'checkbox', type: 'checkbox', width: 40 },
48
+ { field: 'code', headerText: 'Mã hàng' },
49
+ { field: 'name', headerText: 'Tên hàng' },
50
+ { field: 'price', headerText: 'Giá bán' },
51
+ { field: 'printQuantity', headerText: 'Số lượng in', editEnable: true }
52
+ ]}
53
+ />
54
+ )}
55
+ />
56
+ </div>
57
+ )
58
+ }
59
+
60
+ export default MyProductPage
61
+ ```
62
+
63
+ ## 3. Khổ giấy hỗ trợ
64
+ - **Khổ 2 tem (80x22mm)**: Máy in tem cuộn nhiệt
65
+ - **Khổ 3 tem (105x22mm)**: Máy in tem cuộn nhiệt
66
+ - **Khổ A5 (40 tem - Tomy 108)**: 5 cột x 8 hàng
67
+ - **Khổ A4 (65 tem - Tomy 145)**: 5 cột x 13 hàng
68
+ - **Khổ tùy chọn**: Tùy biến số tem trên mỗi hàng
69
+
70
+ ## 4. Các tính năng nổi bật
71
+ - **Kéo thả dịch lề trái/phải** trực tiếp trên mẫu xem trước.
72
+ - **Thêm/xóa/đổi thứ tự** các trường in linh hoạt.
73
+ - **Định dạng phông chữ**: In đậm, in nghiêng, gạch chân, đổi màu, đổi cỡ chữ, đổi tiền tố.
74
+ - **Chế độ xem trước khổ giấy**: Xem cả trang A4/A5 với lưới tem chân thực, tự động phân trang nếu vượt số lượng tem.
75
+ - **Hộp thoại xác nhận** an toàn khi khôi phục thiết lập gốc.
@@ -0,0 +1,113 @@
1
+ import * as react from 'react';
2
+ import { FC, ReactNode } from 'react';
3
+ import { UseFormWatch, UseFormSetValue, Control, FieldErrors } from 'react-hook-form';
4
+
5
+ interface IPrintField {
6
+ id: string;
7
+ key: string;
8
+ label: string;
9
+ type: 'text' | 'barcode' | 'custom';
10
+ enabled: boolean;
11
+ bold?: boolean;
12
+ italic?: boolean;
13
+ underline?: boolean;
14
+ color?: string;
15
+ fontSize?: number;
16
+ offsetX?: number;
17
+ prefix?: string;
18
+ suffix?: string;
19
+ customValue?: string;
20
+ }
21
+ interface ISettingPrint {
22
+ printType: number;
23
+ paperSize: number;
24
+ stampNumber: number;
25
+ productCode?: boolean;
26
+ productName?: boolean;
27
+ companyName?: boolean;
28
+ unitPrice?: boolean;
29
+ printSample?: number;
30
+ hinge?: boolean;
31
+ fields?: IPrintField[];
32
+ }
33
+ interface IBarcodePrintItem {
34
+ id?: string | number;
35
+ code: string;
36
+ name: string;
37
+ price?: number;
38
+ quantity?: number;
39
+ printQuantity?: number;
40
+ companyName?: string;
41
+ [key: string]: any;
42
+ }
43
+ interface IExtraFieldOption {
44
+ id: string;
45
+ key: string;
46
+ label: string;
47
+ type: 'text' | 'custom';
48
+ prefix?: string;
49
+ customValue?: string;
50
+ }
51
+
52
+ declare const getOrganizationName: () => string;
53
+ declare const generateBarcodeHtml: (value: string, printType: number, height?: number) => string;
54
+ declare const renderSingleLabelHtml: (item: IBarcodePrintItem, settings: ISettingPrint, companyNameDefault?: string, barcodeHeight?: number) => string;
55
+ declare const getPaperSizeLabel: (paperSize?: number, stampNumber?: number) => string;
56
+ declare const generatePrintDocument: (settings: ISettingPrint, items: IBarcodePrintItem[], isTest?: boolean, isPreview?: boolean) => {
57
+ html: string;
58
+ totalStamps: number;
59
+ paperLabel: string;
60
+ uniqueProducts: number;
61
+ };
62
+ declare const executePrint: (settings: ISettingPrint, items: IBarcodePrintItem[], isTest?: boolean) => void;
63
+
64
+ interface IFProps$1 {
65
+ watch: UseFormWatch<ISettingPrint>;
66
+ setValue?: UseFormSetValue<ISettingPrint>;
67
+ sampleItem?: Record<string, any>;
68
+ }
69
+ declare const PreviewPrint: ({ watch, setValue, sampleItem }: IFProps$1) => react.JSX.Element;
70
+
71
+ interface IFProps {
72
+ control: Control<ISettingPrint, any>;
73
+ watch: UseFormWatch<ISettingPrint>;
74
+ setValue: UseFormSetValue<ISettingPrint>;
75
+ errors?: FieldErrors<ISettingPrint>;
76
+ availableExtraFields?: IExtraFieldOption[];
77
+ t?: (key: string) => string;
78
+ }
79
+ declare const SettingPrint: (props: IFProps) => react.JSX.Element;
80
+
81
+ interface IFPropsModalPreview {
82
+ isOpen: boolean;
83
+ toggle: () => void;
84
+ settings: ISettingPrint;
85
+ items: IBarcodePrintItem[];
86
+ onPrint?: () => void;
87
+ t?: (key: string) => string;
88
+ }
89
+ declare const ModalPreviewPrint: FC<IFPropsModalPreview>;
90
+
91
+ interface IModalBarcodePrintProps {
92
+ isOpen: boolean;
93
+ toggle: () => void;
94
+ title?: string;
95
+ dataSelected: IBarcodePrintItem[];
96
+ setDataSelected: (items: IBarcodePrintItem[]) => void;
97
+ dataItem?: IBarcodePrintItem | null;
98
+ defaultFields?: IPrintField[];
99
+ availableExtraFields?: IExtraFieldOption[];
100
+ renderTable?: (props: {
101
+ selectedItems: IBarcodePrintItem[];
102
+ setSelectedItems: (items: IBarcodePrintItem[]) => void;
103
+ }) => ReactNode;
104
+ children?: ReactNode;
105
+ windowSize?: any;
106
+ t?: (key: string) => string;
107
+ onPrintSuccess?: () => void;
108
+ notifyError?: (message: string) => void;
109
+ notifySuccess?: (message: string) => void;
110
+ }
111
+ declare const ModalBarcodePrint: FC<IModalBarcodePrintProps>;
112
+
113
+ export { type IBarcodePrintItem, type IExtraFieldOption, type IModalBarcodePrintProps, type IPrintField, type ISettingPrint, ModalBarcodePrint, ModalPreviewPrint, PreviewPrint, SettingPrint, executePrint, generateBarcodeHtml, generatePrintDocument, getOrganizationName, getPaperSizeLabel, renderSingleLabelHtml };
@@ -0,0 +1,113 @@
1
+ import * as react from 'react';
2
+ import { FC, ReactNode } from 'react';
3
+ import { UseFormWatch, UseFormSetValue, Control, FieldErrors } from 'react-hook-form';
4
+
5
+ interface IPrintField {
6
+ id: string;
7
+ key: string;
8
+ label: string;
9
+ type: 'text' | 'barcode' | 'custom';
10
+ enabled: boolean;
11
+ bold?: boolean;
12
+ italic?: boolean;
13
+ underline?: boolean;
14
+ color?: string;
15
+ fontSize?: number;
16
+ offsetX?: number;
17
+ prefix?: string;
18
+ suffix?: string;
19
+ customValue?: string;
20
+ }
21
+ interface ISettingPrint {
22
+ printType: number;
23
+ paperSize: number;
24
+ stampNumber: number;
25
+ productCode?: boolean;
26
+ productName?: boolean;
27
+ companyName?: boolean;
28
+ unitPrice?: boolean;
29
+ printSample?: number;
30
+ hinge?: boolean;
31
+ fields?: IPrintField[];
32
+ }
33
+ interface IBarcodePrintItem {
34
+ id?: string | number;
35
+ code: string;
36
+ name: string;
37
+ price?: number;
38
+ quantity?: number;
39
+ printQuantity?: number;
40
+ companyName?: string;
41
+ [key: string]: any;
42
+ }
43
+ interface IExtraFieldOption {
44
+ id: string;
45
+ key: string;
46
+ label: string;
47
+ type: 'text' | 'custom';
48
+ prefix?: string;
49
+ customValue?: string;
50
+ }
51
+
52
+ declare const getOrganizationName: () => string;
53
+ declare const generateBarcodeHtml: (value: string, printType: number, height?: number) => string;
54
+ declare const renderSingleLabelHtml: (item: IBarcodePrintItem, settings: ISettingPrint, companyNameDefault?: string, barcodeHeight?: number) => string;
55
+ declare const getPaperSizeLabel: (paperSize?: number, stampNumber?: number) => string;
56
+ declare const generatePrintDocument: (settings: ISettingPrint, items: IBarcodePrintItem[], isTest?: boolean, isPreview?: boolean) => {
57
+ html: string;
58
+ totalStamps: number;
59
+ paperLabel: string;
60
+ uniqueProducts: number;
61
+ };
62
+ declare const executePrint: (settings: ISettingPrint, items: IBarcodePrintItem[], isTest?: boolean) => void;
63
+
64
+ interface IFProps$1 {
65
+ watch: UseFormWatch<ISettingPrint>;
66
+ setValue?: UseFormSetValue<ISettingPrint>;
67
+ sampleItem?: Record<string, any>;
68
+ }
69
+ declare const PreviewPrint: ({ watch, setValue, sampleItem }: IFProps$1) => react.JSX.Element;
70
+
71
+ interface IFProps {
72
+ control: Control<ISettingPrint, any>;
73
+ watch: UseFormWatch<ISettingPrint>;
74
+ setValue: UseFormSetValue<ISettingPrint>;
75
+ errors?: FieldErrors<ISettingPrint>;
76
+ availableExtraFields?: IExtraFieldOption[];
77
+ t?: (key: string) => string;
78
+ }
79
+ declare const SettingPrint: (props: IFProps) => react.JSX.Element;
80
+
81
+ interface IFPropsModalPreview {
82
+ isOpen: boolean;
83
+ toggle: () => void;
84
+ settings: ISettingPrint;
85
+ items: IBarcodePrintItem[];
86
+ onPrint?: () => void;
87
+ t?: (key: string) => string;
88
+ }
89
+ declare const ModalPreviewPrint: FC<IFPropsModalPreview>;
90
+
91
+ interface IModalBarcodePrintProps {
92
+ isOpen: boolean;
93
+ toggle: () => void;
94
+ title?: string;
95
+ dataSelected: IBarcodePrintItem[];
96
+ setDataSelected: (items: IBarcodePrintItem[]) => void;
97
+ dataItem?: IBarcodePrintItem | null;
98
+ defaultFields?: IPrintField[];
99
+ availableExtraFields?: IExtraFieldOption[];
100
+ renderTable?: (props: {
101
+ selectedItems: IBarcodePrintItem[];
102
+ setSelectedItems: (items: IBarcodePrintItem[]) => void;
103
+ }) => ReactNode;
104
+ children?: ReactNode;
105
+ windowSize?: any;
106
+ t?: (key: string) => string;
107
+ onPrintSuccess?: () => void;
108
+ notifyError?: (message: string) => void;
109
+ notifySuccess?: (message: string) => void;
110
+ }
111
+ declare const ModalBarcodePrint: FC<IModalBarcodePrintProps>;
112
+
113
+ export { type IBarcodePrintItem, type IExtraFieldOption, type IModalBarcodePrintProps, type IPrintField, type ISettingPrint, ModalBarcodePrint, ModalPreviewPrint, PreviewPrint, SettingPrint, executePrint, generateBarcodeHtml, generatePrintDocument, getOrganizationName, getPaperSizeLabel, renderSingleLabelHtml };