Files
QR-master/src/components/ui/Dialog.tsx
2025-10-13 20:19:18 +02:00

92 lines
2.5 KiB
TypeScript

import React from 'react';
import { cn } from '@/lib/utils';
interface DialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
children: React.ReactNode;
}
export const Dialog: React.FC<DialogProps> = ({ open, onOpenChange, children }) => {
if (!open) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center">
<div
className="fixed inset-0 bg-black/50"
onClick={() => onOpenChange(false)}
/>
<div className="relative z-50 w-full max-w-lg mx-4">
{children}
</div>
</div>
);
};
interface DialogContentProps extends React.HTMLAttributes<HTMLDivElement> {}
export const DialogContent = React.forwardRef<HTMLDivElement, DialogContentProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
'bg-white rounded-xl shadow-lg border border-gray-200 p-6',
className
)}
{...props}
/>
)
);
DialogContent.displayName = 'DialogContent';
interface DialogHeaderProps extends React.HTMLAttributes<HTMLDivElement> {}
export const DialogHeader = React.forwardRef<HTMLDivElement, DialogHeaderProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn('flex flex-col space-y-1.5 text-center sm:text-left', className)}
{...props}
/>
)
);
DialogHeader.displayName = 'DialogHeader';
interface DialogTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {}
export const DialogTitle = React.forwardRef<HTMLHeadingElement, DialogTitleProps>(
({ className, ...props }, ref) => (
<h2
ref={ref}
className={cn('text-lg font-semibold leading-none tracking-tight', className)}
{...props}
/>
)
);
DialogTitle.displayName = 'DialogTitle';
interface DialogDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {}
export const DialogDescription = React.forwardRef<HTMLParagraphElement, DialogDescriptionProps>(
({ className, ...props }, ref) => (
<p
ref={ref}
className={cn('text-sm text-gray-600', className)}
{...props}
/>
)
);
DialogDescription.displayName = 'DialogDescription';
interface DialogFooterProps extends React.HTMLAttributes<HTMLDivElement> {}
export const DialogFooter = React.forwardRef<HTMLDivElement, DialogFooterProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 pt-4', className)}
{...props}
/>
)
);
DialogFooter.displayName = 'DialogFooter';