/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
'use client'
import { Drawer as DrawerPrimitive } from '@base-ui/react/drawer'
import * as React from 'react'
import { cn } from '@/lib/utils'
type DrawerContextProps = {
hasSnapPoints: boolean
modal: DrawerPrimitive.Root.Props['modal']
showSwipeHandle: boolean
swipeDirection: NonNullable
}
const DrawerContext = React.createContext(null)
function useDrawer() {
const context = React.useContext(DrawerContext)
if (!context) {
throw new Error('useDrawer must be used within a Drawer.')
}
return context
}
function Drawer({
modal = true,
showSwipeHandle = false,
snapPoints,
swipeDirection = 'down',
...props
}: DrawerPrimitive.Root.Props & {
showSwipeHandle?: boolean
}) {
const hasSnapPoints = snapPoints != null && snapPoints.length > 0
const contextValue = React.useMemo(
() => ({ hasSnapPoints, modal, showSwipeHandle, swipeDirection }),
[hasSnapPoints, modal, showSwipeHandle, swipeDirection]
)
return (
)
}
function DrawerTrigger({ ...props }: DrawerPrimitive.Trigger.Props) {
return
}
function DrawerPortal({ ...props }: DrawerPrimitive.Portal.Props) {
return
}
function DrawerClose({ ...props }: DrawerPrimitive.Close.Props) {
return
}
function DrawerOverlay({
className,
...props
}: DrawerPrimitive.Backdrop.Props) {
return (
)
}
function DrawerSwipeHandle({
className,
...props
}: React.ComponentProps<'div'>) {
return (
)
}
function DrawerContent({
className,
children,
...props
}: DrawerPrimitive.Popup.Props) {
const { hasSnapPoints, modal, showSwipeHandle, swipeDirection } = useDrawer()
const swipeAxis =
swipeDirection === 'down' || swipeDirection === 'up' ? 'y' : 'x'
return (
{modal === true && (
)}
{showSwipeHandle && }
{children}
)
}
function DrawerHeader({ className, ...props }: React.ComponentProps<'div'>) {
return (
)
}
function DrawerFooter({ className, ...props }: React.ComponentProps<'div'>) {
return (
)
}
function DrawerTitle({ className, ...props }: DrawerPrimitive.Title.Props) {
return (
)
}
function DrawerDescription({
className,
...props
}: DrawerPrimitive.Description.Props) {
return (
)
}
export {
Drawer,
DrawerPortal,
DrawerOverlay,
DrawerSwipeHandle,
DrawerTrigger,
DrawerClose,
DrawerContent,
DrawerHeader,
DrawerFooter,
DrawerTitle,
DrawerDescription,
}