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

alert-dialog.tsx

142 lines4.7 KB

1"use client";
2​
3import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog";
4​
5import { cn } from "~/lib/utils";
6​
7const AlertDialogCreateHandle = AlertDialogPrimitive.createHandle;
8​
9const AlertDialog = AlertDialogPrimitive.Root;
10​
11const AlertDialogPortal = AlertDialogPrimitive.Portal;
12​
13function AlertDialogTrigger(props: AlertDialogPrimitive.Trigger.Props) {
14 return <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />;
16​
17function AlertDialogBackdrop({ className, ...props }: AlertDialogPrimitive.Backdrop.Props) {
18 return (
19 <AlertDialogPrimitive.Backdrop
20 forceRender
21 className={cn(
22 "fixed inset-0 z-50 bg-background/60 backdrop-blur-xs transition-all duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0",
23 className,
24 )}
25 data-slot="alert-dialog-backdrop"
26 {...props}
27 />
28 );
30​
31function AlertDialogViewport({ className, ...props }: AlertDialogPrimitive.Viewport.Props) {
32 return (
33 <AlertDialogPrimitive.Viewport
34 className={cn(
35 "fixed inset-0 z-50 grid grid-rows-[1fr_auto_1fr] justify-items-center p-4",
36 className,
37 )}
38 data-slot="alert-dialog-viewport"
39 {...props}
40 />
41 );
43​
44function AlertDialogPopup({
45 className,
46 bottomStickOnMobile = true,
47 ...props
48}: AlertDialogPrimitive.Popup.Props & {
49 bottomStickOnMobile?: boolean;
50}) {
51 return (
52 <AlertDialogPortal>
53 <AlertDialogBackdrop />
54 <AlertDialogViewport
55 className={cn(bottomStickOnMobile && "max-sm:grid-rows-[1fr_auto] max-sm:p-0 max-sm:pt-12")}
56 >
57 <AlertDialogPrimitive.Popup
58 className={cn(
59 "-translate-y-[calc(1.25rem*var(--nested-dialogs))] relative row-start-2 flex max-h-full min-h-0 w-full min-w-0 max-w-lg scale-[calc(1-0.1*var(--nested-dialogs))] flex-col rounded-2xl border bg-popover not-dark:bg-clip-padding text-popover-foreground opacity-[calc(1-0.1*var(--nested-dialogs))] shadow-lg/5 transition-[scale,opacity,translate] duration-200 ease-in-out will-change-transform before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] data-nested:data-ending-style:translate-y-8 data-nested:data-starting-style:translate-y-8 data-nested-dialog-open:origin-top data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
60 bottomStickOnMobile &&
61 "max-sm:max-w-none max-sm:rounded-none max-sm:border-x-0 max-sm:border-t max-sm:border-b-0 max-sm:opacity-[calc(1-min(var(--nested-dialogs),1))] max-sm:data-ending-style:translate-y-4 max-sm:data-starting-style:translate-y-4 max-sm:before:hidden max-sm:before:rounded-none",
62 className,
63 )}
64 data-slot="alert-dialog-popup"
65 {...props}
66 />
67 </AlertDialogViewport>
68 </AlertDialogPortal>
69 );
71​
72function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">) {
73 return (
74 <div
75 className={cn("flex flex-col gap-2 p-6 text-center max-sm:pb-4 sm:text-left", className)}
76 data-slot="alert-dialog-header"
77 {...props}
78 />
79 );
81​
82function AlertDialogFooter({
83 className,
84 variant = "default",
85 ...props
86}: React.ComponentProps<"div"> & {
87 variant?: "default" | "bare";
88}) {
89 return (
90 <div
91 className={cn(
92 "flex flex-col-reverse gap-2 px-6 sm:flex-row sm:justify-end sm:rounded-b-[calc(var(--radius-2xl)-1px)]",
93 variant === "default" && "border-t bg-muted/72 py-4",
94 variant === "bare" && "pb-6",
95 className,
96 )}
97 data-slot="alert-dialog-footer"
98 {...props}
99 />
100 );
102​
103function AlertDialogTitle({ className, ...props }: AlertDialogPrimitive.Title.Props) {
104 return (
105 <AlertDialogPrimitive.Title
106 className={cn("font-heading font-semibold text-xl leading-none", className)}
107 data-slot="alert-dialog-title"
108 {...props}
109 />
110 );
112​
113function AlertDialogDescription({ className, ...props }: AlertDialogPrimitive.Description.Props) {
114 return (
115 <AlertDialogPrimitive.Description
116 className={cn("text-muted-foreground text-sm", className)}
117 data-slot="alert-dialog-description"
118 {...props}
119 />
120 );
122​
123function AlertDialogClose(props: AlertDialogPrimitive.Close.Props) {
124 return <AlertDialogPrimitive.Close data-slot="alert-dialog-close" {...props} />;
126​
127export {
128 AlertDialogCreateHandle,
129 AlertDialog,
130 AlertDialogPortal,
131 AlertDialogBackdrop,
132 AlertDialogBackdrop as AlertDialogOverlay,
133 AlertDialogTrigger,
134 AlertDialogPopup,
135 AlertDialogPopup as AlertDialogContent,
136 AlertDialogHeader,
137 AlertDialogFooter,
138 AlertDialogTitle,
139 AlertDialogDescription,
140 AlertDialogClose,
141 AlertDialogViewport,
142};