dialog.tsx135 lines, 3.7 KB
| 1 | "use client" |
| 2 | |
| 3 | import * as React from "react" |
| 4 | import * as DialogPrimitive from "@radix-ui/react-dialog" |
| 5 | import { XIcon } from "lucide-react" |
| 6 | |
| 7 | import { cn } from "@/lib/utils" |
| 8 | |
| 9 | function Dialog({ |
| 10 | ...props |
| 11 | }: React.ComponentProps<typeof DialogPrimitive.Root>) { |
| 12 | return <DialogPrimitive.Root data-slot="dialog" {...props} /> |
| 13 | } |
| 14 | |
| 15 | function DialogTrigger({ |
| 16 | ...props |
| 17 | }: React.ComponentProps<typeof DialogPrimitive.Trigger>) { |
| 18 | return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} /> |
| 19 | } |
| 20 | |
| 21 | function DialogPortal({ |
| 22 | ...props |
| 23 | }: React.ComponentProps<typeof DialogPrimitive.Portal>) { |
| 24 | return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} /> |
| 25 | } |
| 26 | |
| 27 | function DialogClose({ |
| 28 | ...props |
| 29 | }: React.ComponentProps<typeof DialogPrimitive.Close>) { |
| 30 | return <DialogPrimitive.Close data-slot="dialog-close" {...props} /> |
| 31 | } |
| 32 | |
| 33 | function DialogOverlay({ |
| 34 | className, |
| 35 | ...props |
| 36 | }: React.ComponentProps<typeof DialogPrimitive.Overlay>) { |
| 37 | return ( |
| 38 | <DialogPrimitive.Overlay |
| 39 | data-slot="dialog-overlay" |
| 40 | className={cn( |
| 41 | "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80", |
| 42 | className |
| 43 | )} |
| 44 | {...props} |
| 45 | /> |
| 46 | ) |
| 47 | } |
| 48 | |
| 49 | function DialogContent({ |
| 50 | className, |
| 51 | children, |
| 52 | ...props |
| 53 | }: React.ComponentProps<typeof DialogPrimitive.Content>) { |
| 54 | return ( |
| 55 | <DialogPortal data-slot="dialog-portal"> |
| 56 | <DialogOverlay /> |
| 57 | <DialogPrimitive.Content |
| 58 | data-slot="dialog-content" |
| 59 | className={cn( |
| 60 | "bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg", |
| 61 | className |
| 62 | )} |
| 63 | {...props} |
| 64 | > |
| 65 | {children} |
| 66 | <DialogPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"> |
| 67 | <XIcon /> |
| 68 | <span className="sr-only">Close</span> |
| 69 | </DialogPrimitive.Close> |
| 70 | </DialogPrimitive.Content> |
| 71 | </DialogPortal> |
| 72 | ) |
| 73 | } |
| 74 | |
| 75 | function DialogHeader({ className, ...props }: React.ComponentProps<"div">) { |
| 76 | return ( |
| 77 | <div |
| 78 | data-slot="dialog-header" |
| 79 | className={cn("flex flex-col gap-2 text-center sm:text-left", className)} |
| 80 | {...props} |
| 81 | /> |
| 82 | ) |
| 83 | } |
| 84 | |
| 85 | function DialogFooter({ className, ...props }: React.ComponentProps<"div">) { |
| 86 | return ( |
| 87 | <div |
| 88 | data-slot="dialog-footer" |
| 89 | className={cn( |
| 90 | "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", |
| 91 | className |
| 92 | )} |
| 93 | {...props} |
| 94 | /> |
| 95 | ) |
| 96 | } |
| 97 | |
| 98 | function DialogTitle({ |
| 99 | className, |
| 100 | ...props |
| 101 | }: React.ComponentProps<typeof DialogPrimitive.Title>) { |
| 102 | return ( |
| 103 | <DialogPrimitive.Title |
| 104 | data-slot="dialog-title" |
| 105 | className={cn("text-lg leading-none font-semibold", className)} |
| 106 | {...props} |
| 107 | /> |
| 108 | ) |
| 109 | } |
| 110 | |
| 111 | function DialogDescription({ |
| 112 | className, |
| 113 | ...props |
| 114 | }: React.ComponentProps<typeof DialogPrimitive.Description>) { |
| 115 | return ( |
| 116 | <DialogPrimitive.Description |
| 117 | data-slot="dialog-description" |
| 118 | className={cn("text-muted-foreground text-sm", className)} |
| 119 | {...props} |
| 120 | /> |
| 121 | ) |
| 122 | } |
| 123 | |
| 124 | export { |
| 125 | Dialog, |
| 126 | DialogClose, |
| 127 | DialogContent, |
| 128 | DialogDescription, |
| 129 | DialogFooter, |
| 130 | DialogHeader, |
| 131 | DialogOverlay, |
| 132 | DialogPortal, |
| 133 | DialogTitle, |
| 134 | DialogTrigger, |
| 135 | } |