|
| 1 | +import * as React from "react" |
| 2 | +import { Drawer as DrawerPrimitive } from "vaul" |
| 3 | + |
| 4 | +import { cn } from "@/lib/utils" |
| 5 | + |
| 6 | +function Drawer({ |
| 7 | + ...props |
| 8 | +}: React.ComponentProps<typeof DrawerPrimitive.Root>) { |
| 9 | + return <DrawerPrimitive.Root data-slot="drawer" {...props} /> |
| 10 | +} |
| 11 | + |
| 12 | +function DrawerTrigger({ |
| 13 | + ...props |
| 14 | +}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) { |
| 15 | + return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} /> |
| 16 | +} |
| 17 | + |
| 18 | +function DrawerPortal({ |
| 19 | + ...props |
| 20 | +}: React.ComponentProps<typeof DrawerPrimitive.Portal>) { |
| 21 | + return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} /> |
| 22 | +} |
| 23 | + |
| 24 | +function DrawerClose({ |
| 25 | + ...props |
| 26 | +}: React.ComponentProps<typeof DrawerPrimitive.Close>) { |
| 27 | + return <DrawerPrimitive.Close data-slot="drawer-close" {...props} /> |
| 28 | +} |
| 29 | + |
| 30 | +function DrawerOverlay({ |
| 31 | + className, |
| 32 | + ...props |
| 33 | +}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) { |
| 34 | + return ( |
| 35 | + <DrawerPrimitive.Overlay |
| 36 | + data-slot="drawer-overlay" |
| 37 | + className={cn( |
| 38 | + "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/80", |
| 39 | + className |
| 40 | + )} |
| 41 | + {...props} |
| 42 | + /> |
| 43 | + ) |
| 44 | +} |
| 45 | + |
| 46 | +function DrawerContent({ |
| 47 | + className, |
| 48 | + children, |
| 49 | + ...props |
| 50 | +}: React.ComponentProps<typeof DrawerPrimitive.Content>) { |
| 51 | + return ( |
| 52 | + <DrawerPortal data-slot="drawer-portal"> |
| 53 | + <DrawerOverlay /> |
| 54 | + <DrawerPrimitive.Content |
| 55 | + data-slot="drawer-content" |
| 56 | + className={cn( |
| 57 | + "group/drawer-content bg-background fixed z-50 flex h-auto flex-col", |
| 58 | + "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-lg", |
| 59 | + "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-lg", |
| 60 | + "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", |
| 61 | + "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", |
| 62 | + className |
| 63 | + )} |
| 64 | + {...props} |
| 65 | + > |
| 66 | + <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" /> |
| 67 | + {children} |
| 68 | + </DrawerPrimitive.Content> |
| 69 | + </DrawerPortal> |
| 70 | + ) |
| 71 | +} |
| 72 | + |
| 73 | +function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) { |
| 74 | + return ( |
| 75 | + <div |
| 76 | + data-slot="drawer-header" |
| 77 | + className={cn("flex flex-col gap-1.5 p-4", className)} |
| 78 | + {...props} |
| 79 | + /> |
| 80 | + ) |
| 81 | +} |
| 82 | + |
| 83 | +function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) { |
| 84 | + return ( |
| 85 | + <div |
| 86 | + data-slot="drawer-footer" |
| 87 | + className={cn("mt-auto flex flex-col gap-2 p-4", className)} |
| 88 | + {...props} |
| 89 | + /> |
| 90 | + ) |
| 91 | +} |
| 92 | + |
| 93 | +function DrawerTitle({ |
| 94 | + className, |
| 95 | + ...props |
| 96 | +}: React.ComponentProps<typeof DrawerPrimitive.Title>) { |
| 97 | + return ( |
| 98 | + <DrawerPrimitive.Title |
| 99 | + data-slot="drawer-title" |
| 100 | + className={cn("text-foreground font-semibold tracking-tight", className)} |
| 101 | + {...props} |
| 102 | + /> |
| 103 | + ) |
| 104 | +} |
| 105 | + |
| 106 | +function DrawerDescription({ |
| 107 | + className, |
| 108 | + ...props |
| 109 | +}: React.ComponentProps<typeof DrawerPrimitive.Description>) { |
| 110 | + return ( |
| 111 | + <DrawerPrimitive.Description |
| 112 | + data-slot="drawer-description" |
| 113 | + className={cn("text-muted-foreground text-sm", className)} |
| 114 | + {...props} |
| 115 | + /> |
| 116 | + ) |
| 117 | +} |
| 118 | + |
| 119 | +export { |
| 120 | + Drawer, |
| 121 | + DrawerPortal, |
| 122 | + DrawerOverlay, |
| 123 | + DrawerTrigger, |
| 124 | + DrawerClose, |
| 125 | + DrawerContent, |
| 126 | + DrawerHeader, |
| 127 | + DrawerFooter, |
| 128 | + DrawerTitle, |
| 129 | + DrawerDescription, |
| 130 | +} |
0 commit comments