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