Repository navigation
Expand file tree
/
Copy pathsheet.tsx
More file actions
172 lines (162 loc) · 5.65 KB
/
Copy pathsheet.tsx
File metadata and controls
172 lines (162 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { Dialog as SheetPrimitive } from "@base-ui/react/dialog";
import { XIcon } from "lucide-react";
import type { CSSProperties } from "react";
import { cn } from "~/lib/utils";
import { Button } from "~/components/ui/button";
import { ControlledOpenContext, renderRetainedPopup } from "~/components/ui/dialog";
function Sheet<Payload>(props: SheetPrimitive.Root.Props<Payload>) {
return (
<ControlledOpenContext value={props.open}>
<SheetPrimitive.Root {...props} />
</ControlledOpenContext>
);
}
const SheetPortal = SheetPrimitive.Portal;
function SheetBackdrop({ className, ...props }: SheetPrimitive.Backdrop.Props) {
return (
<SheetPrimitive.Backdrop
className={cn(
"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",
className,
)}
data-slot="sheet-backdrop"
{...props}
/>
);
}
function SheetViewport({
className,
side,
variant = "default",
...props
}: SheetPrimitive.Viewport.Props & {
side?: "right" | "left" | "top" | "bottom";
variant?: "default" | "inset";
}) {
return (
<SheetPrimitive.Viewport
className={cn(
"fixed inset-0 z-(--z-sheet) grid",
side === "bottom" && "grid grid-rows-[1fr_auto] pt-12",
side === "top" && "grid grid-rows-[auto_1fr] pb-12",
side === "left" && "flex justify-start",
side === "right" && "flex justify-end",
variant === "inset" && "sm:p-4",
className,
)}
data-slot="sheet-viewport"
{...props}
/>
);
}
function SheetPopup({
className,
children,
showCloseButton = true,
keepMounted = false,
transitionDurationMs,
side = "right",
variant = "default",
style,
...props
}: SheetPrimitive.Popup.Props & {
showCloseButton?: boolean;
keepMounted?: boolean;
transitionDurationMs?: number;
side?: "right" | "left" | "top" | "bottom";
variant?: "default" | "inset";
}) {
const transitionStyle =
transitionDurationMs === undefined
? undefined
: ({ transitionDuration: `${transitionDurationMs}ms` } satisfies CSSProperties);
const instant = transitionDurationMs === 0;
return (
<SheetPortal keepMounted={keepMounted}>
<SheetBackdrop
className={
instant
? "transition-none! data-ending-style:opacity-100! data-starting-style:opacity-100!"
: undefined
}
style={transitionStyle}
/>
<SheetViewport side={side} variant={variant}>
<SheetPrimitive.Popup
className={cn(
"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%)]",
side === "bottom" &&
"row-start-2 border-t data-ending-style:translate-y-8 data-starting-style:translate-y-8",
side === "top" &&
"data-ending-style:-translate-y-8 data-starting-style:-translate-y-8 border-b",
side === "left" &&
"data-ending-style:-translate-x-8 data-starting-style:-translate-x-8 w-[calc(100%-(--spacing(12)))] max-w-md border-e",
side === "right" &&
"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",
variant === "inset" &&
"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)]",
instant &&
"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!",
className,
)}
data-slot="sheet-popup"
render={keepMounted ? undefined : renderRetainedPopup}
style={{ ...transitionStyle, ...style }}
{...props}
>
{children}
{showCloseButton && (
<SheetPrimitive.Close
aria-label="Close"
className="absolute end-2 top-2"
render={<Button size="icon" variant="ghost" />}
>
<XIcon />
</SheetPrimitive.Close>
)}
</SheetPrimitive.Popup>
</SheetViewport>
</SheetPortal>
);
}
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
className={cn(
"flex flex-col gap-2 p-6 in-[[data-slot=sheet-popup]:has([data-slot=sheet-panel])]:pb-3 max-sm:pb-4",
className,
)}
data-slot="sheet-header"
{...props}
/>
);
}
function SheetTitle({ className, ...props }: SheetPrimitive.Title.Props) {
return (
<SheetPrimitive.Title
className={cn("font-semibold text-xl leading-none", className)}
data-slot="sheet-title"
{...props}
/>
);
}
function SheetDescription({ className, ...props }: SheetPrimitive.Description.Props) {
return (
<SheetPrimitive.Description
className={cn("text-muted-foreground text-sm", className)}
data-slot="sheet-description"
{...props}
/>
);
}
export {
Sheet,
SheetPortal,
SheetBackdrop,
SheetBackdrop as SheetOverlay,
SheetPopup,
SheetPopup as SheetContent,
SheetHeader,
SheetTitle,
SheetDescription,
};