Spaces:
Sleeping
Sleeping
File size: 2,177 Bytes
d97b8f9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import React from 'react';
import { X } from 'lucide-react';
import { Button } from '@/components/ui/button';
interface CustomDialogProps {
isOpen: boolean;
onClose: () => void;
title: string;
description?: string;
children: React.ReactNode;
allowClose?: boolean;
isPending?: boolean;
}
const CustomDialog: React.FC<CustomDialogProps> = ({
isOpen,
onClose,
title,
description,
children,
allowClose = true,
isPending = false,
}) => {
if (!isOpen) return null;
const handleOverlayClick = (e: React.MouseEvent) => {
// Only allow closing if explicitly enabled and not pending
if (allowClose && !isPending && e.target === e.currentTarget) {
onClose();
}
};
return (
<div className="fixed inset-0 z-[999] flex items-center justify-center p-4 overflow-hidden">
{/* Overlay */}
<div
className="fixed inset-0 bg-black/80 backdrop-blur-sm"
onClick={handleOverlayClick}
/>
{/* Modal Content */}
<div className="relative z-[1000] w-full max-w-3xl rounded-lg border bg-background p-6 shadow-lg flex flex-col max-h-[90vh] overflow-hidden">
{/* Header */}
<div className="mb-4 flex-shrink-0">
<h2 className="text-lg font-semibold">{title}</h2>
{description && <p className="text-sm text-muted-foreground">{description}</p>}
</div>
{/* Body - Add auto overflow to allow content to scroll */}
<div className="flex-1 overflow-auto">
{children}
</div>
{/* Close button - only if allowed */}
{allowClose && !isPending && (
<button
onClick={onClose}
className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none z-[1001]"
>
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</button>
)}
</div>
</div>
);
};
export default CustomDialog; |