Standard Toolkit
Toolkits@accelint/design-toolkitComponents

Drawer

Slide-in panel for navigation or contextual content with stacked view support

Usage

import {
  Drawer,
  DrawerLayout,
  DrawerLayoutMain,
  DrawerPanel,
  DrawerView,
  DrawerHeader,
  DrawerContent,
  DrawerTrigger,
  Button
} from '@accelint/design-toolkit';
import { uuid } from '@accelint/core';

const ids = { drawer: uuid(), view: uuid() };

export function MyDrawer() {
  return (
    <DrawerLayout push="left">
      <DrawerLayoutMain>
        <DrawerTrigger for={`open:${ids.view}`}>
          <Button>Open Drawer</Button>
        </DrawerTrigger>
      </DrawerLayoutMain>

      <Drawer id={ids.drawer} defaultView={ids.view}>
        <DrawerPanel>
          <DrawerView id={ids.view}>
            <DrawerHeader title="Drawer Title" />
            <DrawerContent>Your content here</DrawerContent>
          </DrawerView>
        </DrawerPanel>
      </Drawer>
    </DrawerLayout>
  );
}

Reference

interface DrawerProps {
  id: UniqueId;
  children: React.ReactNode;
  className?: string;
  defaultView?: UniqueId;
  placement?: 'left' | 'right' | 'top' | 'bottom';
  size?: 'small' | 'medium' | 'large';
  onChange?: (view: UniqueId | null) => void;
}

type DrawerLayoutTracks = Partial<
  Record<'top' | 'right' | 'bottom' | 'left', string>
>;

interface DrawerLayoutProps extends React.ComponentPropsWithRef<'div'> {
  extend?: 'top' | 'right' | 'bottom' | 'left' | /* supported combinations */ string;
  push?: 'top' | 'right' | 'bottom' | 'left' | /* supported combinations */ string;
  tracks?: DrawerLayoutTracks;
}

Props

PropTypeDefaultRequired
idUniqueId-Yes
childrenReact.ReactNode-Yes
classNamestring-No
defaultViewUniqueId-No
placement'left' | 'right' | 'top' | 'bottom''left'No
size'small' | 'medium' | 'large''medium'No
onChange(view: UniqueId | null) => void-No

id

Unique identifier for the drawer. Required for event handling and targeted control from outside the drawer's context.

defaultView

ID of the view to display initially when the drawer opens. Must match the id of a DrawerView child component.

placement

Edge of the viewport the drawer slides from:

  • left - Slides from the left edge (default)
  • right - Slides from the right edge
  • top - Slides from the top edge
  • bottom - Slides from the bottom edge

size

Controls the drawer panel dimensions:

  • small - Narrower panel for simple content
  • medium - Default balanced width
  • large - Wider panel for complex content

onChange

Callback invoked when the active view changes. Receives the new view ID or null when all views are closed.

DrawerLayout props

PropTypeDefaultRequired
tracksPartial<Record<'top' | 'right' | 'bottom' | 'left', string>>Semantic Drawer sizeNo
extendPlacement or supported placement combination'left right'No
pushPlacement or supported placement combinationOverlay behaviorNo

tracks

Configures the effective CSS grid track for each supplied placement:

tracks?: Partial<Record<'top' | 'right' | 'bottom' | 'left', string>>

Each supplied string is passed verbatim to a CSS custom property and resolved by the browser as a CSS grid track value. A configured value overrides that placement's semantic Drawer size only while one or more Drawers at the placement are open. Omitted placements retain the existing semantic-size behavior. Closed or absent placements settle to 0px, except the left track, which keeps its Sidenav width when a Sidenav is present.

Examples

Example: Basic drawer with trigger

import {
  Drawer,
  DrawerLayout,
  DrawerLayoutMain,
  DrawerPanel,
  DrawerView,
  DrawerHeader,
  DrawerContent,
  DrawerTrigger,
  Button
} from '@accelint/design-toolkit';
import { uuid } from '@accelint/core';

const ids = { drawer: uuid(), view: uuid() };

<DrawerLayout>
  <DrawerLayoutMain>
    <DrawerTrigger for={`open:${ids.view}`}>
      <Button>Open</Button>
    </DrawerTrigger>
  </DrawerLayoutMain>

  <Drawer id={ids.drawer} defaultView={ids.view}>
    <DrawerPanel>
      <DrawerView id={ids.view}>
        <DrawerHeader title="Settings" />
        <DrawerContent>
          <p>Drawer content goes here</p>
        </DrawerContent>
      </DrawerView>
    </DrawerPanel>
  </Drawer>
</DrawerLayout>

Example: Right-side drawer

