| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [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" |
| 5 | |
| 6 | const Dialog = DialogPrimitive.Root |
| 7 | |
| 8 | const DialogTrigger = DialogPrimitive.Trigger |
| 9 | |
| 10 | const DialogPortal = DialogPrimitive.Portal |
| 11 | |
| 12 | const DialogClose = DialogPrimitive.Close |
| 13 | |
| 14 | const DialogOverlay = React.forwardRef< |
| 15 | React.ElementRef<typeof DialogPrimitive.Overlay>, |
| 16 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> |
| 17 | >(({ className, ...props }, ref) => ( |
| 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 |
| 28 | |
| 29 | const DialogContent = React.forwardRef< |
| 30 | React.ElementRef<typeof DialogPrimitive.Content>, |
| 31 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> |
| 32 | >(({ className, children, ...props }, ref) => ( |
| 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 |
| 52 | |
| 53 | const DialogHeader = ({ |
| 54 | className, |
| 55 | ...props |
| 56 | }: React.HTMLAttributes<HTMLDivElement>) => ( |
| 57 | <div |
| 58 | className={cn( |
| 59 | "flex flex-col space-y-1.5 text-center sm:text-left", |
| 60 | className |
| 61 | )} |
| 62 | {...props} |
| 63 | /> |
| 64 | ) |
| 65 | DialogHeader.displayName = "DialogHeader" |
| 66 | |
| 67 | const DialogFooter = ({ |
| 68 | className, |
| 69 | ...props |
| 70 | }: React.HTMLAttributes<HTMLDivElement>) => ( |
| 71 | <div |
| 72 | className={cn( |
| 73 | "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", |
| 74 | className |
| 75 | )} |
| 76 | {...props} |
| 77 | /> |
| 78 | ) |
| 79 | DialogFooter.displayName = "DialogFooter" |
| 80 | |
| 81 | const DialogTitle = React.forwardRef< |
| 82 | React.ElementRef<typeof DialogPrimitive.Title>, |
| 83 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> |
| 84 | >(({ className, ...props }, ref) => ( |
| 85 | <DialogPrimitive.Title |
| 86 | ref={ref} |
| 87 | className={cn( |
| 88 | "text-lg font-semibold leading-none tracking-tight", |
| 89 | className |
| 90 | )} |
| 91 | {...props} |
| 92 | /> |
| 93 | )) |
| 94 | DialogTitle.displayName = DialogPrimitive.Title.displayName |
| 95 | |
| 96 | const DialogDescription = React.forwardRef< |
| 97 | React.ElementRef<typeof DialogPrimitive.Description>, |
| 98 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> |
| 99 | >(({ className, ...props }, ref) => ( |
| 100 | <DialogPrimitive.Description |
| 101 | ref={ref} |
| 102 | className={cn("text-sm text-muted-foreground", className)} |
| 103 | {...props} |
| 104 | /> |
| 105 | )) |
| 106 | DialogDescription.displayName = DialogPrimitive.Description.displayName |
| 107 | |
| 108 | export { |
| 109 | Dialog, |
| 110 | DialogPortal, |
| 111 | DialogOverlay, |
| 112 | DialogTrigger, |
| 113 | DialogClose, |
| 114 | DialogContent, |
| 115 | DialogHeader, |
| 116 | DialogFooter, |
| 117 | DialogTitle, |
| 118 | DialogDescription, |
| 119 | } |