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";
6import {
7 DIALOG_BACKDROP_CLASS,
8 DIALOG_MOBILE_SHEET_CLASS,
9 DIALOG_POPUP_CLASS,
10} from "~/components/ui/dialog-styles";
11
12const AlertDialog = AlertDialogPrimitive.Root;
13
14const AlertDialogPortal = AlertDialogPrimitive.Portal;
15
16function AlertDialogBackdrop({ className, ...props }: AlertDialogPrimitive.Backdrop.Props) {
17 return (
18 <AlertDialogPrimitive.Backdrop
19 forceRender
20 className={cn(DIALOG_BACKDROP_CLASS, className)}
21 data-slot="alert-dialog-backdrop"
22 {...props}
23 />
24 );
25}
26
27function AlertDialogViewport({ className, ...props }: AlertDialogPrimitive.Viewport.Props) {
28 return (
29 <AlertDialogPrimitive.Viewport
30 className={cn(
31 "fixed inset-0 z-50 grid grid-rows-[1fr_auto_1fr] justify-items-center p-4",
32 className,
33 )}
34 data-slot="alert-dialog-viewport"
35 {...props}
36 />
37 );
38}
39
40function AlertDialogPopup({
41 className,
42 bottomStickOnMobile = true,
43 portalContainer,
44 ...props
45}: AlertDialogPrimitive.Popup.Props & {
46 bottomStickOnMobile?: boolean;
47 portalContainer?: AlertDialogPrimitive.Portal.Props["container"];
48}) {
49 return (
50 <AlertDialogPortal container={portalContainer}>
51 <AlertDialogBackdrop />
52 <AlertDialogViewport
53 className={cn(bottomStickOnMobile && "max-sm:grid-rows-[1fr_auto] max-sm:p-0 max-sm:pt-12")}
54 >
55 <AlertDialogPrimitive.Popup
56 className={cn(
57 DIALOG_POPUP_CLASS,
58 "row-start-2 max-h-full max-w-lg text-popover-foreground",
59 bottomStickOnMobile && DIALOG_MOBILE_SHEET_CLASS,
60 className,
61 )}
62 data-slot="alert-dialog-popup"
63 {...props}
64 />
65 </AlertDialogViewport>
66 </AlertDialogPortal>
67 );
68}
69
70function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">) {
71 return (
72 <div
73 className={cn("flex flex-col gap-2 p-6 text-center max-sm:pb-4 sm:text-left", className)}
74 data-slot="alert-dialog-header"
75 {...props}
76 />
77 );
78}
79
80function AlertDialogFooter({
81 className,
82 variant = "default",
83 ...props
84}: React.ComponentProps<"div"> & {
85 variant?: "default" | "bare";
86}) {
87 return (
88 <div
89 className={cn(
90 "flex flex-col-reverse gap-2 px-6 sm:flex-row sm:justify-end sm:rounded-b-[calc(var(--radius-2xl)-1px)]",
91 variant === "default" && "border-t bg-muted/72 py-4",
92 variant === "bare" && "pb-6",
93 className,
94 )}
95 data-slot="alert-dialog-footer"
96 {...props}
97 />
98 );
99}
100
101function AlertDialogTitle({ className, ...props }: AlertDialogPrimitive.Title.Props) {
102 return (
103 <AlertDialogPrimitive.Title
104 className={cn("wrap-anywhere font-semibold text-xl leading-none", className)}
105 data-slot="alert-dialog-title"
106 {...props}
107 />
108 );
109}
110
111function AlertDialogDescription({ className, ...props }: AlertDialogPrimitive.Description.Props) {
112 return (
113 <AlertDialogPrimitive.Description
114 className={cn("text-muted-foreground text-sm", className)}
115 data-slot="alert-dialog-description"
116 {...props}
117 />
118 );
119}
120
121function AlertDialogClose(props: AlertDialogPrimitive.Close.Props) {
122 return <AlertDialogPrimitive.Close data-slot="alert-dialog-close" {...props} />;
123}
124
125export {
126 AlertDialog,
127 AlertDialogPortal,
128 AlertDialogBackdrop,
129 AlertDialogBackdrop as AlertDialogOverlay,
130 AlertDialogPopup,
131 AlertDialogPopup as AlertDialogContent,
132 AlertDialogHeader,
133 AlertDialogFooter,
134 AlertDialogTitle,
135 AlertDialogDescription,
136 AlertDialogClose,
137 AlertDialogViewport,
138};