dialog.tsx
3,347 bytes
| 1 | 'use client'; |
|---|---|
| 2 | |
| 3 | import * as DialogPrimitive from '@radix-ui/react-dialog'; |
| 4 | import { X } from 'lucide-react'; |
| 5 | import * as React from 'react'; |
| 6 | import { cn } from '@/lib/utils'; |
| 7 | |
| 8 | const Dialog = DialogPrimitive.Root; |
| 9 | const DialogTrigger = DialogPrimitive.Trigger; |
| 10 | const DialogPortal = DialogPrimitive.Portal; |
| 11 | const DialogClose = DialogPrimitive.Close; |
| 12 | |
| 13 | const DialogOverlay = React.forwardRef< |
| 14 | React.ElementRef<typeof DialogPrimitive.Overlay>, |
| 15 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> |
| 16 | >(({ className, ...props }, ref) => ( |
| 17 | <DialogPrimitive.Overlay |
| 18 | ref={ref} |
| 19 | className={cn( |
| 20 | 'fixed inset-0 z-50 bg-black/60 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0', |
| 21 | className, |
| 22 | )} |
| 23 | {...props} |
| 24 | /> |
| 25 | )); |
| 26 | DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; |
| 27 | |
| 28 | const DialogContent = React.forwardRef< |
| 29 | React.ElementRef<typeof DialogPrimitive.Content>, |
| 30 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> |
| 31 | >(({ className, children, ...props }, ref) => ( |
| 32 | <DialogPortal> |
| 33 | <DialogOverlay /> |
| 34 | <DialogPrimitive.Content |
| 35 | ref={ref} |
| 36 | className={cn( |
| 37 | 'fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 border bg-card 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 sm:rounded-xl', |
| 38 | className, |
| 39 | )} |
| 40 | {...props} |
| 41 | > |
| 42 | {children} |
| 43 | <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"> |
| 44 | <X className="h-4 w-4" /> |
| 45 | <span className="sr-only">Close</span> |
| 46 | </DialogPrimitive.Close> |
| 47 | </DialogPrimitive.Content> |
| 48 | </DialogPortal> |
| 49 | )); |
| 50 | DialogContent.displayName = DialogPrimitive.Content.displayName; |
| 51 | |
| 52 | function DialogHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) { |
| 53 | return <div className={cn('flex flex-col space-y-1.5 text-left', className)} {...props} />; |
| 54 | } |
| 55 | function DialogFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) { |
| 56 | return <div className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)} {...props} />; |
| 57 | } |
| 58 | |
| 59 | const DialogTitle = React.forwardRef< |
| 60 | React.ElementRef<typeof DialogPrimitive.Title>, |
| 61 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> |
| 62 | >(({ className, ...props }, ref) => ( |
| 63 | <DialogPrimitive.Title ref={ref} className={cn('text-lg font-semibold', className)} {...props} /> |
| 64 | )); |
| 65 | DialogTitle.displayName = DialogPrimitive.Title.displayName; |
| 66 | |
| 67 | const DialogDescription = React.forwardRef< |
| 68 | React.ElementRef<typeof DialogPrimitive.Description>, |
| 69 | React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> |
| 70 | >(({ className, ...props }, ref) => ( |
| 71 | <DialogPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} /> |
| 72 | )); |
| 73 | DialogDescription.displayName = DialogPrimitive.Description.displayName; |
| 74 | |
| 75 | export { |
| 76 | Dialog, |
| 77 | DialogPortal, |
| 78 | DialogOverlay, |
| 79 | DialogTrigger, |
| 80 | DialogClose, |
| 81 | DialogContent, |
| 82 | DialogHeader, |
| 83 | DialogFooter, |
| 84 | DialogTitle, |
| 85 | DialogDescription, |
| 86 | }; |
| 87 | |