| 1 | import * as React from "react"; |
| 2 | import * as DialogPrimitive from "@radix-ui/react-dialog"; |
| 3 | import { X } from "lucide-react"; |
| 4 | |
| 5 | import { cn } from "@/lib/utils"; |
| 6 | |
| 7 | const Dialog = DialogPrimitive.Root; |
| 8 | |
| 9 | const DialogTrigger = DialogPrimitive.Trigger; |
| 10 | |
| 11 | const DialogPortal = DialogPrimitive.Portal; |
| 12 | |
| 13 | const DialogClose = DialogPrimitive.Close; |
| 14 | |
| 15 | const DialogOverlay = React.forwardRef< |
| 16 | React.ElementRef<typeof DialogPrimitive.Overlay>, |
| 17 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> |
| 18 | >(({ className, ...props }, ref) => ( |
| 19 | <DialogPrimitive.Overlay |
| 20 | ref={ref} |
| 21 | className={cn( |
| 22 | "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", |
| 23 | className, |
| 24 | )} |
| 25 | {...props} |
| 26 | /> |
| 27 | )); |
| 28 | DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; |
| 29 | |
| 30 | const DialogContent = React.forwardRef< |
| 31 | React.ElementRef<typeof DialogPrimitive.Content>, |
| 32 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> |
| 33 | >(({ className, children, ...props }, ref) => ( |
| 34 | <DialogPortal> |
| 35 | <DialogOverlay /> |
| 36 | <DialogPrimitive.Content |
| 37 | ref={ref} |
| 38 | className={cn( |
| 39 | "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg", |
| 40 | className, |
| 41 | )} |
| 42 | {...props} |
| 43 | > |
| 44 | {children} |
| 45 | <DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity data-[state=open]:bg-accent data-[state=open]:text-muted-foreground hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none"> |
| 46 | <X className="h-4 w-4" /> |
| 47 | <span className="sr-only">Close</span> |
| 48 | </DialogPrimitive.Close> |
| 49 | </DialogPrimitive.Content> |
| 50 | </DialogPortal> |
| 51 | )); |
| 52 | DialogContent.displayName = DialogPrimitive.Content.displayName; |
| 53 | |
| 54 | const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( |
| 55 | <div className={cn("flex flex-col space-y-1.5 text-center sm:text-left", className)} {...props} /> |
| 56 | ); |
| 57 | DialogHeader.displayName = "DialogHeader"; |
| 58 | |
| 59 | const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( |
| 60 | <div className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...props} /> |
| 61 | ); |
| 62 | DialogFooter.displayName = "DialogFooter"; |
| 63 | |
| 64 | const DialogTitle = React.forwardRef< |
| 65 | React.ElementRef<typeof DialogPrimitive.Title>, |
| 66 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> |
| 67 | >(({ className, ...props }, ref) => ( |
| 68 | <DialogPrimitive.Title |
| 69 | ref={ref} |
| 70 | className={cn("text-lg font-semibold leading-none tracking-tight", className)} |
| 71 | {...props} |
| 72 | /> |
| 73 | )); |
| 74 | DialogTitle.displayName = DialogPrimitive.Title.displayName; |
| 75 | |
| 76 | const DialogDescription = React.forwardRef< |
| 77 | React.ElementRef<typeof DialogPrimitive.Description>, |
| 78 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> |
| 79 | >(({ className, ...props }, ref) => ( |
| 80 | <DialogPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} /> |
| 81 | )); |
| 82 | DialogDescription.displayName = DialogPrimitive.Description.displayName; |
| 83 | |
| 84 | export { |
| 85 | Dialog, |
| 86 | DialogPortal, |
| 87 | DialogOverlay, |
| 88 | DialogClose, |
| 89 | DialogTrigger, |
| 90 | DialogContent, |
| 91 | DialogHeader, |
| 92 | DialogFooter, |
| 93 | DialogTitle, |
| 94 | DialogDescription, |
| 95 | }; |