|
| 1 | +"use client"; |
| 2 | + |
1 | 3 | import * as React from "react"; |
2 | 4 | import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"; |
3 | 5 |
|
4 | 6 | import { cn } from "@/lib/utils"; |
5 | 7 | import { buttonVariants } from "@/components/ui/button"; |
6 | 8 |
|
7 | | -const AlertDialog = AlertDialogPrimitive.Root; |
8 | | - |
9 | | -const AlertDialogTrigger = AlertDialogPrimitive.Trigger; |
| 9 | +function AlertDialog({ |
| 10 | + ...props |
| 11 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) { |
| 12 | + return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />; |
| 13 | +} |
10 | 14 |
|
11 | | -const AlertDialogPortal = AlertDialogPrimitive.Portal; |
| 15 | +function AlertDialogTrigger({ |
| 16 | + ...props |
| 17 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) { |
| 18 | + return ( |
| 19 | + <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} /> |
| 20 | + ); |
| 21 | +} |
12 | 22 |
|
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; |
| 23 | +function AlertDialogPortal({ |
| 24 | + ...props |
| 25 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) { |
| 26 | + return ( |
| 27 | + <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} /> |
| 28 | + ); |
| 29 | +} |
27 | 30 |
|
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} |
| 31 | +function AlertDialogOverlay({ |
| 32 | + className, |
| 33 | + ...props |
| 34 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) { |
| 35 | + return ( |
| 36 | + <AlertDialogPrimitive.Overlay |
| 37 | + data-slot="alert-dialog-overlay" |
36 | 38 | 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", |
| 39 | + "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 | 40 | className |
39 | 41 | )} |
40 | 42 | {...props} |
41 | 43 | /> |
42 | | - </AlertDialogPortal> |
43 | | -)); |
44 | | -AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName; |
| 44 | + ); |
| 45 | +} |
45 | 46 |
|
46 | | -const AlertDialogHeader = ({ |
| 47 | +function AlertDialogContent({ |
47 | 48 | className, |
48 | 49 | ...props |
49 | | -}: React.HTMLAttributes<HTMLDivElement>) => ( |
50 | | - <div |
51 | | - className={cn( |
52 | | - "flex flex-col space-y-2 text-center sm:text-left", |
53 | | - className |
54 | | - )} |
55 | | - {...props} |
56 | | - /> |
57 | | -); |
58 | | -AlertDialogHeader.displayName = "AlertDialogHeader"; |
| 50 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Content>) { |
| 51 | + return ( |
| 52 | + <AlertDialogPortal> |
| 53 | + <AlertDialogOverlay /> |
| 54 | + <AlertDialogPrimitive.Content |
| 55 | + data-slot="alert-dialog-content" |
| 56 | + className={cn( |
| 57 | + "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", |
| 58 | + className |
| 59 | + )} |
| 60 | + {...props} |
| 61 | + /> |
| 62 | + </AlertDialogPortal> |
| 63 | + ); |
| 64 | +} |
59 | 65 |
|
60 | | -const AlertDialogFooter = ({ |
| 66 | +function AlertDialogHeader({ |
61 | 67 | className, |
62 | 68 | ...props |
63 | | -}: React.HTMLAttributes<HTMLDivElement>) => ( |
64 | | - <div |
65 | | - className={cn( |
66 | | - "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", |
67 | | - className |
68 | | - )} |
69 | | - {...props} |
70 | | - /> |
71 | | -); |
72 | | -AlertDialogFooter.displayName = "AlertDialogFooter"; |
| 69 | +}: React.ComponentProps<"div">) { |
| 70 | + return ( |
| 71 | + <div |
| 72 | + data-slot="alert-dialog-header" |
| 73 | + className={cn("flex flex-col gap-2 text-center sm:text-left", className)} |
| 74 | + {...props} |
| 75 | + /> |
| 76 | + ); |
| 77 | +} |
73 | 78 |
|
74 | | -const AlertDialogTitle = React.forwardRef< |
75 | | - React.ElementRef<typeof AlertDialogPrimitive.Title>, |
76 | | - React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title> |
77 | | ->(({ className, ...props }, ref) => ( |
78 | | - <AlertDialogPrimitive.Title |
79 | | - ref={ref} |
80 | | - className={cn("text-lg font-semibold", className)} |
81 | | - {...props} |
82 | | - /> |
83 | | -)); |
84 | | -AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName; |
| 79 | +function AlertDialogFooter({ |
| 80 | + className, |
| 81 | + ...props |
| 82 | +}: React.ComponentProps<"div">) { |
| 83 | + return ( |
| 84 | + <div |
| 85 | + data-slot="alert-dialog-footer" |
| 86 | + className={cn( |
| 87 | + "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", |
| 88 | + className |
| 89 | + )} |
| 90 | + {...props} |
| 91 | + /> |
| 92 | + ); |
| 93 | +} |
85 | 94 |
|
86 | | -const AlertDialogDescription = React.forwardRef< |
87 | | - React.ElementRef<typeof AlertDialogPrimitive.Description>, |
88 | | - React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description> |
89 | | ->(({ className, ...props }, ref) => ( |
90 | | - <AlertDialogPrimitive.Description |
91 | | - ref={ref} |
92 | | - className={cn("text-sm text-muted-foreground", className)} |
93 | | - {...props} |
94 | | - /> |
95 | | -)); |
96 | | -AlertDialogDescription.displayName = |
97 | | - AlertDialogPrimitive.Description.displayName; |
| 95 | +function AlertDialogTitle({ |
| 96 | + className, |
| 97 | + ...props |
| 98 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) { |
| 99 | + return ( |
| 100 | + <AlertDialogPrimitive.Title |
| 101 | + data-slot="alert-dialog-title" |
| 102 | + className={cn("text-lg font-semibold", className)} |
| 103 | + {...props} |
| 104 | + /> |
| 105 | + ); |
| 106 | +} |
98 | 107 |
|
99 | | -const AlertDialogAction = React.forwardRef< |
100 | | - React.ElementRef<typeof AlertDialogPrimitive.Action>, |
101 | | - React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action> |
102 | | ->(({ ...props }, ref) => <AlertDialogPrimitive.Action ref={ref} {...props} />); |
103 | | -AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName; |
| 108 | +function AlertDialogDescription({ |
| 109 | + className, |
| 110 | + ...props |
| 111 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) { |
| 112 | + return ( |
| 113 | + <AlertDialogPrimitive.Description |
| 114 | + data-slot="alert-dialog-description" |
| 115 | + className={cn("text-muted-foreground text-sm", className)} |
| 116 | + {...props} |
| 117 | + /> |
| 118 | + ); |
| 119 | +} |
104 | 120 |
|
105 | | -const AlertDialogCancel = React.forwardRef< |
106 | | - React.ElementRef<typeof AlertDialogPrimitive.Cancel>, |
107 | | - React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel> |
108 | | ->(({ className, ...props }, ref) => ( |
109 | | - <AlertDialogPrimitive.Cancel |
110 | | - ref={ref} |
111 | | - className={cn( |
112 | | - buttonVariants({ variant: "outline" }), |
113 | | - "mt-2 sm:mt-0", |
114 | | - className |
115 | | - )} |
116 | | - {...props} |
117 | | - /> |
118 | | -)); |
119 | | -AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName; |
| 121 | +function AlertDialogAction({ |
| 122 | + className, |
| 123 | + ...props |
| 124 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Action>) { |
| 125 | + return <AlertDialogPrimitive.Action className={className} {...props} />; |
| 126 | +} |
| 127 | + |
| 128 | +function AlertDialogCancel({ |
| 129 | + className, |
| 130 | + ...props |
| 131 | +}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) { |
| 132 | + return ( |
| 133 | + <AlertDialogPrimitive.Cancel |
| 134 | + className={cn(buttonVariants({ variant: "outline" }), className)} |
| 135 | + {...props} |
| 136 | + /> |
| 137 | + ); |
| 138 | +} |
120 | 139 |
|
121 | 140 | export { |
122 | 141 | AlertDialog, |
|
0 commit comments