Skip to content

Vben Drawer

Vben Drawer is the shared drawer wrapper used by the framework. It supports auto-height layout, loading state, connected components, and an imperative API similar to the modal API.

Basic Usage

ts
const [Drawer, drawerApi] = useVbenDrawer({
  // props
  // events
});

Current Usage Notes

  • If you use connectedComponent, the inner and outer components share data through drawerApi.setData() and drawerApi.getData().
  • Default drawer behavior can be adjusted in apps/<app>/src/bootstrap.ts through setDefaultDrawerProps(...).
  • setState(...) works on DrawerState, not ModalState.

Key Props

PropDescriptionType
appendToMainmount inside the main content area instead of bodyboolean
connectedComponentconnect an inner component to the drawer wrapperComponent
closeIconPlacementposition of the close icon'left' | 'right'
placementdrawer side'left' | 'right' | 'top' | 'bottom'
overlayBlurblur amount for the overlaynumber
submittinglock drawer interactions while submittingboolean

Events

EventDescriptionType
onBeforeClosecalled before close; returning false or rejecting prevents close() => Promise<boolean | undefined> | boolean | undefined
onOpenChangecalled when open state changes(isOpen: boolean) => void
onOpenedcalled after open animation completes() => void
onClosedcalled after close animation completes() => void

drawerApi

MethodDescription
setState(...)updates drawer state
open()opens the drawer
close()closes the drawer
setData(data)stores shared data
getData<T>()reads shared data
lock(isLocked = true)locks the drawer into submitting state
unlock()alias for lock(false)

Contributors

The avatar of contributor named as xingyu4j xingyu4j

Changelog

Released under the MIT License.