Open History to see the last commit
1"use client";
2
3import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog";
4
5import { cn } from "~/lib/utils";
6
7const AlertDialogCreateHandle = AlertDialogPrimitive.createHandle;
8
9const AlertDialog = AlertDialogPrimitive.Root;
10
11const AlertDialogPortal = AlertDialogPrimitive.Portal;
12
13function AlertDialogTrigger(props: AlertDialogPrimitive.Trigger.Props) {
14 return <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />;
15}
16
17function AlertDialogBackdrop({ className, ...props }: AlertDialogPrimitive.Backdrop.Props) {
18 return (
19 <AlertDialogPrimitive.Backdrop
20 className={cn(
21 "fixed inset-0 z-50 bg-black/32 backdrop-blur-sm transition-all duration-200 ease-out data-ending-style:opacity-0 data-starting-style:opacity-0",
22 className,
23 )}
24 data-slot="alert-dialog-backdrop"
25 {...props}
26 />
27 );
28}
29
30function AlertDialogViewport({ className, ...props }: AlertDialogPrimitive.Viewport.Props) {
31 return (
32 <AlertDialogPrimitive.Viewport
33 className={cn(
34 "fixed inset-0 z-50 grid grid-rows-[1fr_auto_3fr] justify-items-center p-4",
35 className,
36 )}
37 data-slot="alert-dialog-viewport"
38 {...props}
39 />
40 );
41}
42
43function AlertDialogPopup({
44 className,
45 bottomStickOnMobile = true,
46 ...props
47}: AlertDialogPrimitive.Popup.Props & {
48 bottomStickOnMobile?: boolean;
49}) {
50 return (
51 <AlertDialogPortal>
52 <AlertDialogBackdrop />
53 <AlertDialogViewport
54 className={cn(bottomStickOnMobile && "max-sm:grid-rows-[1fr_auto] max-sm:p-0 max-sm:pt-12")}
55 >
56 <AlertDialogPrimitive.Popup
57 className={cn(
58 "-translate-y-[calc(1.25rem*var(--nested-dialogs))] relative row-start-2 flex max-h-full min-h-0 w-full min-w-0 max-w-lg scale-[calc(1-0.1*var(--nested-dialogs))] flex-col rounded-2xl border bg-popover not-dark:bg-clip-padding text-popover-foreground opacity-[calc(1-0.1*var(--nested-dialogs))] shadow-lg/5 transition-[scale,opacity,translate] duration-200 ease-in-out will-change-transform before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] data-nested:data-ending-style:translate-y-8 data-nested:data-starting-style:translate-y-8 data-nested-dialog-open:origin-top data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
59 bottomStickOnMobile &&
60 "max-sm:max-w-none max-sm:rounded-none max-sm:border-x-0 max-sm:border-t max-sm:border-b-0 max-sm:opacity-[calc(1-min(var(--nested-dialogs),1))] max-sm:data-ending-style:translate-y-4 max-sm:data-starting-style:translate-y-4 max-sm:before:hidden max-sm:before:rounded-none",
61 className,
62 )}
63 data-slot="alert-dialog-popup"
64 {...props}
65 />
66 </AlertDialogViewport>
67 </AlertDialogPortal>
68 );
69}
70
71function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">) {
72 return (
73 <div
74 className={cn("flex flex-col gap-2 p-6 text-center max-sm:pb-4 sm:text-left", className)}
75 data-slot="alert-dialog-header"
76 {...props}
77 />
78 );
79}
80
81function AlertDialogFooter({
82 className,
83 variant = "default",
84 ...props
85}: React.ComponentProps<"div"> & {
86 variant?: "default" | "bare";
87}) {
88 return (
89 <div
90 className={cn(
91 "flex flex-col-reverse gap-2 px-6 sm:flex-row sm:justify-end sm:rounded-b-[calc(var(--radius-2xl)-1px)]",
92 variant === "default" && "border-t bg-muted/72 py-4",
93 variant === "bare" && "pb-6",
94 className,
95 )}
96 data-slot="alert-dialog-footer"
97 {...props}
98 />
99 );
100}
101
102function AlertDialogTitle({ className, ...props }: AlertDialogPrimitive.Title.Props) {
103 return (
104 <AlertDialogPrimitive.Title
105 className={cn("font-heading font-semibold text-xl leading-none", className)}
106 data-slot="alert-dialog-title"
107 {...props}
108 />
109 );
110}
111
112function AlertDialogDescription({ className, ...props }: AlertDialogPrimitive.Description.Props) {
113 return (
114 <AlertDialogPrimitive.Description
115 className={cn("text-muted-foreground text-sm", className)}
116 data-slot="alert-dialog-description"
117 {...props}
118 />
119 );
120}
121
122function AlertDialogClose(props: AlertDialogPrimitive.Close.Props) {
123 return <AlertDialogPrimitive.Close data-slot="alert-dialog-close" {...props} />;
124}
125
126export {
127 AlertDialogCreateHandle,
128 AlertDialog,
129 AlertDialogPortal,
130 AlertDialogBackdrop,
131 AlertDialogBackdrop as AlertDialogOverlay,
132 AlertDialogTrigger,
133 AlertDialogPopup,
134 AlertDialogPopup as AlertDialogContent,
135 AlertDialogHeader,
136 AlertDialogFooter,
137 AlertDialogTitle,
138 AlertDialogDescription,
139 AlertDialogClose,
140 AlertDialogViewport,
141};