| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 1 | import * as React from "react"; |
| 2 | import * as DialogPrimitive from "@radix-ui/react-dialog"; |
| 3 | import { cn } from "@/lib/utils"; |
| 4 | import { Cross2Icon } from "@radix-ui/react-icons"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 5 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 6 | const Dialog = DialogPrimitive.Root; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 7 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 8 | const DialogTrigger = DialogPrimitive.Trigger; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 9 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 10 | const DialogPortal = DialogPrimitive.Portal; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 11 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 12 | const DialogClose = DialogPrimitive.Close; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 13 | |
| 14 | const DialogOverlay = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 15 | React.ElementRef<typeof DialogPrimitive.Overlay>, |
| 16 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 17 | >(({ className, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 18 | <DialogPrimitive.Overlay |
| 19 | ref={ref} |
| 20 | className={cn( |
| 21 | "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", |
| 22 | className, |
| 23 | )} |
| 24 | {...props} |
| 25 | /> |
| 26 | )); |
| 27 | DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 28 | |
| 29 | const DialogContent = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 30 | React.ElementRef<typeof DialogPrimitive.Content>, |
| 31 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 32 | >(({ className, children, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 33 | <DialogPortal> |
| 34 | <DialogOverlay /> |
| 35 | <DialogPrimitive.Content |
| 36 | ref={ref} |
| 37 | className={cn( |
| 38 | "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", |
| 39 | className, |
| 40 | )} |
| 41 | {...props} |
| 42 | > |
| 43 | {children} |
| 44 | <DialogPrimitive.Close 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 data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"> |
| 45 | <Cross2Icon className="h-4 w-4" /> |
| 46 | <span className="sr-only">Close</span> |
| 47 | </DialogPrimitive.Close> |
| 48 | </DialogPrimitive.Content> |
| 49 | </DialogPortal> |
| 50 | )); |
| 51 | DialogContent.displayName = DialogPrimitive.Content.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 52 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 53 | const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( |
| 54 | <div className={cn("flex flex-col space-y-1.5 text-center sm:text-left", className)} {...props} /> |
| 55 | ); |
| 56 | DialogHeader.displayName = "DialogHeader"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 57 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 58 | const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( |
| 59 | <div className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...props} /> |
| 60 | ); |
| 61 | DialogFooter.displayName = "DialogFooter"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 62 | |
| 63 | const DialogTitle = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 64 | React.ElementRef<typeof DialogPrimitive.Title>, |
| 65 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 66 | >(({ className, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 67 | <DialogPrimitive.Title |
| 68 | ref={ref} |
| 69 | className={cn("text-lg font-semibold leading-none tracking-tight", className)} |
| 70 | {...props} |
| 71 | /> |
| 72 | )); |
| 73 | DialogTitle.displayName = DialogPrimitive.Title.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 74 | |
| 75 | const DialogDescription = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 76 | React.ElementRef<typeof DialogPrimitive.Description>, |
| 77 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 78 | >(({ className, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 79 | <DialogPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} /> |
| 80 | )); |
| 81 | DialogDescription.displayName = DialogPrimitive.Description.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 82 | |
| 83 | export { |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 84 | Dialog, |
| 85 | DialogPortal, |
| 86 | DialogOverlay, |
| 87 | DialogTrigger, |
| 88 | DialogClose, |
| 89 | DialogContent, |
| 90 | DialogHeader, |
| 91 | DialogFooter, |
| 92 | DialogTitle, |
| 93 | DialogDescription, |
| 94 | }; |