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(
74 "flex min-h-0 flex-col gap-2 p-6 text-center max-sm:pb-4 sm:text-left",
75 className,
76 )}
77 data-slot="alert-dialog-header"
78 {...props}
79 />
80 );
81}
82
83function AlertDialogFooter({
84 className,
85 variant = "default",
86 ...props
87}: React.ComponentProps<"div"> & {
88 variant?: "default" | "bare";
89}) {
90 return (
91 <div
92 className={cn(
93 "flex flex-col-reverse gap-2 px-6 sm:flex-row sm:justify-end sm:rounded-b-[calc(var(--radius-2xl)-1px)]",
94 variant === "default" && "border-t bg-muted/72 py-4",
95 variant === "bare" && "pb-6",
96 className,
97 )}
98 data-slot="alert-dialog-footer"
99 {...props}
100 />
101 );
102}
103
104function AlertDialogTitle({ className, ...props }: AlertDialogPrimitive.Title.Props) {
105 return (
106 <AlertDialogPrimitive.Title
107 className={cn("wrap-anywhere shrink-0 font-semibold text-xl leading-none", className)}
108 data-slot="alert-dialog-title"
109 {...props}
110 />
111 );
112}
113
114function AlertDialogDescription({ className, ...props }: AlertDialogPrimitive.Description.Props) {
115 return (
116 <AlertDialogPrimitive.Description
117 className={cn(
118 "wrap-anywhere max-h-[min(24rem,60dvh)] min-h-0 overflow-y-auto overscroll-contain text-muted-foreground text-sm select-text",
119 className,
120 )}
121 data-slot="alert-dialog-description"
122 {...props}
123 />
124 );
125}
126
127function AlertDialogClose(props: AlertDialogPrimitive.Close.Props) {
128 return <AlertDialogPrimitive.Close data-slot="alert-dialog-close" {...props} />;
129}
130
131export {
132 AlertDialog,
133 AlertDialogPortal,
134 AlertDialogBackdrop,
135 AlertDialogBackdrop as AlertDialogOverlay,
136 AlertDialogPopup,
137 AlertDialogPopup as AlertDialogContent,
138 AlertDialogHeader,
139 AlertDialogFooter,
140 AlertDialogTitle,
141 AlertDialogDescription,
142 AlertDialogClose,
143 AlertDialogViewport,
144};