mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 16:33:36 +00:00
93 lines
2.6 KiB
TypeScript
93 lines
2.6 KiB
TypeScript
import { Button } from '@/components/ui/button';
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
import { X, Copy, Check, QrCode, Zap } from 'lucide-react';
|
|
import { useCopyToClipboard } from '@/hooks/useCopyToClipboard';
|
|
|
|
interface QRModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
title: string;
|
|
description: string;
|
|
qrCodeUrl: string;
|
|
content: string;
|
|
icon?: 'qr' | 'zap';
|
|
}
|
|
|
|
export function QRModal({
|
|
isOpen,
|
|
onClose,
|
|
title,
|
|
description,
|
|
qrCodeUrl,
|
|
content,
|
|
icon = 'qr',
|
|
}: QRModalProps) {
|
|
const { copy, copied } = useCopyToClipboard();
|
|
|
|
const handleCopy = () => {
|
|
copy(content);
|
|
};
|
|
if (!isOpen) return null;
|
|
|
|
const IconComponent = icon === 'zap' ? Zap : QrCode;
|
|
|
|
return (
|
|
<div
|
|
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
|
|
onClick={onClose}
|
|
>
|
|
<Card
|
|
className="w-full max-w-md border-0 shadow-lg bg-background"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<CardHeader className="relative">
|
|
<Button
|
|
onClick={onClose}
|
|
className="absolute top-2 right-2"
|
|
size="sm"
|
|
variant="ghost"
|
|
>
|
|
<X className="h-4 w-4" />
|
|
</Button>
|
|
<CardTitle className="flex items-center pr-8">
|
|
<IconComponent className="h-5 w-5 mr-2" />
|
|
{title}
|
|
</CardTitle>
|
|
<CardDescription>
|
|
{description}
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
<div className="flex justify-center">
|
|
<div className="bg-white dark:bg-gray-100 p-4 rounded-lg border shadow-sm">
|
|
<img
|
|
src={qrCodeUrl}
|
|
alt={`${title} QR Code`}
|
|
className="w-64 h-64 object-contain"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="text-center">
|
|
<div
|
|
className="bg-muted p-3 rounded-lg border font-mono text-sm break-all cursor-pointer hover:bg-muted/80 transition-colors relative group"
|
|
onClick={handleCopy}
|
|
title="Click to copy"
|
|
>
|
|
{content}
|
|
<div className="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
|
{copied ? (
|
|
<Check className="h-4 w-4 text-green-600" />
|
|
) : (
|
|
<Copy className="h-4 w-4 text-muted-foreground" />
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|