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