-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathBarcodeGenerator.editorPreview.tsx
More file actions
50 lines (44 loc) · 1.88 KB
/
Copy pathBarcodeGenerator.editorPreview.tsx
File metadata and controls
50 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import classNames from "classnames";
import { ReactElement } from "react";
import { parseStyle } from "@mendix/widget-plugin-platform/preview/parse-style";
import { BarcodeGeneratorPreviewProps } from "../typings/BarcodeGeneratorProps";
import { DownloadIcon } from "./components/icons/DownloadIcon";
import { BarcodePreview } from "./components/preview/BarcodePreview";
import { DataMatrixPreview } from "./components/preview/DataMatrixPreview";
import { QRCodePreview } from "./components/preview/QRCodePreview";
const defaultDownloadCaption = "Download";
function PreviewDownloadButton(props: BarcodeGeneratorPreviewProps): ReactElement | null {
if (!props.allowDownload) {
return null;
}
return (
<a className="mx-link" role="button" aria-label={props.downloadButtonAriaLabel || undefined} tabIndex={0}>
<DownloadIcon /> {props.downloadButtonCaption || defaultDownloadCaption}
</a>
);
}
export function preview(props: BarcodeGeneratorPreviewProps): ReactElement {
const styles = parseStyle(props.style);
const isQrCode = props.codeFormat === "QRCode";
const isDataMatrix = props.codeFormat === "DataMatrix";
const downloadButton = <PreviewDownloadButton {...props} />;
return (
<div
className={classNames(props.class, props.className, "barcode-generator", {
"barcode-generator--as-card": props.showAsCard
})}
style={styles}
>
{isQrCode ? (
<QRCodePreview {...props} downloadButton={downloadButton} />
) : isDataMatrix ? (
<DataMatrixPreview {...props} downloadButton={downloadButton} />
) : (
<BarcodePreview {...props} downloadButton={downloadButton} />
)}
</div>
);
}
export function getPreviewCss(): string {
return require("./ui/BarcodeGenerator.scss");
}