Drawer
Drawer opens side-panel workflows without replacing the underlying screen.
@duskmoon-dev/components/drawer Usage
When to use
- Use it when supporting content should stay attached to a trigger or task context.
- Prefer controlled open state when the surrounding workflow needs to react to dismissal.
Implementation notes
Features
Documents trigger, placement, and open-state patterns for content rendered above the page.
Highlights controlled state and close callbacks where overlays expose them.
Drawer is most often configured through `open`, `title`, `placement`, `onClose`.
Renders title and children when open
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Basic usage
Import the component stylesheet and Drawer from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function Example() {
return (<Drawer
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Renders title and children when open
test-backedDrawer scenario from the component test coverage: renders title and children when open.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function DrawerRendersTitleAndChildrenDemo() {
return (<Drawer
// Renders title and children when open
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Keeps closed drawer without open class
test-backedDrawer scenario from the component test coverage: keeps closed drawer without open class.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function DrawerKeepsClosedDrawerWithoutDemo() {
return (<Drawer
// Keeps closed drawer without open class
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Supports title prop
test-backedDrawer scenario from the component test coverage: supports title prop.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function DrawerSupportsTitlePropDemo() {
return (<Drawer
// Supports title prop
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Supports placement classes
test-backedDrawer scenario from the component test coverage: supports placement classes.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function DrawerSupportsPlacementClassesDemo() {
return (<Drawer
// Supports placement classes
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Calls onClose from the close button
test-backedDrawer scenario from the component test coverage: calls onclose from the close button.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function DrawerCallsOnCloseFromTheDemo() {
return (<Drawer
// Calls onClose from the close button
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Renders footer and extra content
test-backedDrawer scenario from the component test coverage: renders footer and extra content.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function DrawerRendersFooterAndExtraDemo() {
return (<Drawer
// Renders footer and extra content
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Applies size, placement, width, and height
test-backedDrawer scenario from the component test coverage: applies size, placement, width, and height.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function DrawerAppliesSizePlacementWidthDemo() {
return (<Drawer
// Applies size, placement, width, and height
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Forwards aside ref and native props
test-backedDrawer scenario from the component test coverage: forwards aside ref and native props.
import "@duskmoon-dev/components/styles.css";
import { Drawer } from "@duskmoon-dev/components/drawer";
export function DrawerForwardsAsideRefAndDemo() {
return (<Drawer
// Forwards aside ref and native props
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Drawer
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>
</div>
<div data-theme="moonlight">
<Drawer
title="DuskMoon"
open
>
DuskMoon Drawer
</Drawer>
</div> API
The API reference below lists every parsed exported type or interface for Drawer. Start with `open`, `title`, `placement`, `onClose` for common usage.
packages/components/src/components/drawer/Drawer.types.ts
Scenarios: packages/components/src/components/drawer/Drawer.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
open | boolean | No | open configures Drawer. |
title | ReactNode | No | title configures Drawer. |
children | ReactNode | No | children configures Drawer. |
placement | DrawerPlacement | No | placement configures Drawer. |
onClose | (event: MouseEvent<HTMLButtonElement>) => void | No | onClose configures Drawer. |
closeIcon | ReactNode | No | closeIcon configures Drawer. |
footer | ReactNode | No | footer configures Drawer. |
extra | ReactNode | No | extra configures Drawer. |
width | CSSProperties["width"] | No | width configures Drawer. |
height | CSSProperties["height"] | No | height configures Drawer. |
size | DrawerSize | No | size configures Drawer. |
className | string | No | className configures Drawer. |
"left" | "right" | "top" | "bottom" "sm" | "md" | "lg" | "xl" ForwardRefExoticComponent< DrawerProps & RefAttributes<HTMLElement> >