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

alert-dialog.tsx

146 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 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 portalContainer,
50 ...props
51}: AlertDialogPrimitive.Popup.Props & {
52 bottomStickOnMobile?: boolean;
53 portalContainer?: AlertDialogPrimitive.Portal.Props["container"];
54}) {
55 return (
56 <AlertDialogPortal container={portalContainer}>
57 <AlertDialogBackdrop />
58 <AlertDialogViewport
59 className={cn(bottomStickOnMobile && "max-sm:grid-rows-[1fr_auto] max-sm:p-0 max-sm:pt-12")}
60 >
61 <AlertDialogPrimitive.Popup
62 className={cn(
63 DIALOG_POPUP_CLASS,
64 "row-start-2 max-h-full max-w-lg text-popover-foreground",
65 bottomStickOnMobile && DIALOG_MOBILE_SHEET_CLASS,
66 className,
67 )}
68 data-slot="alert-dialog-popup"
69 {...props}
70 />
71 </AlertDialogViewport>
72 </AlertDialogPortal>
73 );
75​
76function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">) {
77 return (
78 <div
79 className={cn("flex flex-col gap-2 p-6 text-center max-sm:pb-4 sm:text-left", className)}
80 data-slot="alert-dialog-header"
81 {...props}
82 />
83 );
85​
86function AlertDialogFooter({
87 className,
88 variant = "default",
89 ...props
90}: React.ComponentProps<"div"> & {
91 variant?: "default" | "bare";
92}) {
93 return (
94 <div
95 className={cn(
96 "flex flex-col-reverse gap-2 px-6 sm:flex-row sm:justify-end sm:rounded-b-[calc(var(--radius-2xl)-1px)]",
97 variant === "default" && "border-t bg-muted/72 py-4",
98 variant === "bare" && "pb-6",
99 className,
100 )}
101 data-slot="alert-dialog-footer"
102 {...props}
103 />
104 );
106​
107function AlertDialogTitle({ className, ...props }: AlertDialogPrimitive.Title.Props) {
108 return (
109 <AlertDialogPrimitive.Title
110 className={cn("font-heading font-semibold text-xl leading-none", className)}
111 data-slot="alert-dialog-title"
112 {...props}
113 />
114 );
116​
117function AlertDialogDescription({ className, ...props }: AlertDialogPrimitive.Description.Props) {
118 return (
119 <AlertDialogPrimitive.Description
120 className={cn("text-muted-foreground text-sm", className)}
121 data-slot="alert-dialog-description"
122 {...props}
123 />
124 );
126​
127function AlertDialogClose(props: AlertDialogPrimitive.Close.Props) {
128 return <AlertDialogPrimitive.Close data-slot="alert-dialog-close" {...props} />;
130​
131export {
132 AlertDialogCreateHandle,
133 AlertDialog,
134 AlertDialogPortal,
135 AlertDialogBackdrop,
136 AlertDialogBackdrop as AlertDialogOverlay,
137 AlertDialogTrigger,
138 AlertDialogPopup,
139 AlertDialogPopup as AlertDialogContent,
140 AlertDialogHeader,
141 AlertDialogFooter,
142 AlertDialogTitle,
143 AlertDialogDescription,
144 AlertDialogClose,
145 AlertDialogViewport,
146};