|
| 1 | +"use client" |
| 2 | + |
| 3 | +import * as React from "react" |
| 4 | +import { Drawer as DrawerPrimitive } from "vaul" |
| 5 | + |
| 6 | +import { cn } from "@/lib/utils" |
| 7 | + |
| 8 | +function Drawer({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>) { |
| 9 | + return <DrawerPrimitive.Root data-slot="drawer" {...props} /> |
| 10 | +} |
| 11 | + |
| 12 | +function DrawerTrigger({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Trigger>) { |
| 13 | + return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} /> |
| 14 | +} |
| 15 | + |
| 16 | +function DrawerPortal({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Portal>) { |
| 17 | + return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} /> |
| 18 | +} |
| 19 | + |
| 20 | +function DrawerClose({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Close>) { |
| 21 | + return <DrawerPrimitive.Close data-slot="drawer-close" {...props} /> |
| 22 | +} |
| 23 | + |
| 24 | +function DrawerOverlay({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Overlay>) { |
| 25 | + return ( |
| 26 | + <DrawerPrimitive.Overlay |
| 27 | + data-slot="drawer-overlay" |
| 28 | + className={cn( |
| 29 | + "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-black/50", |
| 30 | + className, |
| 31 | + )} |
| 32 | + {...props} |
| 33 | + /> |
| 34 | + ) |
| 35 | +} |
| 36 | + |
| 37 | +function DrawerContent({ className, children, ...props }: React.ComponentProps<typeof DrawerPrimitive.Content>) { |
| 38 | + return ( |
| 39 | + <DrawerPortal data-slot="drawer-portal"> |
| 40 | + <DrawerOverlay /> |
| 41 | + <DrawerPrimitive.Content |
| 42 | + data-slot="drawer-content" |
| 43 | + className={cn( |
| 44 | + "group/drawer-content bg-background fixed z-50 flex h-auto flex-col", |
| 45 | + "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-sm data-[vaul-drawer-direction=top]:border-b", |
| 46 | + "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-sm data-[vaul-drawer-direction=bottom]:border-t", |
| 47 | + "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]:border-l data-[vaul-drawer-direction=right]:sm:max-w-sm", |
| 48 | + "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]:border-r data-[vaul-drawer-direction=left]:sm:max-w-sm", |
| 49 | + className, |
| 50 | + )} |
| 51 | + {...props}> |
| 52 | + <div className="bg-muted mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block" /> |
| 53 | + {children} |
| 54 | + </DrawerPrimitive.Content> |
| 55 | + </DrawerPortal> |
| 56 | + ) |
| 57 | +} |
| 58 | + |
| 59 | +function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) { |
| 60 | + return <div data-slot="drawer-header" className={cn("flex flex-col gap-1.5 py-4", className)} {...props} /> |
| 61 | +} |
| 62 | + |
| 63 | +function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) { |
| 64 | + return <div data-slot="drawer-footer" className={cn("mt-auto flex flex-col gap-2 py-4", className)} {...props} /> |
| 65 | +} |
| 66 | + |
| 67 | +function DrawerTitle({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Title>) { |
| 68 | + return ( |
| 69 | + <DrawerPrimitive.Title |
| 70 | + data-slot="drawer-title" |
| 71 | + className={cn("text-foreground font-semibold", className)} |
| 72 | + {...props} |
| 73 | + /> |
| 74 | + ) |
| 75 | +} |
| 76 | + |
| 77 | +function DrawerDescription({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Description>) { |
| 78 | + return ( |
| 79 | + <DrawerPrimitive.Description |
| 80 | + data-slot="drawer-description" |
| 81 | + className={cn("text-muted-foreground text-sm", className)} |
| 82 | + {...props} |
| 83 | + /> |
| 84 | + ) |
| 85 | +} |
| 86 | + |
| 87 | +export { |
| 88 | + Drawer, |
| 89 | + DrawerPortal, |
| 90 | + DrawerOverlay, |
| 91 | + DrawerTrigger, |
| 92 | + DrawerClose, |
| 93 | + DrawerContent, |
| 94 | + DrawerHeader, |
| 95 | + DrawerFooter, |
| 96 | + DrawerTitle, |
| 97 | + DrawerDescription, |
| 98 | +} |
0 commit comments