Open History to see the last commit
1"use client";
2
3import { Dialog as SheetPrimitive } from "@base-ui/react/dialog";
4import { XIcon } from "lucide-react";
5import type { CSSProperties } from "react";
6import { cn } from "~/lib/utils";
7import { Button } from "~/components/ui/button";
8
9const Sheet = SheetPrimitive.Root;
10
11const SheetPortal = SheetPrimitive.Portal;
12
13function SheetBackdrop({ className, ...props }: SheetPrimitive.Backdrop.Props) {
14 return (
15 <SheetPrimitive.Backdrop
16 className={cn(
17 "fixed inset-0 z-(--z-sheet) bg-background/60 backdrop-blur-xs transition-all duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0",
18 className,
19 )}
20 data-slot="sheet-backdrop"
21 {...props}
22 />
23 );
24}
25
26function SheetViewport({
27 className,
28 side,
29 variant = "default",
30 ...props
31}: SheetPrimitive.Viewport.Props & {
32 side?: "right" | "left" | "top" | "bottom";
33 variant?: "default" | "inset";
34}) {
35 return (
36 <SheetPrimitive.Viewport
37 className={cn(
38 "fixed inset-0 z-(--z-sheet) grid",
39 side === "bottom" && "grid grid-rows-[1fr_auto] pt-12",
40 side === "top" && "grid grid-rows-[auto_1fr] pb-12",
41 side === "left" && "flex justify-start",
42 side === "right" && "flex justify-end",
43 variant === "inset" && "sm:p-4",
44 className,
45 )}
46 data-slot="sheet-viewport"
47 {...props}
48 />
49 );
50}
51
52function SheetPopup({
53 className,
54 children,
55 showCloseButton = true,
56 keepMounted = false,
57 transitionDurationMs,
58 side = "right",
59 variant = "default",
60 style,
61 ...props
62}: SheetPrimitive.Popup.Props & {
63 showCloseButton?: boolean;
64 keepMounted?: boolean;
65 transitionDurationMs?: number;
66 side?: "right" | "left" | "top" | "bottom";
67 variant?: "default" | "inset";
68}) {
69 const transitionStyle =
70 transitionDurationMs === undefined
71 ? undefined
72 : ({ transitionDuration: `${transitionDurationMs}ms` } satisfies CSSProperties);
73 const instant = transitionDurationMs === 0;
74
75 return (
76 <SheetPortal keepMounted={keepMounted}>
77 <SheetBackdrop
78 className={
79 instant
80 ? "transition-none! data-ending-style:opacity-100! data-starting-style:opacity-100!"
81 : undefined
82 }
83 style={transitionStyle}
84 />
85 <SheetViewport side={side} variant={variant}>
86 <SheetPrimitive.Popup
87 className={cn(
88 "relative flex max-h-full min-h-0 w-full min-w-0 flex-col bg-popover not-dark:bg-clip-padding text-popover-foreground shadow-lg/5 transition-[opacity,translate] duration-200 ease-in-out will-change-transform before:pointer-events-none before:absolute before:inset-0 before:shadow-[0_1px_--theme(--color-black/4%)] data-ending-style:opacity-0 data-starting-style:opacity-0 max-sm:before:hidden dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
89 side === "bottom" &&
90 "row-start-2 border-t data-ending-style:translate-y-8 data-starting-style:translate-y-8",
91 side === "top" &&
92 "data-ending-style:-translate-y-8 data-starting-style:-translate-y-8 border-b",
93 side === "left" &&
94 "data-ending-style:-translate-x-8 data-starting-style:-translate-x-8 w-[calc(100%-(--spacing(12)))] max-w-md border-e",
95 side === "right" &&
96 "col-start-2 w-[calc(100%-(--spacing(12)))] max-w-md border-s data-ending-style:translate-x-8 data-starting-style:translate-x-8",
97 variant === "inset" &&
98 "before:hidden sm:rounded-2xl sm:border sm:before:rounded-[calc(var(--radius-2xl)-1px)] sm:**:data-[slot=sheet-footer]:rounded-b-[calc(var(--radius-2xl)-1px)]",
99 instant &&
100 "transition-none! will-change-auto! data-ending-style:translate-x-0! data-starting-style:translate-x-0! data-ending-style:translate-y-0! data-starting-style:translate-y-0! data-ending-style:opacity-100! data-starting-style:opacity-100!",
101 className,
102 )}
103 data-slot="sheet-popup"
104 style={{ ...transitionStyle, ...style }}
105 {...props}
106 >
107 {children}
108 {showCloseButton && (
109 <SheetPrimitive.Close
110 aria-label="Close"
111 className="absolute end-2 top-2"
112 render={<Button size="icon" variant="ghost" />}
113 >
114 <XIcon />
115 </SheetPrimitive.Close>
116 )}
117 </SheetPrimitive.Popup>
118 </SheetViewport>
119 </SheetPortal>
120 );
121}
122
123function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
124 return (
125 <div
126 className={cn(
127 "flex flex-col gap-2 p-6 in-[[data-slot=sheet-popup]:has([data-slot=sheet-panel])]:pb-3 max-sm:pb-4",
128 className,
129 )}
130 data-slot="sheet-header"
131 {...props}
132 />
133 );
134}
135
136function SheetTitle({ className, ...props }: SheetPrimitive.Title.Props) {
137 return (
138 <SheetPrimitive.Title
139 className={cn("font-semibold text-xl leading-none", className)}
140 data-slot="sheet-title"
141 {...props}
142 />
143 );
144}
145
146function SheetDescription({ className, ...props }: SheetPrimitive.Description.Props) {
147 return (
148 <SheetPrimitive.Description
149 className={cn("text-muted-foreground text-sm", className)}
150 data-slot="sheet-description"
151 {...props}
152 />
153 );
154}
155
156export {
157 Sheet,
158 SheetPortal,
159 SheetBackdrop,
160 SheetBackdrop as SheetOverlay,
161 SheetPopup,
162 SheetPopup as SheetContent,
163 SheetHeader,
164 SheetTitle,
165 SheetDescription,
166};