# Drawer A swipeable edge panel for content you can pull into view, expand in stages and dismiss with a gesture. [Interactive guide](/docs/components/drawer) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use Drawer when dragging, swiping or settling into multiple snap positions forms part of the interaction. ### How to compose it Set the edge on Drawer and the surface treatment on DrawerContent. Pair snap points with keyboard-operable controls and provide one visible close action. ### What to verify Verify gesture and button control reach the same snap states. Confirm outside interaction follows modal mode and that the floating variant retains its gutter. ## Usage ```tsx import { Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerTitle, DrawerDescription, DrawerBody, DrawerFooter, DrawerClose } from 'wss3-forge' ``` - For a wide panel, DrawerContent.closePosition places the header close button on the right, and titlePosition places the heading on the left. Choose edge to align with the panel or content to align with the centered body. - Use Drawer when people can drag or resize the panel with a gesture. Use Sheet for an edge panel opened and closed with buttons. - Set the physical edge on Drawer. Set variant and width on DrawerContent. A docked panel can reach both screen edges at 100%. A floating panel keeps its outer gutter at every width. - Use snapPoints for resting positions. Pair the swipe handle with a button that changes the active point for keyboard users. Provide one visible close action. - DrawerContent supplies its portal and modal backdrop. Set modal={false} on Drawer to keep the surrounding interface interactive. ```tsx Press notes Production notes for the next run. ``` ## Runnable examples ### Swipeable proof queue ```tsx import { useState } from 'react' import { Dismiss16Regular } from '@fluentui/react-icons' import { Button, DescriptionList, Grid, Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, DrawerTrigger, HStack, Select, VStack } from 'wss3-forge' const edges = { bottom: 'down', top: 'up', right: 'right', left: 'left' } as const const positions = [ { value: 'edge', label: 'Panel edge' }, { value: 'content', label: 'Content' }, ] const widths = { Default: undefined, '480 px': 480, '65%': '65%', '100%': '100%' } as const const stops = [0.55, 1] function ProofQueue() { const [side, setSide] = useState('bottom') const [variant, setVariant] = useState<'docked' | 'floating'>('docked') const [width, setWidth] = useState('Default') const [closePosition, setClosePosition] = useState<'edge' | 'content'>('content') const [titlePosition, setTitlePosition] = useState<'edge' | 'content'>('content') const wide = width === '65%' || width === '100%' || (width === 'Default' && (side === 'top' || side === 'bottom')) const [snap, setSnap] = useState(stops[0]) const bottom = side === 'bottom' const expanded = snap === 1 return ( setVariant(value === 'floating' ? 'floating' : 'docked')} /> setClosePosition(value === 'edge' ? 'edge' : 'content')} /> ) } ``` ### Nested ```tsx import { Button, Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, Text } from 'wss3-forge' function SimpleDrawer({ side = 'bottom', label = 'Open drawer', nonModal = false, rtl = false }: { side?: 'top' | 'right' | 'bottom' | 'left'; label?: string; nonModal?: boolean; rtl?: boolean }) { return {rtl ? 'تفاصيل الطلب' : 'Order details'} {rtl ? 'تفاصيل الشحن والتسليم.' : 'Review delivery information for your order.'} {rtl ? 'تسليم قياسي' : 'Standard delivery'} } function NestedDrawers() { return AccountManage account and delivery preferences. } export default function Example() { return () } ``` ### Scrollable content ```tsx import { Button, Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, Text, VStack } from 'wss3-forge' export default function Example() { return ( Order historyReview recent delivery updates. {Array.from({ length: 24 }, (_, index) => Delivery receipt #{4189 - index})} ) } ``` ### RTL ```tsx import { Button, Direction, Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, Text } from 'wss3-forge' function SimpleDrawer({ side = 'bottom', label = 'Open drawer', nonModal = false, rtl = false }: { side?: 'top' | 'right' | 'bottom' | 'left'; label?: string; nonModal?: boolean; rtl?: boolean }) { return {rtl ? 'تفاصيل الطلب' : 'Order details'} {rtl ? 'تفاصيل الشحن والتسليم.' : 'Review delivery information for your order.'} {rtl ? 'تسليم قياسي' : 'Standard delivery'} } export default function Example() { return () } ``` ## Primitive libraries ### Base UI The Base UI drawer supports render, swipeDirection, snapPoint, onSnapPointChange, modal and disablePointerDismissal. ```sh npm install wss3-forge @base-ui/react ``` ```tsx import { Drawer, DrawerTrigger, DrawerContent, DrawerTitle, DrawerClose } from 'wss3-forge/base-ui' OpenProof queueDone ``` #### Preview ```tsx import { useState } from 'react' import { Dismiss16Regular } from '@fluentui/react-icons' import { Button, DescriptionList, Grid, HStack, Select, VStack } from 'wss3-forge' import { Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, DrawerTrigger } from 'wss3-forge/base-ui' const edges = { bottom: 'down', top: 'up', right: 'right', left: 'left' } as const const positions = [ { value: 'edge', label: 'Panel edge' }, { value: 'content', label: 'Content' }, ] const widths = { Default: undefined, '480 px': 480, '65%': '65%', '100%': '100%' } as const const stops = [0.55, 1] export default function ProofQueue() { const [side, setSide] = useState('bottom') const [variant, setVariant] = useState<'docked' | 'floating'>('docked') const [width, setWidth] = useState('Default') const [closePosition, setClosePosition] = useState<'edge' | 'content'>('content') const [titlePosition, setTitlePosition] = useState<'edge' | 'content'>('content') const wide = width === '65%' || width === '100%' || (width === 'Default' && (side === 'top' || side === 'bottom')) const [snap, setSnap] = useState(stops[0]) const bottom = side === 'bottom' const expanded = snap === 1 return ( setVariant(value === 'floating' ? 'floating' : 'docked')} /> setClosePosition(value === 'edge' ? 'edge' : 'content')} /> ({ value, label: value[0].toUpperCase() + value.slice(1) }))} onValueChange={value => setSide(value as keyof typeof edges)} /> setWidth(value as keyof typeof widths)} /> {wide && setTitlePosition(value === 'edge' ? 'edge' : 'content')} /> } { if (open) setSnap(stops[0]) }}> Proof queue {bottom ? 'Drag the handle to expand the queue or swipe down to close.' : 'Swipe toward the edge to close the queue.'} {bottom && } ) } ``` ### React Aria The Forge React Aria drawer uses the Base UI drawer engine. Use this optional entry point for that contract. The ordinary React Aria barrel also exposes the Forge Vaul drawer. The React Aria registry uses the Base UI drawer. This preview imports wss3-forge/react-aria/drawer. ```sh npm install wss3-forge react-aria-components @base-ui/react ``` ```tsx import { Drawer, DrawerTrigger, DrawerContent, DrawerTitle, DrawerClose } from 'wss3-forge/react-aria/drawer' OpenProof queueDone ``` #### Preview ```tsx import { useState } from 'react' import { Dismiss16Regular } from '@fluentui/react-icons' import { Button, DescriptionList, Grid, HStack, Select, VStack } from 'wss3-forge' import { Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, DrawerTrigger } from 'wss3-forge/react-aria/drawer' const edges = { bottom: 'down', top: 'up', right: 'right', left: 'left' } as const const positions = [ { value: 'edge', label: 'Panel edge' }, { value: 'content', label: 'Content' }, ] const widths = { Default: undefined, '480 px': 480, '65%': '65%', '100%': '100%' } as const const stops = [0.55, 1] export default function ProofQueue() { const [side, setSide] = useState('bottom') const [variant, setVariant] = useState<'docked' | 'floating'>('docked') const [width, setWidth] = useState('Default') const [closePosition, setClosePosition] = useState<'edge' | 'content'>('content') const [titlePosition, setTitlePosition] = useState<'edge' | 'content'>('content') const wide = width === '65%' || width === '100%' || (width === 'Default' && (side === 'top' || side === 'bottom')) const [snap, setSnap] = useState(stops[0]) const bottom = side === 'bottom' const expanded = snap === 1 return ( setVariant(value === 'floating' ? 'floating' : 'docked')} /> setClosePosition(value === 'edge' ? 'edge' : 'content')} />