2024-10-28 18:23:21 +05:30
|
|
|
import React, { useState } from 'react';
|
2024-10-25 05:41:04 +05:30
|
|
|
import { QRCodeSVG } from 'qrcode.react';
|
2024-10-28 18:23:21 +05:30
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Check, Copy } from "lucide-react";
|
2024-10-25 05:41:04 +05:30
|
|
|
|
|
|
|
|
interface QRCodeProps {
|
2024-10-25 21:12:53 +05:30
|
|
|
text: string;
|
|
|
|
|
width?: number;
|
|
|
|
|
height?: number;
|
2024-10-25 05:41:04 +05:30
|
|
|
}
|
|
|
|
|
|
2024-10-25 21:12:53 +05:30
|
|
|
const QRCode: React.FC<QRCodeProps> = ({ text, width = 256, height = 256 }) => {
|
2024-10-28 18:23:21 +05:30
|
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
|
|
|
|
|
|
const handleCopy = async () => {
|
|
|
|
|
await navigator.clipboard.writeText(text);
|
|
|
|
|
setCopied(true);
|
|
|
|
|
setTimeout(() => setCopied(false), 2000);
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-25 05:41:04 +05:30
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-center space-y-4">
|
2024-10-25 21:12:53 +05:30
|
|
|
<QRCodeSVG value={text} size={Math.min(width, height)} />
|
2024-10-28 18:23:21 +05:30
|
|
|
<div className="flex items-center space-x-2">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value={text}
|
|
|
|
|
readOnly
|
|
|
|
|
className="flex-1 px-3 py-2 text-sm border rounded-md bg-muted"
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
onClick={handleCopy}
|
|
|
|
|
>
|
|
|
|
|
{copied ? <Check className="h-4 w-4" /> : <Copy className="h-4 w-4" />}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2024-10-25 05:41:04 +05:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default QRCode;
|