|
| 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 | +function AlertDialog({ |
| 8 | + ...props |
| 9 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) { |
| 10 | + return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />; |
| 11 | +} |
| 12 | + |
| 13 | +function AlertDialogTrigger({ |
| 14 | + ...props |
| 15 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) { |
| 16 | + return ( |
| 17 | + <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} /> |
| 18 | + ); |
| 19 | +} |
| 20 | + |
| 21 | +function AlertDialogPortal({ |
| 22 | + ...props |
| 23 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) { |
| 24 | + return ( |
| 25 | + <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} /> |
| 26 | + ); |
| 27 | +} |
| 28 | + |
| 29 | +const AlertDialogOverlay = React.forwardRef< |
| 30 | + HTMLDivElement, |
| 31 | + React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay> |
| 32 | +>(({ className, ...props }, ref) => { |
| 33 | + return ( |
| 34 | + <AlertDialogPrimitive.Overlay |
| 35 | + data-slot="alert-dialog-overlay" |
| 36 | + className={cn( |
| 37 | + "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/50", |
| 38 | + className, |
| 39 | + )} |
| 40 | + ref={ref} |
| 41 | + {...props} |
| 42 | + /> |
| 43 | + ); |
| 44 | +}); |
| 45 | + |
| 46 | +function AlertDialogContent({ |
| 47 | + className, |
| 48 | + ...props |
| 49 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Content>) { |
| 50 | + return ( |
| 51 | + <AlertDialogPortal> |
| 52 | + <AlertDialogOverlay /> |
| 53 | + <AlertDialogPrimitive.Content |
| 54 | + data-slot="alert-dialog-content" |
| 55 | + className={cn( |
| 56 | + "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 border-stone-200 bg-white p-6 shadow-lg duration-200 sm:max-w-lg dark:border-stone-800 dark:bg-stone-950", |
| 57 | + className, |
| 58 | + )} |
| 59 | + {...props} |
| 60 | + /> |
| 61 | + </AlertDialogPortal> |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +function AlertDialogHeader({ |
| 66 | + className, |
| 67 | + ...props |
| 68 | +}: React.ComponentProps<"div">) { |
| 69 | + return ( |
| 70 | + <div |
| 71 | + data-slot="alert-dialog-header" |
| 72 | + className={cn("flex flex-col gap-2 text-center sm:text-left", className)} |
| 73 | + {...props} |
| 74 | + /> |
| 75 | + ); |
| 76 | +} |
| 77 | + |
| 78 | +function AlertDialogFooter({ |
| 79 | + className, |
| 80 | + ...props |
| 81 | +}: React.ComponentProps<"div">) { |
| 82 | + return ( |
| 83 | + <div |
| 84 | + data-slot="alert-dialog-footer" |
| 85 | + className={cn( |
| 86 | + "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", |
| 87 | + className, |
| 88 | + )} |
| 89 | + {...props} |
| 90 | + /> |
| 91 | + ); |
| 92 | +} |
| 93 | + |
| 94 | +function AlertDialogTitle({ |
| 95 | + className, |
| 96 | + ...props |
| 97 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) { |
| 98 | + return ( |
| 99 | + <AlertDialogPrimitive.Title |
| 100 | + data-slot="alert-dialog-title" |
| 101 | + className={cn("text-lg font-semibold", className)} |
| 102 | + {...props} |
| 103 | + /> |
| 104 | + ); |
| 105 | +} |
| 106 | + |
| 107 | +function AlertDialogDescription({ |
| 108 | + className, |
| 109 | + ...props |
| 110 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) { |
| 111 | + return ( |
| 112 | + <AlertDialogPrimitive.Description |
| 113 | + data-slot="alert-dialog-description" |
| 114 | + className={cn("text-sm text-stone-500 dark:text-stone-400", className)} |
| 115 | + {...props} |
| 116 | + /> |
| 117 | + ); |
| 118 | +} |
| 119 | + |
| 120 | +function AlertDialogAction({ |
| 121 | + className, |
| 122 | + ...props |
| 123 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Action>) { |
| 124 | + return ( |
| 125 | + <AlertDialogPrimitive.Action |
| 126 | + className={cn(buttonVariants(), className)} |
| 127 | + {...props} |
| 128 | + /> |
| 129 | + ); |
| 130 | +} |
| 131 | + |
| 132 | +function AlertDialogCancel({ |
| 133 | + className, |
| 134 | + ...props |
| 135 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) { |
| 136 | + return ( |
| 137 | + <AlertDialogPrimitive.Cancel |
| 138 | + className={cn(buttonVariants({ variant: "outline" }), className)} |
| 139 | + {...props} |
| 140 | + /> |
| 141 | + ); |
| 142 | +} |
| 143 | + |
| 144 | +export { |
| 145 | + AlertDialog, |
| 146 | + AlertDialogPortal, |
| 147 | + AlertDialogOverlay, |
| 148 | + AlertDialogTrigger, |
| 149 | + AlertDialogContent, |
| 150 | + AlertDialogHeader, |
| 151 | + AlertDialogFooter, |
| 152 | + AlertDialogTitle, |
| 153 | + AlertDialogDescription, |
| 154 | + AlertDialogAction, |
| 155 | + AlertDialogCancel, |
| 156 | +}; |
0 commit comments