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