'use client' import * as React from 'react' import { Drawer as DrawerPrimitive } from '@base-ui/react/drawer' import { IconX } from '@tabler/icons-react' import { Button } from './button' import { cn } from './utils' type DrawerContextProps = { hasSnapPoints: boolean modal: DrawerPrimitive.Root.Props['modal'] 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 = 'trap-focus', snapPoints, swipeDirection = 'right', ...props }: DrawerPrimitive.Root.Props) { const hasSnapPoints = snapPoints != null && snapPoints.length > 0 const contextValue = React.useMemo( () => ({ hasSnapPoints, modal, swipeDirection }), [hasSnapPoints, modal, swipeDirection] ) return ( ) } function DrawerTrigger({ ...props }: DrawerPrimitive.Trigger.Props) { return } function DrawerClose({ ...props }: DrawerPrimitive.Close.Props) { return } type DrawerContentProps = DrawerPrimitive.Popup.Props & { showCloseButton?: boolean } function DrawerContent({ className, children, showCloseButton = true, ...props }: DrawerContentProps) { const { hasSnapPoints, modal, swipeDirection } = useDrawer() const [container, setContainer] = React.useState(null) const markerRef = React.useCallback((node: HTMLElement | null) => { if (node) setContainer(node.closest('[data-applet]')) }, []) const swipeAxis = swipeDirection === 'down' || swipeDirection === 'up' ? 'y' : 'x' return ( <>