import { Drawer, DrawerPanel, DrawerView, DrawerHeader, DrawerContent } from '@accelint/design-toolkit';
import { uuid } from '@accelint/core';

const ids = { drawer: uuid(), view: uuid() };

<Drawer id={ids.drawer} defaultView={ids.view} placement="right">
  <DrawerPanel>
    <DrawerView id={ids.view}>
      <DrawerHeader title="Notifications" />
      <DrawerContent>
        <p>Your notifications</p>
      </DrawerContent>
    </DrawerView>
  </DrawerPanel>
</Drawer>

Example: Multiple stacked views

import {
  Drawer,
  DrawerPanel,
  DrawerView,
  DrawerHeader,
  DrawerContent,
  DrawerTrigger,
  Button
} from '@accelint/design-toolkit';
import { uuid } from '@accelint/core';

const ids = {
  drawer: uuid(),
  main: uuid(),
  settings: uuid()
};

<Drawer id={ids.drawer} defaultView={ids.main}>
  <DrawerPanel>
    <DrawerView id={ids.main}>
      <DrawerHeader title="Menu" />
      <DrawerContent>
        <DrawerTrigger for={ids.settings}>
          <Button>Open Settings</Button>
        </DrawerTrigger>
      </DrawerContent>
    </DrawerView>

    <DrawerView id={ids.settings}>
      <DrawerHeader title="Settings" />
      <DrawerContent>
        <p>Settings content</p>
      </DrawerContent>
    </DrawerView>
  </DrawerPanel>
</Drawer>

Example: Controlled drawer state

import { Drawer, DrawerPanel, DrawerView, DrawerHeader, DrawerContent } from '@accelint/design-toolkit';
import { uuid } from '@accelint/core';
import { useState } from 'react';

function ControlledDrawer() {
  const ids = { drawer: uuid(), view: uuid() };
  const [activeView, setActiveView] = useState(ids.view);

  return (
    <Drawer
      id={ids.drawer}
      defaultView={ids.view}
      onChange={setActiveView}
    >
      <DrawerPanel>
        <DrawerView id={ids.view}>
          <DrawerHeader title="Controlled" />
          <DrawerContent>
            <p>Active: {activeView}</p>
          </DrawerContent>
        </DrawerView>
      </DrawerPanel>
    </Drawer>
  );
}

Example: Configured browser-resolved tracks

Pass CSS grid-track values for any combination of the four placements. The browser resolves fixed lengths, functions, and custom-property references.

<DrawerLayout
  tracks={{
    top: '72px',
    right: 'minmax(18rem, 30vw)',
    bottom: 'minmax(8rem, 25vh)',
    left: 'calc(12rem + 8px)'
  }}
>
  <DrawerLayoutMain>Main content</DrawerLayoutMain>
  {/* Open Drawers resolve their matching configured track. */}
</DrawerLayout>

Use a CSS custom property when the host layout owns the value. For example, an open left Drawer resolves var(--navigation-width) to 240px when its container defines --navigation-width: 240px.

<DrawerLayout tracks={{ left: 'var(--navigation-width)' }}>
  <DrawerLayoutMain>Main content</DrawerLayoutMain>
  {/* The containing element defines --navigation-width: 240px. */}
</DrawerLayout>

Example: Partial configuration with semantic fallback

Configure only the placement that needs a custom reservation. An open, unconfigured right Drawer continues to use its small, medium, or large semantic track.

<DrawerLayout tracks={{ left: '256px' }} push="left">
  <DrawerLayoutMain>Main content moves outside the open left track.</DrawerLayoutMain>
  {/* An open left Drawer uses 256px; an open right Drawer uses its semantic size. */}
</DrawerLayout>

Example: Push and overlay use the same effective track

tracks determines the grid track for both push and overlay Drawers. push only determines whether DrawerLayoutMain occupies the corresponding grid lines.

<DrawerLayout tracks={{ right: '280px' }} push="right">
  <DrawerLayoutMain>Main content is pushed outside the right track.</DrawerLayoutMain>
</DrawerLayout>

<DrawerLayout tracks={{ right: '280px' }}>
  <DrawerLayoutMain>Main content retains its overlay placement.</DrawerLayoutMain>
</DrawerLayout>

Browser resolution, malformed values, and CSS-wide keywords

Use values accepted by the browser's CSS grid-track grammar. tracks deliberately does not parse, normalize, or validate values at runtime. CSS-wide keywords such as initial, inherit, unset, revert, and revert-layer are also passed through unchanged.

Good to know: If a value is malformed or unsupported for the browser's grid-track grammar, no JavaScript validation error is thrown. The browser's CSS error-handling rules determine the resolved declaration. Test values in the browsers and container styles your application supports.

