Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from Neon-20/qrcode
Browse files Browse the repository at this point in the history
qrcode
  • Loading branch information
Neon-20 authored Oct 13, 2023
2 parents d73a798 + 4c30fe1 commit 3b56302
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"lucide-react": "^0.277.0",
"next": "13.5.4",
"postcss": "8.4.31",
"qr-code-styling": "^1.6.0-rc.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-intersection-observer": "^9.5.2",
Expand Down
46 changes: 46 additions & 0 deletions src/components/qrcode/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { useEffect, useRef } from 'react';
import QRCodeStyling from 'qr-code-styling';

interface GenerateQRProps {
url: string | URL;
size?: number;
background?: string;
color?: string;
}

const GenerateQR: React.FC<GenerateQRProps> = ({ url, size = 512, background = 'white', color = 'black' }) => {
const qrCodeRef = useRef<HTMLDivElement | null>(null);

useEffect(() => {
if (qrCodeRef.current) {
const qrCode = new QRCodeStyling({
width: size,
height: size,
data: url.toString(),
image: '',
margin: 20,
qrOptions: {
typeNumber: 0,
mode: 'Byte',
errorCorrectionLevel: 'Q',
},
dotsOptions: {
color: color,
type: 'square',
},
backgroundOptions: {
color: background,
},
});

qrCode.append(qrCodeRef.current);
qrCode.update();
}
}, [url, size, background, color]);

return (
<div ref={qrCodeRef}></div>
);
};

export default GenerateQR;

0 comments on commit 3b56302

Please sign in to comment.