diff options
Diffstat (limited to 'src/common/components/Scanner')
| -rw-r--r-- | src/common/components/Scanner/index.tsx | 39 | ||||
| -rw-r--r-- | src/common/components/Scanner/scanner.module.css | 16 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/common/components/Scanner/index.tsx b/src/common/components/Scanner/index.tsx new file mode 100644 index 0000000..56d2495 --- /dev/null +++ b/src/common/components/Scanner/index.tsx @@ -0,0 +1,39 @@ +import { useZxing } from "react-zxing"; +import styles from "./scanner.module.css" + +type Props = { + paused: boolean, + onScan: (string: string) => void +} + +const Scanner = (props: Props) => { + const { ref } = useZxing({ + constraints: { + video: { + facingMode: 'environment', + width: { ideal: 1280 }, + height: { ideal: 720 }, + frameRate: { ideal: 30, max: 60 } + } + }, + timeBetweenDecodingAttempts: 100, + paused: props.paused, + onDecodeResult(result) { + props.onScan(result.getText()); + }, + }) + + const restartCam = () => { + ref.current?.pause() + ref.current?.play() + } + + return ( + <div className={styles.wrapper}> + <video ref={ref} onClick={restartCam} className={styles.video} /> + <div className={styles.videoFrame} /> + </div> + ) +} + +export default Scanner
\ No newline at end of file diff --git a/src/common/components/Scanner/scanner.module.css b/src/common/components/Scanner/scanner.module.css new file mode 100644 index 0000000..3528172 --- /dev/null +++ b/src/common/components/Scanner/scanner.module.css @@ -0,0 +1,16 @@ +.wrapper { + @apply relative w-auto h-auto rounded-lg border border-default-300; +} + +.video { + @apply rounded-lg; +} + +.videoFrame { + @apply absolute + border-dashed border-2 border-default-50 + w-3/5 h-1/5 + top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 + pointer-events-none + rounded-md; +} |
