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

alert-dialog.tsx

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