@arcblock/ux 2.1.1 → 2.1.2
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/lib/QRCode/index.js +14 -5
- package/package.json +4 -4
- package/src/QRCode/index.js +19 -6
package/lib/QRCode/index.js
CHANGED
|
@@ -54,8 +54,8 @@ function QRCode(_ref) {
|
|
|
54
54
|
|
|
55
55
|
const ref = _react.default.useRef(null);
|
|
56
56
|
|
|
57
|
-
(0, _react.
|
|
58
|
-
|
|
57
|
+
const options = (0, _react.useMemo)(() => {
|
|
58
|
+
return _objectSpread(_objectSpread(_objectSpread({}, defaults), {}, {
|
|
59
59
|
data,
|
|
60
60
|
width: size,
|
|
61
61
|
height: size
|
|
@@ -65,9 +65,18 @@ function QRCode(_ref) {
|
|
|
65
65
|
crossOrigin: 'anonymous',
|
|
66
66
|
margin: 0
|
|
67
67
|
}
|
|
68
|
-
}), config)
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
}), config);
|
|
69
|
+
}, [data, size, image, config]);
|
|
70
|
+
const [qrCode] = (0, _react.useState)(new _qrCodeStyling.default(options));
|
|
71
|
+
(0, _react.useEffect)(() => {
|
|
72
|
+
if (ref.current) {
|
|
73
|
+
qrCode.append(ref.current);
|
|
74
|
+
}
|
|
75
|
+
}, [qrCode, ref]);
|
|
76
|
+
(0, _react.useEffect)(() => {
|
|
77
|
+
if (!qrCode) return;
|
|
78
|
+
qrCode.update(options);
|
|
79
|
+
}, [data, size, image, config]);
|
|
71
80
|
return /*#__PURE__*/_react.default.createElement("div", Object.assign({
|
|
72
81
|
ref: ref
|
|
73
82
|
}, rest));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"react": ">=18.1.0",
|
|
53
53
|
"react-ga": "^2.7.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "a73064aaab5cde4fa378672c9c037cf427022123",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/icons": "^2.1.
|
|
58
|
-
"@arcblock/react-hooks": "^2.1.
|
|
57
|
+
"@arcblock/icons": "^2.1.2",
|
|
58
|
+
"@arcblock/react-hooks": "^2.1.2",
|
|
59
59
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
60
60
|
"@emotion/react": "^11.9.0",
|
|
61
61
|
"@emotion/styled": "^11.8.1",
|
package/src/QRCode/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import QRCodeStyling from '@solana/qr-code-styling';
|
|
4
4
|
|
|
@@ -19,8 +19,8 @@ const defaults = {
|
|
|
19
19
|
// 注意: 依赖的 @solana/qr-code-styling 是一份 fork 版本, 原版本的 margin 配置存在 bug
|
|
20
20
|
function QRCode({ data, size, image, config, ...rest }) {
|
|
21
21
|
const ref = React.useRef(null);
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const options = useMemo(() => {
|
|
23
|
+
return {
|
|
24
24
|
...defaults,
|
|
25
25
|
data,
|
|
26
26
|
width: size,
|
|
@@ -33,9 +33,22 @@ function QRCode({ data, size, image, config, ...rest }) {
|
|
|
33
33
|
},
|
|
34
34
|
}),
|
|
35
35
|
...config,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
};
|
|
37
|
+
}, [data, size, image, config]);
|
|
38
|
+
|
|
39
|
+
const [qrCode] = useState(new QRCodeStyling(options));
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (ref.current) {
|
|
43
|
+
qrCode.append(ref.current);
|
|
44
|
+
}
|
|
45
|
+
}, [qrCode, ref]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!qrCode) return;
|
|
49
|
+
qrCode.update(options);
|
|
50
|
+
}, [data, size, image, config]);
|
|
51
|
+
|
|
39
52
|
return <div ref={ref} {...rest} />;
|
|
40
53
|
}
|
|
41
54
|
|