Skip to content

Commit f6ba2ee

Browse files
committed
qrcode-click
1 parent e7508eb commit f6ba2ee

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/widgets.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const loadingSVG = (<svg xmlns="http://www.w3.org/2000/svg" width="50" height="5
2727
</path>
2828
</svg>);
2929

30-
const developmentMode = false;
3130

32-
export const ConnectQR = ({ mobile, level = 'H', size = null, label = qrCodeLabel, loading = loadingSVG, maxSize = 400, vspace = 130, hspace = 50 }) => {
31+
32+
export const ConnectQR = ({ mobile, level = 'H', size = null, label = qrCodeLabel, loading = loadingSVG, maxSize = 400, vspace = 130, hspace = 50, onClickCode=null }) => {
3333
const [optimumSize, setOptimumSize] = useState(0);
3434
useEffect(() => {
3535
const handleResize = () => {
@@ -62,29 +62,24 @@ export const ConnectQR = ({ mobile, level = 'H', size = null, label = qrCodeLabe
6262
if ((!mobile.connectionCode) || size === 0) {
6363
return null;
6464
}
65-
if(developmentMode && window.location.hostname==='localhost' && navigator.clipboard && navigator.clipboard.writeText){
66-
65+
6766
return (
6867
<div style={styles.qrCode} onClick={() => {
69-
navigator.clipboard.writeText(mobile.connectionCode);
68+
if(onClickCode){
69+
onClickCode(mobile.connectionCode);
70+
}
71+
7072
}}>
7173
<QRCodeSVG value={mobile.connectionCode} level={level} size={size ? size : optimumSize} />
7274
{label}
7375
</div>
7476
);
7577

76-
}
77-
78-
return (
79-
<div style={styles.qrCode}>
80-
<QRCodeSVG value={mobile.connectionCode} level={level} size={size ? size : optimumSize} />
81-
{label}
82-
</div>
83-
);
78+
8479
};
8580

8681

87-
export const PairingQR = ({ mobile, level = 'H', size = null, label = qrCodeLabel, loading = loadingSVG, maxSize = 400, vspace = 130, hspace = 50 }) => {
82+
export const PairingQR = ({ mobile, level = 'H', size = null, label = qrCodeLabel, loading = loadingSVG, maxSize = 400, vspace = 130, hspace = 50, onClickCode=null }) => {
8883
const [optimumSize, setOptimumSize] = useState(0);
8984
useEffect(() => {
9085
const handleResize = () => {
@@ -117,10 +112,17 @@ export const PairingQR = ({ mobile, level = 'H', size = null, label = qrCodeLabe
117112
if ((!mobile.pairingCode) || size === 0) {
118113
return null;
119114
}
120-
return (
121-
<div style={styles.qrCode}>
122-
<QRCodeSVG value={mobile.pairingCode} level={level} size={size ? size : optimumSize} />
123-
{label}
124-
</div>
125-
);
115+
116+
return (
117+
<div style={styles.qrCode} onClick={() => {
118+
if(onClickCode){
119+
onClickCode(mobile.pairingCode);
120+
}
121+
}}>
122+
<QRCodeSVG value={mobile.pairingCode} level={level} size={size ? size : optimumSize} />
123+
{label}
124+
</div>
125+
);
126+
127+
126128
};

0 commit comments

Comments
 (0)