-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsheet.tsx
94 lines (85 loc) · 3.44 KB
/
sheet.tsx
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
import * as SheetPrimitive from "@radix-ui/react-dialog";
import { cva } from "class-variance-authority";
import { XIcon } from "lucide-react";
import type { ComponentProps, HTMLAttributes } from "react";
import { cn } from "./cn";
const Sheet = SheetPrimitive.Root;
const SheetTrigger = SheetPrimitive.Trigger;
const SheetClose = SheetPrimitive.Close;
const SheetPortal = SheetPrimitive.Portal;
const sheetVariants = cva(
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=open]:animate-in data-[state=closed]:duration-300 data-[state=open]:duration-500",
{
variants: {
side: {
top: "data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 border-b",
bottom:
"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 border-t",
left: "data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
right:
"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
},
},
defaultVariants: {
side: "right",
},
},
);
function SheetOverlay({ className, ...rest }: ComponentProps<typeof SheetPrimitive.Overlay>) {
return (
<SheetPrimitive.Overlay
className={cn(
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80 data-[state=closed]:animate-out data-[state=open]:animate-in",
className,
)}
{...rest}
/>
);
}
function SheetContent({
side = "right",
className,
sheetOverlayClassName,
children,
...rest
}: ComponentProps<typeof SheetPrimitive.Content> & {
sheetOverlayClassName?: string;
side?: "top" | "bottom" | "left" | "right";
}) {
return (
<SheetPortal>
<SheetOverlay className={sheetOverlayClassName} />
<SheetPrimitive.Content className={cn(sheetVariants({ side }), className)} {...rest}>
<SheetPrimitive.Close className="absolute top-4 right-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<XIcon className="size-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
{children}
</SheetPrimitive.Content>
</SheetPortal>
);
}
function SheetHeader({ className, ...rest }: HTMLAttributes<HTMLDivElement>) {
return <div className={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...rest} />;
}
function SheetFooter({ className, ...rest }: HTMLAttributes<HTMLDivElement>) {
return <div className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...rest} />;
}
function SheetTitle({ className, ...rest }: ComponentProps<typeof SheetPrimitive.Title>) {
return <SheetPrimitive.Title className={cn("font-semibold text-foreground text-lg", className)} {...rest} />;
}
function SheetDescription({ className, ...rest }: ComponentProps<typeof SheetPrimitive.Description>) {
return <SheetPrimitive.Description className={cn("text-muted-foreground text-sm", className)} {...rest} />;
}
export {
Sheet,
SheetPortal,
SheetOverlay,
SheetTrigger,
SheetClose,
SheetContent,
SheetHeader,
SheetFooter,
SheetTitle,
SheetDescription,
};