A drawer component in neobrutalism style.
1"use client"
2
3import { Drawer as DrawerPrimitive } from "vaul"
4
5import * as React from "react"
6
7import { cn } from "@/lib/utils"
8
9function Drawer({
10 shouldScaleBackground = true,
11 ...props
12}: React.ComponentProps<typeof DrawerPrimitive.Root>) {
13 return (
14 <DrawerPrimitive.Root
15 data-slot="drawer"
16 shouldScaleBackground={shouldScaleBackground}
17 {...props}
18 />
19 )
20}
21
22function DrawerTrigger({
23 ...props
24}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
25 return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />
26}
27
28function DrawerPortal({
29 ...props
30}: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
31 return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} />
32}
33
34function DrawerClose({
35 ...props
36}: React.ComponentProps<typeof DrawerPrimitive.Close>) {
37 return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />
38}
39
40function DrawerOverlay({
41 className,
42 ...props
43}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
44 return (
45 <DrawerPrimitive.Overlay
46 data-slot="drawer-overlay"
47 className={cn(
48 "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-overlay",
49 className,
50 )}
51 {...props}
52 />
53 )
54}
55
56function DrawerContent({
57 className,
58 children,
59 ...props
60}: React.ComponentProps<typeof DrawerPrimitive.Content>) {
61 return (
62 <DrawerPortal>
63 <DrawerOverlay />
64 <DrawerPrimitive.Content
65 data-slot="drawer-content"
66 className={cn(
67 "bg-background group/drawer-content fixed z-50 flex h-auto flex-col",
68 "data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-base border-t-2 border-t-border",
69 "data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-base border-b-2 border-b-border",
70 "data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:sm:max-w-sm border-r-2 border-r-border",
71 "data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:sm:max-w-sm border-l-2 border-l-border",
72 className,
73 )}
74 {...props}
75 >
76 <div className="mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block bg-current" />
77 {children}
78 </DrawerPrimitive.Content>
79 </DrawerPortal>
80 )
81}
82
83function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) {
84 return (
85 <div
86 data-slot="drawer-header"
87 className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
88 {...props}
89 />
90 )
91}
92
93function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) {
94 return (
95 <div
96 data-slot="drawer-footer"
97 className={cn("mt-auto flex flex-col gap-3 p-4", className)}
98 {...props}
99 />
100 )
101}
102
103function DrawerTitle({
104 className,
105 ...props
106}: React.ComponentProps<typeof DrawerPrimitive.Title>) {
107 return (
108 <DrawerPrimitive.Title
109 data-slot="drawer-title"
110 className={cn(
111 "text-lg font-heading leading-none tracking-tight",
112 className,
113 )}
114 {...props}
115 />
116 )
117}
118
119function DrawerDescription({
120 className,
121 ...props
122}: React.ComponentProps<typeof DrawerPrimitive.Description>) {
123 return (
124 <DrawerPrimitive.Description
125 data-slot="drawer-description"
126 className={cn("text-sm font-base text-foreground", className)}
127 {...props}
128 />
129 )
130}
131
132export {
133 Drawer,
134 DrawerPortal,
135 DrawerOverlay,
136 DrawerTrigger,
137 DrawerClose,
138 DrawerContent,
139 DrawerHeader,
140 DrawerFooter,
141 DrawerTitle,
142 DrawerDescription,
143}
144