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

qrcode #1

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading