Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

alert-dialog.tsx

147 lines3.9 KB

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 );
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 );
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 );
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 );
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 );
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 );
113​
114function AlertDialogDescription({ className, ...props }: AlertDialogPrimitive.Description.Props) {
115 return (
116 <AlertDialogPrimitive.Description
117 className={cn(
118 // A long description (say, the arguments of a tool call awaiting
119 // approval) scrolls in place instead of pushing the actions out of
120 // the popup, which the viewport already caps.
121 "wrap-anywhere max-h-[min(24rem,60dvh)] min-h-0 overflow-y-auto overscroll-contain text-muted-foreground text-sm select-text",
122 className,
123 )}
124 data-slot="alert-dialog-description"
125 {...props}
126 />
127 );
129​
130function AlertDialogClose(props: AlertDialogPrimitive.Close.Props) {
131 return <AlertDialogPrimitive.Close data-slot="alert-dialog-close" {...props} />;
133​
134export {
135 AlertDialog,
136 AlertDialogPortal,
137 AlertDialogBackdrop,
138 AlertDialogBackdrop as AlertDialogOverlay,
139 AlertDialogPopup,
140 AlertDialogPopup as AlertDialogContent,
141 AlertDialogHeader,
142 AlertDialogFooter,
143 AlertDialogTitle,
144 AlertDialogDescription,
145 AlertDialogClose,
146 AlertDialogViewport,
147};