@iobroker/json-config 8.2.1 → 8.2.3
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 +5 -2
- package/build/JsonConfigComponent/ConfigImageSendTo.js +5 -2
- package/build/JsonConfigComponent/ConfigImageSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigQrCode.js +13 -1
- package/build/JsonConfigComponent/ConfigQrCode.js.map +1 -1
- package/build/JsonConfigComponent/ConfigQrCodeSendTo.js +17 -2
- package/build/JsonConfigComponent/ConfigQrCodeSendTo.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -954,7 +954,7 @@ The backend must return a plain string (the data to encode).
|
|
|
954
954
|
| `size` | size of the QR code in px |
|
|
955
955
|
| `fgColor` | foreground color (default: `"#000000"`) |
|
|
956
956
|
| `bgColor` | background color (default: `"#ffffff"`) |
|
|
957
|
-
| `level` | error correction level: `L`, `M`, `Q`, or `H` (default: `L`)
|
|
957
|
+
| `level` | error correction level: `L`, `M`, `Q`, or `H` (default: `L`) |
|
|
958
958
|
|
|
959
959
|
#### Example of code in back-end for `qrCodeSendTo`
|
|
960
960
|
|
|
@@ -1708,7 +1708,10 @@ The schema is used here: https://github.com/SchemaStore/schemastore/blob/6da29cd
|
|
|
1708
1708
|
### **WORK IN PROGRESS**
|
|
1709
1709
|
-->
|
|
1710
1710
|
## Changelog
|
|
1711
|
-
### 8.2.
|
|
1711
|
+
### 8.2.3 (2026-03-04)
|
|
1712
|
+
- (@GermanBluefox) Increased the QR code padding
|
|
1713
|
+
|
|
1714
|
+
### 8.2.2 (2026-03-03)
|
|
1712
1715
|
- (@GermanBluefox) Added option `sendFirstByClick` to `imageSendTo`
|
|
1713
1716
|
- (@GermanBluefox) Added new component: `qrCodeSendTo`
|
|
1714
1717
|
- (@GermanBluefox) Added option `digits` to `state` component
|
|
@@ -45,7 +45,9 @@ export default class ConfigImageSendTo extends ConfigGeneric {
|
|
|
45
45
|
const localContext = this.getContext();
|
|
46
46
|
if (localContext !== this.localContext || !this.initialized) {
|
|
47
47
|
this.localContext = localContext;
|
|
48
|
-
|
|
48
|
+
if (!this.props.schema.sendFirstByClick || this.state.image !== undefined) {
|
|
49
|
+
setTimeout(() => this.askInstance(), this.initialized ? 300 : 50);
|
|
50
|
+
}
|
|
49
51
|
this.initialized = true;
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -56,12 +58,13 @@ export default class ConfigImageSendTo extends ConfigGeneric {
|
|
|
56
58
|
display: 'flex',
|
|
57
59
|
alignItems: 'center',
|
|
58
60
|
justifyContent: 'center',
|
|
61
|
+
cursor: this.state.loading ? 'default' : 'pointer',
|
|
59
62
|
}, onClick: () => !this.state.loading && this.askInstance() }, this.state.loading ? (React.createElement(CircularProgress, null)) : typeof this.props.schema.sendFirstByClick === 'boolean' ? (I18n.t('ra_Click to show')) : (this.getText(this.props.schema.sendFirstByClick, this.props.schema.noTranslation))));
|
|
60
63
|
}
|
|
61
64
|
if (this.state.image === undefined) {
|
|
62
65
|
return null;
|
|
63
66
|
}
|
|
64
|
-
return (React.createElement("img", { alt: "dynamic content", src: this.state.image, style: { width: this.props.schema.width || '100%', height: this.props.schema.height } }));
|
|
67
|
+
return (React.createElement("img", { title: this.getText(this.props.schema.tooltip), alt: "dynamic content", src: this.state.image, style: { width: this.props.schema.width || '100%', height: this.props.schema.height } }));
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
//# sourceMappingURL=ConfigImageSendTo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigImageSendTo.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigImageSendTo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,aAAmE,MAAM,iBAA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AI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,CACH,6BACI,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAC9C,GAAG,EAAC,iBAAiB,EACrB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACrB,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GACvF,CACL,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { CircularProgress } from '@mui/material';\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemImageSendTo } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigImageSendToProps extends ConfigGenericProps {\n schema: ConfigItemImageSendTo;\n}\n\ninterface ConfigImageSendToState extends ConfigGenericState {\n image?: string;\n loading?: boolean;\n}\n\nexport default class ConfigImageSendTo extends ConfigGeneric<ConfigImageSendToProps, ConfigImageSendToState> {\n private initialized = false;\n\n private localContext: string | undefined;\n\n componentDidMount(): void {\n super.componentDidMount();\n\n if (!this.props.schema.sendFirstByClick) {\n this.askInstance();\n }\n }\n\n askInstance(): void {\n if (this.props.alive) {\n let data = this.props.schema.data;\n if (data === undefined && this.props.schema.jsonData) {\n const dataStr: string = this.getPattern(this.props.schema.jsonData, null, true);\n if (dataStr) {\n try {\n data = JSON.parse(dataStr);\n } catch {\n console.error(`Cannot parse json data: ${JSON.stringify(data)}`);\n }\n }\n }\n\n if (data === undefined) {\n data = null;\n }\n this.setState({ loading: true }, () =>\n this.props.oContext.socket\n .sendTo(\n `${this.props.oContext.adapterName}.${this.props.oContext.instance}`,\n this.props.schema.command || 'send',\n data,\n )\n .then(image => this.setState({ image: image || '' })),\n );\n }\n }\n\n getContext(): string {\n const localContext: Record<string, any> = {};\n\n if (Array.isArray(this.props.schema.alsoDependsOn)) {\n this.props.schema.alsoDependsOn.forEach(\n attr => (localContext[attr] = ConfigGeneric.getValue(this.props.data, attr)),\n );\n }\n\n return JSON.stringify(localContext);\n }\n\n renderItem(/* error, disabled, defaultValue */): JSX.Element {\n if (this.props.alive) {\n const localContext = this.getContext();\n if (localContext !== this.localContext || !this.initialized) {\n this.localContext = localContext;\n if (!this.props.schema.sendFirstByClick || this.state.image !== undefined) {\n setTimeout(() => this.askInstance(), this.initialized ? 300 : 50);\n }\n this.initialized = true;\n }\n }\n\n if (!this.state.image && this.props.schema.sendFirstByClick) {\n return (\n <div\n style={{\n width: this.props.schema.width || '100%',\n height: this.props.schema.height,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n cursor: this.state.loading ? 'default' : 'pointer',\n }}\n onClick={() => !this.state.loading && this.askInstance()}\n >\n {this.state.loading ? (\n <CircularProgress />\n ) : typeof this.props.schema.sendFirstByClick === 'boolean' ? (\n I18n.t('ra_Click to show')\n ) : (\n this.getText(this.props.schema.sendFirstByClick, this.props.schema.noTranslation)\n )}\n </div>\n );\n }\n\n if (this.state.image === undefined) {\n return null;\n }\n\n return (\n <img\n title={this.getText(this.props.schema.tooltip)}\n alt=\"dynamic content\"\n src={this.state.image}\n style={{ width: this.props.schema.width || '100%', height: this.props.schema.height }}\n />\n );\n }\n}\n"]}
|
|
@@ -12,7 +12,19 @@ export default class ConfigQrCode extends ConfigGeneric {
|
|
|
12
12
|
if (!QRCodeComponent) {
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
// Quiet zone: QR spec (ISO 18004) requires min 4 modules.
|
|
16
|
+
// ~15% of size ensures sufficient quiet zone, minimum 32px
|
|
17
|
+
const padding = Math.max(32, Math.round((this.props.schema.size || 256) * 0.15));
|
|
18
|
+
return (React.createElement("div", { style: {
|
|
19
|
+
display: 'flex',
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
backgroundColor: this.props.schema.bgColor || 'white',
|
|
23
|
+
padding,
|
|
24
|
+
width: '100%',
|
|
25
|
+
height: '100%',
|
|
26
|
+
} },
|
|
27
|
+
React.createElement(QRCodeComponent, { title: this.getText(this.props.schema.tooltip), value: this.props.schema.data, size: this.props.schema.size, fgColor: this.props.schema.fgColor, bgColor: this.props.schema.bgColor, level: this.props.schema.level })));
|
|
16
28
|
}
|
|
17
29
|
}
|
|
18
30
|
//# sourceMappingURL=ConfigQrCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigQrCode.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigQrCode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAIxC,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAUlG,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAmD;IACzF,KAAK,CAAC,iBAAiB;QACnB,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,sBAAsB;QACtB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,UAAU;QACN,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAC1C,IAAI,CAAC,eAAe,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,CACH,oBAAC,eAAe,IACZ,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAC7B,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAC5B,OAAO,EAAE,IAAI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M;aACjB;YAED,oBAAC,eAAe,IACZ,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAC9C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAC7B,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAC5B,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAClC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAClC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAChC,CACA,CACT,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\n\nimport type QRCode from 'react-qr-code';\nimport type { ConfigItemQrCode } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigQrCodeProps extends ConfigGenericProps {\n schema: ConfigItemQrCode;\n}\n\ninterface ConfigQrCodeState extends ConfigGenericState {\n QRCode: typeof QRCode | null;\n}\n\nexport default class ConfigQrCode extends ConfigGeneric<ConfigQrCodeProps, ConfigQrCodeState> {\n async componentDidMount(): Promise<void> {\n super.componentDidMount();\n // lazy load of qrcode\n const module = await import('react-qr-code');\n this.setState({ QRCode: module.default });\n }\n\n renderItem(): JSX.Element | null {\n const QRCodeComponent = this.state.QRCode;\n if (!QRCodeComponent) {\n return null;\n }\n // Quiet zone: QR spec (ISO 18004) requires min 4 modules.\n // ~15% of size ensures sufficient quiet zone, minimum 32px\n const padding = Math.max(32, Math.round((this.props.schema.size || 256) * 0.15));\n\n return (\n <div\n style={{\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n backgroundColor: this.props.schema.bgColor || 'white',\n padding,\n width: '100%',\n height: '100%',\n }}\n >\n <QRCodeComponent\n title={this.getText(this.props.schema.tooltip)}\n value={this.props.schema.data}\n size={this.props.schema.size}\n fgColor={this.props.schema.fgColor}\n bgColor={this.props.schema.bgColor}\n level={this.props.schema.level}\n />\n </div>\n );\n }\n}\n"]}
|
|
@@ -47,7 +47,9 @@ export default class ConfigQrCodeSendTo extends ConfigGeneric {
|
|
|
47
47
|
const localContext = this.getContext();
|
|
48
48
|
if (localContext !== this.localContext || !this.initialized) {
|
|
49
49
|
this.localContext = localContext;
|
|
50
|
-
|
|
50
|
+
if (!this.props.schema.sendFirstByClick || this.state.qrData !== undefined) {
|
|
51
|
+
setTimeout(() => this.askInstance(), this.initialized ? 300 : 50);
|
|
52
|
+
}
|
|
51
53
|
this.initialized = true;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -57,13 +59,26 @@ export default class ConfigQrCodeSendTo extends ConfigGeneric {
|
|
|
57
59
|
display: 'flex',
|
|
58
60
|
alignItems: 'center',
|
|
59
61
|
justifyContent: 'center',
|
|
62
|
+
cursor: this.state.loading ? 'default' : 'pointer',
|
|
60
63
|
}, onClick: () => !this.state.loading && this.askInstance() }, this.state.loading ? (React.createElement(CircularProgress, null)) : typeof this.props.schema.sendFirstByClick === 'boolean' ? (I18n.t('ra_Click to show')) : (this.getText(this.props.schema.sendFirstByClick, this.props.schema.noTranslation))));
|
|
61
64
|
}
|
|
62
65
|
const QRCodeComponent = this.state.QRCode;
|
|
63
66
|
if (!QRCodeComponent || this.state.qrData === undefined) {
|
|
64
67
|
return null;
|
|
65
68
|
}
|
|
66
|
-
|
|
69
|
+
// Quiet zone: QR spec (ISO 18004) requires min 4 modules.
|
|
70
|
+
// ~15% of size ensures sufficient quiet zone, minimum 32px
|
|
71
|
+
const padding = Math.max(32, Math.round((this.props.schema.size || 256) * 0.15));
|
|
72
|
+
return (React.createElement("div", { style: {
|
|
73
|
+
display: 'flex',
|
|
74
|
+
justifyContent: 'center',
|
|
75
|
+
alignItems: 'center',
|
|
76
|
+
backgroundColor: this.props.schema.bgColor || 'white',
|
|
77
|
+
padding,
|
|
78
|
+
width: '100%',
|
|
79
|
+
height: '100%',
|
|
80
|
+
} },
|
|
81
|
+
React.createElement(QRCodeComponent, { title: this.getText(this.props.schema.tooltip), value: this.state.qrData, size: this.props.schema.size, fgColor: this.props.schema.fgColor, bgColor: this.props.schema.bgColor, level: this.props.schema.level })));
|
|
67
82
|
}
|
|
68
83
|
}
|
|
69
84
|
//# sourceMappingURL=ConfigQrCodeSendTo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigQrCodeSendTo.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigQrCodeSendTo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAIlD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAYlG,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,aAA+D;IACnG,WAAW,GAAG,KAAK,CAAC;IAEpB,YAAY,CAAqB;IAEzC,KAAK,CAAC,iBAAiB;QACnB,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACL,CAAC;IAED,WAAW;QACP,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;YAClC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ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;gBACf,cAAc,EAAE,QAAQ;gBACxB,UAAU,EAAE,QAAQ;gBACpB,eAAe,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO;gBACrD,OAAO;gBACP,KAAK,EAAE,MAAM;gBACb,MAAM,EAAE,MAAM;aACjB;YAED,oBAAC,eAAe,IACZ,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAC9C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACxB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAC5B,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAClC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAClC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAChC,CACA,CACT,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { CircularProgress } from '@mui/material';\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type QRCode from 'react-qr-code';\nimport type { ConfigItemQrCodeSendTo } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigQrCodeSendToProps extends ConfigGenericProps {\n schema: ConfigItemQrCodeSendTo;\n}\n\ninterface ConfigQrCodeSendToState extends ConfigGenericState {\n qrData?: string;\n loading?: boolean;\n QRCode: typeof QRCode | null;\n}\n\nexport default class ConfigQrCodeSendTo extends ConfigGeneric<ConfigQrCodeSendToProps, ConfigQrCodeSendToState> {\n private initialized = false;\n\n private localContext: string | undefined;\n\n async componentDidMount(): Promise<void> {\n super.componentDidMount();\n const module = await import('react-qr-code');\n this.setState({ QRCode: module.default });\n if (!this.props.schema.sendFirstByClick) {\n this.askInstance();\n }\n }\n\n askInstance(): void {\n if (this.props.alive) {\n let data = this.props.schema.data;\n if (data === undefined && this.props.schema.jsonData) {\n const dataStr: string = this.getPattern(this.props.schema.jsonData, null, true);\n if (dataStr) {\n try {\n data = JSON.parse(dataStr);\n } catch {\n console.error(`Cannot parse json data: ${JSON.stringify(data)}`);\n }\n }\n }\n\n if (data === undefined) {\n data = null;\n }\n this.setState({ loading: true }, () =>\n this.props.oContext.socket\n .sendTo(\n `${this.props.oContext.adapterName}.${this.props.oContext.instance}`,\n this.props.schema.command || 'send',\n data,\n )\n .then(qrData => this.setState({ qrData: qrData || '', loading: false })),\n );\n }\n }\n\n getContext(): string {\n const localContext: Record<string, any> = {};\n\n if (Array.isArray(this.props.schema.alsoDependsOn)) {\n this.props.schema.alsoDependsOn.forEach(\n attr => (localContext[attr] = ConfigGeneric.getValue(this.props.data, attr)),\n );\n }\n\n return JSON.stringify(localContext);\n }\n\n renderItem(): JSX.Element | null {\n if (this.props.alive) {\n const localContext = this.getContext();\n if (localContext !== this.localContext || !this.initialized) {\n this.localContext = localContext;\n if (!this.props.schema.sendFirstByClick || this.state.qrData !== undefined) {\n setTimeout(() => this.askInstance(), this.initialized ? 300 : 50);\n }\n this.initialized = true;\n }\n }\n\n if (!this.state.qrData && this.props.schema.sendFirstByClick) {\n return (\n <div\n style={{\n width: '100%',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n cursor: this.state.loading ? 'default' : 'pointer',\n }}\n onClick={() => !this.state.loading && this.askInstance()}\n >\n {this.state.loading ? (\n <CircularProgress />\n ) : typeof this.props.schema.sendFirstByClick === 'boolean' ? (\n I18n.t('ra_Click to show')\n ) : (\n this.getText(this.props.schema.sendFirstByClick, this.props.schema.noTranslation)\n )}\n </div>\n );\n }\n\n const QRCodeComponent = this.state.QRCode;\n if (!QRCodeComponent || this.state.qrData === undefined) {\n return null;\n }\n // Quiet zone: QR spec (ISO 18004) requires min 4 modules.\n // ~15% of size ensures sufficient quiet zone, minimum 32px\n const padding = Math.max(32, Math.round((this.props.schema.size || 256) * 0.15));\n\n return (\n <div\n style={{\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n backgroundColor: this.props.schema.bgColor || 'white',\n padding,\n width: '100%',\n height: '100%',\n }}\n >\n <QRCodeComponent\n title={this.getText(this.props.schema.tooltip)}\n value={this.state.qrData}\n size={this.props.schema.size}\n fgColor={this.props.schema.fgColor}\n bgColor={this.props.schema.bgColor}\n level={this.props.schema.level}\n />\n </div>\n );\n }\n}\n"]}
|