mirror of
https://github.com/allankoechke/mantisbase-admin.git
synced 2026-11-30 10:19:37 +00:00
Fix scrolling, layout, and collapsible sections; improve animations and sizing. #VERCEL_SKIP Co-authored-by: Allan K. Koech <44490960+allankoechke@users.noreply.github.com>
112 lines
3.8 KiB
TypeScript
112 lines
3.8 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { Drawer as DrawerPrimitive } from "vaul"
|
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
const Drawer = ({ shouldScaleBackground = true, ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
|
|
<DrawerPrimitive.Root shouldScaleBackground={shouldScaleBackground} {...props} />
|
|
)
|
|
Drawer.displayName = "Drawer"
|
|
|
|
const DrawerTrigger = DrawerPrimitive.Trigger
|
|
|
|
const DrawerPortal = DrawerPrimitive.Portal
|
|
|
|
const DrawerClose = DrawerPrimitive.Close
|
|
|
|
const DrawerOverlay = React.forwardRef<
|
|
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
|
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
|
|
>(({ className, ...props }, ref) => (
|
|
<DrawerPrimitive.Overlay ref={ref} className={cn("fixed inset-0 z-50 bg-black/80", className)} {...props} />
|
|
))
|
|
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName
|
|
|
|
const drawerVariants = cva(
|
|
"fixed z-50 gap-4 bg-background shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
|
|
{
|
|
variants: {
|
|
side: {
|
|
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
|
|
bottom:
|
|
"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
|
|
left: "inset-y-0 left-0 h-full border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",
|
|
right:
|
|
"inset-y-0 right-0 h-full border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
side: "right",
|
|
},
|
|
},
|
|
)
|
|
|
|
interface DrawerContentProps
|
|
extends React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>,
|
|
VariantProps<typeof drawerVariants> {}
|
|
|
|
const DrawerContent = React.forwardRef<React.ElementRef<typeof DrawerPrimitive.Content>, DrawerContentProps>(
|
|
({ side = "right", className, children, ...props }, ref) => (
|
|
<DrawerPortal>
|
|
<DrawerOverlay />
|
|
<DrawerPrimitive.Content
|
|
ref={ref}
|
|
className={cn(drawerVariants({ side }), "flex flex-col", className)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</DrawerPrimitive.Content>
|
|
</DrawerPortal>
|
|
),
|
|
)
|
|
DrawerContent.displayName = "DrawerContent"
|
|
|
|
const DrawerHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
|
<div className={cn("flex flex-col space-y-1.5 text-center sm:text-left p-6 border-b", className)} {...props} />
|
|
)
|
|
DrawerHeader.displayName = "DrawerHeader"
|
|
|
|
const DrawerFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
|
<div
|
|
className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 p-6 border-t mt-auto", className)}
|
|
{...props}
|
|
/>
|
|
)
|
|
DrawerFooter.displayName = "DrawerFooter"
|
|
|
|
const DrawerTitle = React.forwardRef<
|
|
React.ElementRef<typeof DrawerPrimitive.Title>,
|
|
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
|
|
>(({ className, ...props }, ref) => (
|
|
<DrawerPrimitive.Title
|
|
ref={ref}
|
|
className={cn("text-lg font-semibold leading-none tracking-tight", className)}
|
|
{...props}
|
|
/>
|
|
))
|
|
DrawerTitle.displayName = DrawerPrimitive.Title.displayName
|
|
|
|
const DrawerDescription = React.forwardRef<
|
|
React.ElementRef<typeof DrawerPrimitive.Description>,
|
|
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
|
|
>(({ className, ...props }, ref) => (
|
|
<DrawerPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
|
|
))
|
|
DrawerDescription.displayName = DrawerPrimitive.Description.displayName
|
|
|
|
export {
|
|
Drawer,
|
|
DrawerPortal,
|
|
DrawerOverlay,
|
|
DrawerTrigger,
|
|
DrawerClose,
|
|
DrawerContent,
|
|
DrawerHeader,
|
|
DrawerFooter,
|
|
DrawerTitle,
|
|
DrawerDescription,
|
|
}
|