Migration and compatibility

Adoption is opt-in. Existing DrawerLayout callers require no migration and keep semantic Drawer-size tracks. Add tracks only where a placement needs an explicit reservation.

Accessibility and non-goals

tracks is layout-only. It does not change Drawer accessible names, roles, keyboard operation, focus management, dismissal behavior, screen-reader output, or open/closed content visibility. It also does not change Sidenav's independent reservation behavior.

The API does not add a CSS parser, runtime validation, normalization, Drawer registration changes, a layout context, or aggregation for concurrent Drawers at the same placement. Same-placement Drawers continue to share their existing placement area; a configured placement supplies one effective track while any matching Drawer is open.

Example: Large drawer with push behavior

import {
  Drawer,
  DrawerLayout,
  DrawerLayoutMain,
  DrawerPanel,
  DrawerView,
  DrawerHeader,
  DrawerContent
} from '@accelint/design-toolkit';
import { uuid } from '@accelint/core';

const ids = { drawer: uuid(), view: uuid() };

<DrawerLayout push="left">
  <DrawerLayoutMain>
    <p>Main content is pushed when drawer opens</p>
  </DrawerLayoutMain>

  <Drawer id={ids.drawer} defaultView={ids.view} size="large">
    <DrawerPanel>
      <DrawerView id={ids.view}>
        <DrawerHeader title="Wide Panel" />
        <DrawerContent>
          <p>Large drawer content</p>
        </DrawerContent>
      </DrawerView>
    </DrawerPanel>
  </Drawer>
</DrawerLayout>

Example: Drawer with menu navigation

import {
  Drawer,
  DrawerPanel,
  DrawerView,
  DrawerMenu,
  DrawerMenuItem,
  DrawerHeader,
  DrawerContent,
  Icon
} from '@accelint/design-toolkit';
import { Settings, Home } from '@accelint/icons';
import { uuid } from '@accelint/core';

const ids = {
  drawer: uuid(),
  home: uuid(),
  settings: uuid()
};

<Drawer id={ids.drawer} defaultView={ids.home}>
  <DrawerMenu>
    <DrawerMenuItem for={ids.home} textValue="Home">
      <Icon><Home /></Icon>
    </DrawerMenuItem>
    <DrawerMenuItem for={ids.settings} textValue="Settings">
      <Icon><Settings /></Icon>
    </DrawerMenuItem>
  </DrawerMenu>

  <DrawerPanel>
    <DrawerView id={ids.home}>
      <DrawerHeader title="Home" />
      <DrawerContent>Home content</DrawerContent>
    </DrawerView>

    <DrawerView id={ids.settings}>
      <DrawerHeader title="Settings" />
      <DrawerContent>Settings content</DrawerContent>
    </DrawerView>
  </DrawerPanel>
</Drawer>

Multi-Part Structure

Drawer is a multi-part component composed of several sub-components:

  • Drawer - Root container that manages view state and event handling
  • DrawerLayout - Layout wrapper that configures drawer positioning behavior
  • DrawerLayoutMain - Main content area adjacent to drawers
  • DrawerPanel - Container for drawer views
  • DrawerView - Individual stacked view within the drawer
  • DrawerHeader - Header section with title and optional actions
  • DrawerContent - Scrollable content area
  • DrawerFooter - Footer section for actions
  • DrawerMenu - Icon-based navigation menu
  • DrawerMenuItem - Individual menu item
  • DrawerTrigger - Button that controls drawer open/close/navigation
  • DrawerClose - Close button component
  • DrawerBack - Back navigation button

See individual component pages for detailed documentation.

Event System

Drawer uses a global event bus for programmatic control:

Simple Events (context-aware)

  • 'back' - Navigate to previous view in stack
  • 'clear' - Clear all views from stack
  • 'close' - Close the current drawer
  • 'reset' - Reset stack to default view
  • viewId - Push a specific view onto the stack

Targeted Events (external control)

  • 'open:${viewId}' - Clear stack and open specific view
  • 'close:${drawerId}' - Close specific drawer
  • 'toggle:${viewId}' - Toggle view open/closed
  • 'back:${drawerId}' - Navigate back in specific drawer
  • 'clear:${drawerId}' - Clear specific drawer stack
  • 'reset:${drawerId}' - Reset specific drawer stack

Chained Events

Pass an array to trigger multiple events sequentially:

<DrawerTrigger for={['reset', ids.settings, ids.profile]}>
  <Button>Reset & Open Settings</Button>
</DrawerTrigger>

Good to know: Simple events only work within the context of a Drawer. Use targeted events to control drawers from outside their component tree.

On this page