-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hjort
committed
Apr 26, 2022
1 parent
c59b0de
commit 3008106
Showing
6 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useLayoutEffect, useState, useRef } from 'react'; | ||
import { QRCodeCanvas } from 'qrcode.react'; | ||
|
||
interface Props { | ||
value: string; | ||
className: string; | ||
} | ||
|
||
/** | ||
* Displays the given value as a QR code. The size of the QR is controlled by className. | ||
*/ | ||
export default function QR({ value, className }: Props) { | ||
const [size, setSize] = useState(0); | ||
const ref = useRef<HTMLDivElement>(null); | ||
const [obs] = useState( | ||
new ResizeObserver((entries) => { | ||
setSize( | ||
ref.current !== null | ||
? Math.min( | ||
entries[0].contentRect.height, | ||
entries[0].contentRect.width | ||
) | ||
: 0 | ||
); | ||
}) | ||
); | ||
|
||
useLayoutEffect(() => { | ||
if (ref.current) { | ||
obs.observe(ref.current); | ||
return () => obs.disconnect(); | ||
} | ||
return () => {}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [ref.current]); | ||
|
||
return ( | ||
<div className={className} ref={ref}> | ||
<QRCodeCanvas size={size} value={value} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15796,24 +15796,15 @@ q@^1.1.2: | |
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7" | ||
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc= | ||
|
||
[email protected]: | ||
version "0.0.0" | ||
resolved "https://registry.yarnpkg.com/qr.js/-/qr.js-0.0.0.tgz#cace86386f59a0db8050fa90d9b6b0e88a1e364f" | ||
integrity sha1-ys6GOG9ZoNuAUPqQ2baw6IoeNk8= | ||
|
||
qrcode-terminal@^0.10.0: | ||
version "0.10.0" | ||
resolved "https://registry.yarnpkg.com/qrcode-terminal/-/qrcode-terminal-0.10.0.tgz#a76a48e2610a18f97fa3a2bd532b682acff86c53" | ||
integrity sha1-p2pI4mEKGPl/o6K9UytoKs/4bFM= | ||
|
||
qrcode.react@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/qrcode.react/-/qrcode.react-1.0.1.tgz#2834bb50e5e275ffe5af6906eff15391fe9e38a5" | ||
integrity sha512-8d3Tackk8IRLXTo67Y+c1rpaiXjoz/Dd2HpcMdW//62/x8J1Nbho14Kh8x974t9prsLHN6XqVgcnRiBGFptQmg== | ||
dependencies: | ||
loose-envify "^1.4.0" | ||
prop-types "^15.6.0" | ||
qr.js "0.0.0" | ||
qrcode.react@^3.0.1: | ||
version "3.0.1" | ||
resolved "https://registry.yarnpkg.com/qrcode.react/-/qrcode.react-3.0.1.tgz#0cb1d7cfdf3955737fbd3509c193985795ca0612" | ||
integrity sha512-uCNm16ClMCrdM2R20c/zqmdwHcbMQf3K7ey39EiK/UgEKbqWeM0iH2QxW3iDVFzjQKFzH23ICgOyG4gNsJ0/gw== | ||
|
||
[email protected]: | ||
version "6.7.0" | ||
|