Skip to content

Commit 5d9e04d

Browse files
committed
fix: update @types/react version in package.json
1 parent df54fe5 commit 5d9e04d

17 files changed

+422
-584
lines changed
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { ReactElement } from "react";
22
import { BarcodeGeneratorContainerProps } from "../typings/BarcodeGeneratorProps";
33
import { barcodeConfig } from "./config/Barcode.config";
4-
import { BarcodeConfigProvider } from "./config/BarcodeConfigContext";
5-
import { BarcodeGeneratorInner } from "./components/BarcodeGeneratorInner";
4+
import { BarcodeContextProvider, useBarcodeConfig } from "./config/BarcodeContext";
5+
import { QRCodeRenderer } from "./components/QRCode";
6+
import { BarcodeRenderer } from "./components/Barcode";
67

78
import "./ui/BarcodeGenerator.scss";
89

10+
function BarcodeContainer({ tabIndex }: { tabIndex?: number }): ReactElement {
11+
const config = useBarcodeConfig();
12+
13+
return (
14+
<div className="barcode-generator" tabIndex={tabIndex}>
15+
{config.isQRCode ? <QRCodeRenderer /> : <BarcodeRenderer />}
16+
</div>
17+
);
18+
}
19+
920
export default function BarcodeGenerator(props: BarcodeGeneratorContainerProps): ReactElement {
1021
const config = barcodeConfig(props);
1122

@@ -14,8 +25,8 @@ export default function BarcodeGenerator(props: BarcodeGeneratorContainerProps):
1425
}
1526

1627
return (
17-
<BarcodeConfigProvider config={config}>
18-
<BarcodeGeneratorInner tabIndex={props.tabIndex} />
19-
</BarcodeConfigProvider>
28+
<BarcodeContextProvider config={config}>
29+
<BarcodeContainer tabIndex={props.tabIndex} />
30+
</BarcodeContextProvider>
2031
);
2132
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useRenderBarcode } from "../hooks/useRenderBarcode";
2+
import { useDownloadBarcode } from "../hooks/useDownloadBarcode";
3+
import { useBarcodeConfig } from "../config/BarcodeContext";
4+
5+
import { Fragment } from "react";
6+
7+
export const BarcodeRenderer = () => {
8+
const ref = useRenderBarcode();
9+
const { allowDownload } = useBarcodeConfig();
10+
const { downloadBarcode } = useDownloadBarcode({ ref });
11+
12+
return (
13+
<Fragment>
14+
<svg ref={ref} />
15+
{allowDownload && (
16+
<button className="btn btn-default" onClick={downloadBarcode}>
17+
Download barcode
18+
</button>
19+
)}
20+
</Fragment>
21+
);
22+
};

packages/pluggableWidgets/barcode-generator-web/src/components/BarcodeGeneratorInner.tsx

Lines changed: 0 additions & 54 deletions
This file was deleted.

packages/pluggableWidgets/barcode-generator-web/src/components/BarcodeRenderer.tsx

Lines changed: 0 additions & 58 deletions
This file was deleted.

packages/pluggableWidgets/barcode-generator-web/src/components/CodeRenderer.tsx

Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { QRCodeSVG } from "qrcode.react";
2+
import { Fragment, useRef } from "react";
3+
import { useDownloadQrCode } from "../hooks/useDownloadQRCode";
4+
import { useBarcodeConfig } from "../config/BarcodeContext";
5+
6+
export const QRCodeRenderer = () => {
7+
const ref = useRef<SVGSVGElement>(null);
8+
const { downloadQrCode } = useDownloadQrCode({ ref });
9+
10+
const {
11+
value,
12+
allowDownload,
13+
qrSize: size,
14+
qrMargin: margin,
15+
qrTitle: title,
16+
qrLevel: level,
17+
qrImageSrc: imageSrc,
18+
qrImageX: imageX,
19+
qrImageY: imageY,
20+
qrImageHeight: imageHeight,
21+
qrImageWidth: imageWidth,
22+
qrImageOpacity: imageOpacity,
23+
qrImageExcavate: imageExcavate
24+
} = useBarcodeConfig();
25+
const imageSettings = imageSrc
26+
? {
27+
src: imageSrc,
28+
x: imageX,
29+
y: imageY,
30+
height: imageHeight,
31+
width: imageWidth,
32+
opacity: imageOpacity,
33+
excavate: imageExcavate
34+
}
35+
: undefined;
36+
37+
return (
38+
<Fragment>
39+
<QRCodeSVG
40+
ref={ref}
41+
value={value}
42+
size={size}
43+
level={level.toUpperCase() as "L" | "M" | "Q" | "H"}
44+
marginSize={margin}
45+
title={title}
46+
imageSettings={imageSettings}
47+
/>
48+
{allowDownload && (
49+
<button type="button" onClick={downloadQrCode} className="btn btn-default">
50+
Download QR Code
51+
</button>
52+
)}
53+
</Fragment>
54+
);
55+
};

0 commit comments

Comments
 (0)