|
| 1 | +import * as React from "react" |
| 2 | +import * as DialogPrimitive from "@radix-ui/react-dialog" |
| 3 | +import { Cross2Icon } from "@radix-ui/react-icons" |
| 4 | + |
| 5 | +import { cn } from "@/lib/utils" |
| 6 | + |
| 7 | +const Dialog = DialogPrimitive.Root |
| 8 | + |
| 9 | +const DialogTrigger = DialogPrimitive.Trigger |
| 10 | + |
| 11 | +const DialogClose = DialogPrimitive.Close |
| 12 | + |
| 13 | +const DialogPortal = DialogPrimitive.Portal |
| 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 | + className={cn( |
| 21 | + "fixed inset-0 z-50 bg-background/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 | + ref={ref} |
| 26 | + /> |
| 27 | +)) |
| 28 | +DialogOverlay.displayName = DialogPrimitive.Overlay.displayName |
| 29 | + |
| 30 | +interface DialogContentProps |
| 31 | + extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {} |
| 32 | + |
| 33 | +const DialogContent = React.forwardRef< |
| 34 | + React.ElementRef<typeof DialogPrimitive.Content>, |
| 35 | + DialogContentProps |
| 36 | +>(({ className, children, ...props }, ref) => ( |
| 37 | + <DialogPortal> |
| 38 | + <DialogOverlay /> |
| 39 | + <DialogPrimitive.Content |
| 40 | + ref={ref} |
| 41 | + className="fixed z-50 flex h-screen w-screen items-center justify-center" |
| 42 | + {...props} |
| 43 | + > |
| 44 | + <div |
| 45 | + className={cn( |
| 46 | + "relative rounded-lg border border-gray-100 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out", |
| 47 | + className |
| 48 | + )} |
| 49 | + > |
| 50 | + <DialogClose 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-secondary"> |
| 51 | + <Cross2Icon className="size-5" /> |
| 52 | + </DialogClose> |
| 53 | + {children} |
| 54 | + </div> |
| 55 | + </DialogPrimitive.Content> |
| 56 | + </DialogPortal> |
| 57 | +)) |
| 58 | +DialogContent.displayName = DialogPrimitive.Content.displayName |
| 59 | + |
| 60 | +const DialogTitle = React.forwardRef< |
| 61 | + React.ElementRef<typeof DialogPrimitive.Title>, |
| 62 | + React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> |
| 63 | +>(({ className, ...props }, ref) => ( |
| 64 | + <DialogPrimitive.Title |
| 65 | + ref={ref} |
| 66 | + className={cn("text-lg font-semibold text-foreground", className)} |
| 67 | + {...props} |
| 68 | + /> |
| 69 | +)) |
| 70 | +DialogTitle.displayName = DialogPrimitive.Title.displayName |
| 71 | + |
| 72 | +const DialogDescription = React.forwardRef< |
| 73 | + React.ElementRef<typeof DialogPrimitive.Description>, |
| 74 | + React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> |
| 75 | +>(({ className, ...props }, ref) => ( |
| 76 | + <DialogPrimitive.Description |
| 77 | + ref={ref} |
| 78 | + className={cn("text-sm text-muted-foreground", className)} |
| 79 | + {...props} |
| 80 | + /> |
| 81 | +)) |
| 82 | +DialogDescription.displayName = DialogPrimitive.Description.displayName |
| 83 | + |
| 84 | +const DialogHeader = ({ |
| 85 | + className, |
| 86 | + children, |
| 87 | + ...props |
| 88 | +}: React.HTMLAttributes<HTMLDivElement>) => ( |
| 89 | + <div className={cn("w-full pr-6", className)} {...props}> |
| 90 | + <DialogTitle>{children}</DialogTitle> |
| 91 | + </div> |
| 92 | +) |
| 93 | +DialogHeader.displayName = "DialogHeader" |
| 94 | + |
| 95 | +const DialogFooter = ({ |
| 96 | + className, |
| 97 | + ...props |
| 98 | +}: React.HTMLAttributes<HTMLDivElement>) => ( |
| 99 | + <div |
| 100 | + className={cn( |
| 101 | + "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", |
| 102 | + className |
| 103 | + )} |
| 104 | + {...props} |
| 105 | + /> |
| 106 | +) |
| 107 | +DialogFooter.displayName = "DialogFooter" |
| 108 | + |
| 109 | +export { |
| 110 | + Dialog, |
| 111 | + DialogPortal, |
| 112 | + DialogOverlay, |
| 113 | + DialogTrigger, |
| 114 | + DialogClose, |
| 115 | + DialogContent, |
| 116 | + DialogHeader, |
| 117 | + DialogFooter, |
| 118 | + DialogTitle, |
| 119 | + DialogDescription, |
| 120 | +} |
0 commit comments