xonecas.io
556
Bn

bees-nest / files

bees-nest / src / components / ui / alert-dialog.tsx

5.5 KB
1"use client";
2
3import { AlertDialog as AlertDialogPrimitive } from "radix-ui";
4import type * as React from "react";
5import { Button } from "@/components/ui/button";
6import { cn } from "@/lib/utils";
7
8function AlertDialog({
9  ...props
10}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
11  return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
12}
13
14function AlertDialogTrigger({
15  ...props
16}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
17  return (
18    <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
19  );
20}
21
22function AlertDialogPortal({
23  ...props
24}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
25  return (
26    <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
27  );
28}
29
30function AlertDialogOverlay({
31  className,
32  ...props
33}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
34  return (
35    <AlertDialogPrimitive.Overlay
36      data-slot="alert-dialog-overlay"
37      className={cn(
38        "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/80 duration-100 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 z-50",
39        className,
40      )}
41      {...props}
42    />
43  );
44}
45
46function AlertDialogContent({
47  className,
48  size = "default",
49  ...props
50}: React.ComponentProps<typeof AlertDialogPrimitive.Content> & {
51  size?: "default" | "sm";
52}) {
53  return (
54    <AlertDialogPortal>
55      <AlertDialogOverlay />
56      <AlertDialogPrimitive.Content
57        data-slot="alert-dialog-content"
58        data-size={size}
59        className={cn(
60          "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-background ring-foreground/5 gap-6 rounded-4xl p-6 ring-1 duration-100 data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-md group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 outline-none",
61          className,
62        )}
63        {...props}
64      />
65    </AlertDialogPortal>
66  );
67}
68
69function AlertDialogHeader({
70  className,
71  ...props
72}: React.ComponentProps<"div">) {
73  return (
74    <div
75      data-slot="alert-dialog-header"
76      className={cn(
77        "grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
78        className,
79      )}
80      {...props}
81    />
82  );
83}
84
85function AlertDialogFooter({
86  className,
87  ...props
88}: React.ComponentProps<"div">) {
89  return (
90    <div
91      data-slot="alert-dialog-footer"
92      className={cn(
93        "flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
94        className,
95      )}
96      {...props}
97    />
98  );
99}
100
101function AlertDialogMedia({
102  className,
103  ...props
104}: React.ComponentProps<"div">) {
105  return (
106    <div
107      data-slot="alert-dialog-media"
108      className={cn(
109        "bg-muted mb-2 inline-flex size-16 items-center justify-center rounded-full sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-8",
110        className,
111      )}
112      {...props}
113    />
114  );
115}
116
117function AlertDialogTitle({
118  className,
119  ...props
120}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
121  return (
122    <AlertDialogPrimitive.Title
123      data-slot="alert-dialog-title"
124      className={cn(
125        "text-lg font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
126        className,
127      )}
128      {...props}
129    />
130  );
131}
132
133function AlertDialogDescription({
134  className,
135  ...props
136}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
137  return (
138    <AlertDialogPrimitive.Description
139      data-slot="alert-dialog-description"
140      className={cn(
141        "text-muted-foreground *:[a]:hover:text-foreground text-sm text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3",
142        className,
143      )}
144      {...props}
145    />
146  );
147}
148
149function AlertDialogAction({
150  className,
151  variant = "default",
152  size = "default",
153  ...props
154}: React.ComponentProps<typeof AlertDialogPrimitive.Action> &
155  Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
156  return (
157    <Button variant={variant} size={size} asChild>
158      <AlertDialogPrimitive.Action
159        data-slot="alert-dialog-action"
160        className={cn(className)}
161        {...props}
162      />
163    </Button>
164  );
165}
166
167function AlertDialogCancel({
168  className,
169  variant = "outline",
170  size = "default",
171  ...props
172}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> &
173  Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
174  return (
175    <Button variant={variant} size={size} asChild>
176      <AlertDialogPrimitive.Cancel
177        data-slot="alert-dialog-cancel"
178        className={cn(className)}
179        {...props}
180      />
181    </Button>
182  );
183}
184
185export {
186  AlertDialog,
187  AlertDialogAction,
188  AlertDialogCancel,
189  AlertDialogContent,
190  AlertDialogDescription,
191  AlertDialogFooter,
192  AlertDialogHeader,
193  AlertDialogMedia,
194  AlertDialogOverlay,
195  AlertDialogPortal,
196  AlertDialogTitle,
197  AlertDialogTrigger,
198};