Drawer
A drawer panel that slides in from a screen edge, commonly used for details or forms that need more display space. Differences from Dialog: it hugs an edge, slides by direction, and the panel size applies to a single side (width or height).
Basic usage
Four directions and custom sizes
import { useState } from 'react'
import { LhButton, LhDrawer } from '@lh-ui/react'
export default function Demo() {
const [open, setOpen] = useState(false)
return (
<>
<LhButton onClick={() => setOpen(true)}>Open drawer</LhButton>
<LhDrawer title="Drawer title" open={open} onClose={() => setOpen(false)}>
Drawer content
</LhDrawer>
</>
)
}
Drawer Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| children | Body content | ReactNode | — | — |
| open | Whether to show (controlled) | boolean | — | false |
| title | Title | ReactNode | — | — |
| direction | Slide-in direction | 'right' | 'left' | 'top' | 'bottom' | — | 'right' |
| size | Panel size (number → px; string supports percentages) | string | number | — | '30%' |
| showClose | Whether to show the close button | boolean | — | true |
| maskClosable | Whether clicking the modal closes the drawer | boolean | — | false |
| closeOnEsc | Whether Esc closes the drawer | boolean | — | true |
| lockScroll | Whether to lock body scroll (also traps focus when locked) | boolean | — | true |
| beforeClose | Intercept before closing; closing only proceeds when done is called | (done: () => void) => void | — |