|
| 1 | +import * as React from 'react' |
| 2 | +import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog' |
| 3 | +import { cn } from '@/lib/utils' |
| 4 | +import { buttonVariants } from '@/components/ui/button' |
| 5 | + |
| 6 | +const AlertDialog = AlertDialogPrimitive.Root |
| 7 | +const AlertDialogTrigger = AlertDialogPrimitive.Trigger |
| 8 | +const AlertDialogPortal = AlertDialogPrimitive.Portal |
| 9 | + |
| 10 | +const AlertDialogOverlay = React.forwardRef< |
| 11 | + React.ElementRef<typeof AlertDialogPrimitive.Overlay>, |
| 12 | + React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay> |
| 13 | +>(({ className, ...props }, ref) => ( |
| 14 | + <AlertDialogPrimitive.Overlay |
| 15 | + className={cn( |
| 16 | + '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', |
| 17 | + className |
| 18 | + )} |
| 19 | + {...props} |
| 20 | + ref={ref} |
| 21 | + /> |
| 22 | +)) |
| 23 | +AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName |
| 24 | + |
| 25 | +const AlertDialogContent = React.forwardRef< |
| 26 | + React.ElementRef<typeof AlertDialogPrimitive.Content>, |
| 27 | + React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content> |
| 28 | +>(({ className, ...props }, ref) => ( |
| 29 | + <AlertDialogPortal> |
| 30 | + <AlertDialogOverlay /> |
| 31 | + <AlertDialogPrimitive.Content |
| 32 | + ref={ref} |
| 33 | + className={cn( |
| 34 | + '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', |
| 35 | + className |
| 36 | + )} |
| 37 | + {...props} |
| 38 | + /> |
| 39 | + </AlertDialogPortal> |
| 40 | +)) |
| 41 | +AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName |
| 42 | + |
| 43 | +const AlertDialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( |
| 44 | + <div className={cn('flex flex-col space-y-2 text-center sm:text-left', className)} {...props} /> |
| 45 | +) |
| 46 | +AlertDialogHeader.displayName = 'AlertDialogHeader' |
| 47 | + |
| 48 | +const AlertDialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( |
| 49 | + <div className={cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className)} {...props} /> |
| 50 | +) |
| 51 | +AlertDialogFooter.displayName = 'AlertDialogFooter' |
| 52 | + |
| 53 | +const AlertDialogTitle = React.forwardRef< |
| 54 | + React.ElementRef<typeof AlertDialogPrimitive.Title>, |
| 55 | + React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title> |
| 56 | +>(({ className, ...props }, ref) => ( |
| 57 | + <AlertDialogPrimitive.Title ref={ref} className={cn('text-lg font-semibold', className)} {...props} /> |
| 58 | +)) |
| 59 | +AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName |
| 60 | + |
| 61 | +const AlertDialogDescription = React.forwardRef< |
| 62 | + React.ElementRef<typeof AlertDialogPrimitive.Description>, |
| 63 | + React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description> |
| 64 | +>(({ className, ...props }, ref) => ( |
| 65 | + <AlertDialogPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} /> |
| 66 | +)) |
| 67 | +AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName |
| 68 | + |
| 69 | +const AlertDialogAction = React.forwardRef< |
| 70 | + React.ElementRef<typeof AlertDialogPrimitive.Action>, |
| 71 | + React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action> |
| 72 | +>(({ className, ...props }, ref) => ( |
| 73 | + <AlertDialogPrimitive.Action ref={ref} className={cn(buttonVariants(), className)} {...props} /> |
| 74 | +)) |
| 75 | +AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName |
| 76 | + |
| 77 | +const AlertDialogCancel = React.forwardRef< |
| 78 | + React.ElementRef<typeof AlertDialogPrimitive.Cancel>, |
| 79 | + React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel> |
| 80 | +>(({ className, ...props }, ref) => ( |
| 81 | + <AlertDialogPrimitive.Cancel ref={ref} className={cn(buttonVariants({ variant: 'outline' }), 'mt-2 sm:mt-0', className)} {...props} /> |
| 82 | +)) |
| 83 | +AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName |
| 84 | + |
| 85 | +export { |
| 86 | + AlertDialog, AlertDialogPortal, AlertDialogOverlay, AlertDialogTrigger, |
| 87 | + AlertDialogContent, AlertDialogHeader, AlertDialogFooter, |
| 88 | + AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel, |
| 89 | +} |
0 commit comments