Drawer

The <smart-drawer> component provides a side panel overlay (left/right) with optional header, close button, and backdrop. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract DrawerBaseComponent defines the shared API — open (two-way ModelSignal<boolean>), title, optional IDrawerOptions, cssClass (alias class), a closed output, and a close() method that sets open to false and emits closed. DrawerStandardComponent is a barebones placeholder concrete implementation. DrawerComponent is the public wrapper that renders DrawerStandardComponent by default and accepts a custom replacement via DRAWER_STANDARD_COMPONENT_TOKEN.


Usage

<smart-button [options]="viewCart">View cart</smart-button>

<smart-drawer
  [(open)]="open"
  title="Shopping cart"
  [options]="options"
  (closed)="onClosed()"
>
  <ul>
    <li>Throwback Hip Bag, $90.00</li>
    <li>Medium Stuff Satchel, $32.00</li>
  </ul>
</smart-drawer>

<p>Times closed: {{ closedCount() }}</p>

The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Components

DrawerComponent (<smart-drawer>)

Main wrapper component. Renders DrawerStandardComponent by default. When DRAWER_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet.

DrawerStandardComponent (<smart-drawer-standard>)

Barebones placeholder concrete implementation. When open() is true, renders an optional overlay <div class="drawer-overlay"> (when options.withOverlay) and an <aside role="dialog" aria-modal="true"> with a data-position attribute (left or right, default right). When a title is provided, the aside includes a <header> with an <h2 id="smart-drawer-title"> and a close <button aria-label="Close">. Projected content is rendered via <ng-content />. It does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.

DrawerPresetComponent (<smart-drawer-preset>)

Fully-styled variation that extends DrawerBaseComponent and is a drop-in replacement for DrawerStandardComponent. Register it for DRAWER_STANDARD_COMPONENT_TOKEN to restyle every <smart-drawer> (or every preset at once with provideSmartPresets()), or use the <smart-drawer-preset> selector directly. It renders the translated Preline offcanvas look: a fixed, sliding side panel (role="dialog", aria-modal="true", tabindex="-1") with a header (title + circular close button with the Preline X icon), a <ng-content /> body, and an optional dimmed backdrop. It consumes options.position (left/right, default right → data-position + start/end placement), options.wide (max-w-xs → max-w-md), options.withOverlay (renders a click-to-close backdrop), and options.brandedHeader (blue header bar with inverted title/close styling). Open/close is Angular-driven via the open model + @if and close() (no Preline JS runtime). All classes are smart:-prefixed Tailwind with explicit dark: variants; the class recipes are internal (not exported from @smartsoft001/angular). The header is always rendered, with or without title.

The preset declares cssClass without the class alias, so bind [cssClass] when you use the <smart-drawer-preset> selector directly; class on <smart-drawer> reaches it through the wrapper.

The preset's body is its <ng-content />: the wrapper hands the content projected into <smart-drawer> to the registered implementation, and the <smart-drawer-preset> selector takes projected content directly. It does not consume options.stickyFooter (no footer slot in the base API) or options.variant (content-type variants are projected content, not built into the offcanvas shell). Top/bottom placements from the Preline reference are not expressible — IDrawerOptions.position is left | right only.

DrawerBaseComponent (abstract)

Abstract base directive for extending custom drawer implementations. Exposes open as a two-way ModelSignal<boolean> (default false), title as an InputSignal<string | undefined>, options as an InputSignal<IDrawerOptions | undefined>, cssClass as an InputSignal<string> (with alias class), a closed output, and a close() method that sets open to false and emits closed.

API

Inputs

InputTypeDefaultDescription
openModelSignal<boolean>falseWhether the drawer is open (two-way bindable)
titleInputSignal<string | undefined>-Optional drawer title (renders header when set)
optionsInputSignal<IDrawerOptions | undefined>-Optional configuration
classInputSignal<string>''Classes on the panel (cssClass input, alias class)

Outputs

OutputTypeDescription
closedOutputEmitterRef<void>Emitted when the drawer closes itself (close(): the close button or the overlay)
openChangeOutputEmitterRef<boolean>The open model's change event, for [(open)]

IDrawerOptions

FieldTypeDefaultDescription
position'left' | 'right''right'The side the panel opens on. The standard writes it to the data-position attribute; the preset places the panel there.
withOverlayboolean-Renders a backdrop; a click on it closes the drawer (standard and preset).
wideboolean-A wider panel (max-w-md instead of max-w-xs). Preset only.
brandedHeaderboolean-A blue header bar with inverted title and close button. Preset only.
stickyFooterboolean-Not read by the built-in implementations; available to a custom implementation.
variantSmartDrawerVariant-Not read by the built-in implementations; available to a custom implementation.

SmartDrawerVariant is 'empty' | 'create-form' | 'user-profile' | 'contact-list' | 'file-details'.

The standard component only consumes position (mapped to the data-position attribute on the aside, default 'right') and withOverlay (toggles the backdrop overlay).

DRAWER_STANDARD_COMPONENT_TOKEN

InjectionToken that allows replacing the default DrawerStandardComponent with a custom implementation. Provide a Type<DrawerBaseComponent> to override. The wrapper passes open, title, options and the class, hands over the projected content, and re-emits the implementation's closed and open changes.

Extending the base class

import {
  ChangeDetectionStrategy,
  Component,
  computed,
  ViewEncapsulation,
} from '@angular/core';

import {
  DRAWER_STANDARD_COMPONENT_TOKEN,
  DrawerBaseComponent,
  DrawerComponent,
  IDrawerOptions,
} from '@smartsoft001/angular';

@Component({
  selector: 'docs-custom-drawer',
  template: `
    @if (open()) {
      @if (options()?.withOverlay) {
        <div class="docs-drawer__overlay" (click)="close()"></div>
      }
      <aside
        role="dialog"
        aria-modal="true"
        [class]="panelClasses()"
        [attr.data-position]="options()?.position ?? 'right'"
      >
        @if (title()) {
          <header class="docs-drawer__header">
            <h2>{{ title() }}</h2>
            <button
              type="button"
              class="docs-drawer__close"
              aria-label="Close"
              (click)="close()"
            >
              &times;
            </button>
          </header>
        }
        <!--
          smart-drawer passes open, title, options and cssClass to a custom
          implementation (no other inputs), and its projected content to the
          implementation's default ng-content. This one renders a fixed body,
          so it declares no ng-content.
        -->
        <p class="docs-drawer__body">Your cart is empty.</p>
      </aside>
    }
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomDrawerComponent extends DrawerBaseComponent {
  // `cssClass` comes from the base (alias `class`): the wrapper hands the
  // consumer's class to it under that name.
  panelClasses = computed(() => {
    const classes = ['docs-drawer__panel'];
    if (this.options()?.wide) classes.push('docs-drawer__panel--wide');
    const extra = this.cssClass();
    if (extra) classes.push(extra);
    return classes.join(' ');
  });
}

@Component({
  selector: 'docs-drawer-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DrawerComponent],
  // The token swaps the standard drawer for the custom one everywhere below
  // this component, so consumers keep writing `<smart-drawer>`.
  providers: [
    {
      provide: DRAWER_STANDARD_COMPONENT_TOKEN,
      useValue: CustomDrawerComponent,
    },
  ],
  template: `
    <smart-drawer [open]="true" title="Shopping cart" [options]="options" />
  `,
})
export class DrawerCustomExampleComponent {
  options: IDrawerOptions = { position: 'right', withOverlay: true };
}

Content Projection

DrawerStandardComponent uses <ng-content /> to project arbitrary children. A custom implementation registered via DRAWER_STANDARD_COMPONENT_TOKEN receives the same content in its default <ng-content /> slot, so it can show or hide the slot with @if (open()) like the standard drawer, and control flow at the root of the projected content keeps working. The content arrives wrapped in one display: contents element: selectors on the slot's parent that target its direct children (space-y-*, divide-*, > *) do not reach the projected nodes.

Accessibility

  • The aside is rendered with role="dialog" and aria-modal="true" so assistive technologies treat it as a modal dialog.
  • When a title is provided, the aside is labelled via aria-labelledby="smart-drawer-title" (matching the <h2 id="smart-drawer-title"> inside the header). Without a title, no label is set — supply one through class-scoped styling or wrap the drawer in a labelled landmark if needed.
  • The header close button has aria-label="Close".
  • Positioning is exposed declaratively via the data-position="left|right" attribute on the aside, allowing CSS to style left- vs right-anchored drawers without runtime branching. Default is right.
  • The overlay (when options.withOverlay is true) closes the drawer on click.

Source

The component lives in packages/shared/angular/src/lib/components/drawer and is documented for Claude Code by the angular-components-drawer skill.

SmartDrawer is a side panel (role="dialog") that slides in from the right (or left) with a header holding the title and a close button, and children as the body. Its open state is controlled (open + onOpenChange) or kept inside (defaultOpen). Closing through the close button or the overlay calls onClosed. It renders nothing while closed.


Usage

import { useState } from 'react';

import { IDrawerOptions, SmartButton, SmartDrawer } from '@smartsoft001/react';

// A backdrop behind the panel; a click on it closes the drawer.
const options: IDrawerOptions = { withOverlay: true };

export function DrawerUsageExample() {
  const [open, setOpen] = useState(false);
  const [closedCount, setClosedCount] = useState(0);

  return (
    <>
      <SmartButton options={{ click: () => setOpen(true) }}>
        View cart
      </SmartButton>

      <SmartDrawer
        open={open}
        onOpenChange={setOpen}
        title="Shopping cart"
        options={options}
        onClosed={() => setClosedCount((count) => count + 1)}
      >
        <ul>
          <li>Throwback Hip Bag, $90.00</li>
          <li>Medium Stuff Satchel, $32.00</li>
        </ul>
      </SmartDrawer>

      <p>Times closed: {closedCount}</p>
    </>
  );
}

The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Exports

All from @smartsoft001/react.

ExportKindWhat it is
SmartDrawercomponentRenders the implementation registered as components.drawer on SmartProvider, SmartDrawerStandard by default.
SmartDrawerPresetcomponentStyled drawer (offcanvas) variation (preset).
SmartDrawerStandardcomponentThe default drawer rendering.
useDrawerhookThe behaviour every drawer variant shares: the open state, controlled through open / onOpenChange or kept internally from defaultOpen, and close(), which hides the drawer and reports onClosed.

The preset's class helpers (getDrawerPanelClasses, getDrawerBackdropClasses, getDrawerHeaderClasses, getDrawerTitleClasses, getDrawerCloseClasses, getDrawerBodyClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartDrawerProps

PropTypeDefaultDescription
open?boolean—Whether the drawer is shown. Leave it undefined for an uncontrolled drawer that starts from defaultOpen.
defaultOpen?booleanfalseInitial open of an uncontrolled drawer.
onOpenChange?(open: boolean) => void—Called when the drawer opens or closes.
title?string—Heading of the panel; the standard drawer renders the header (with the close button) only when it is set.
options?IDrawerOptions—Side, width, backdrop and header look.
className?string—Classes on the panel.
onClosed?() => void—Called after the drawer closed itself (close button / overlay click).
children?ReactNode—The body of the panel.

IDrawerOptions

FieldTypeDefaultDescription
position?'left' | 'right''right'The side the panel opens on.
wide?boolean—A wider panel (preset).
withOverlay?boolean—Renders a backdrop; a click on it closes the drawer.
brandedHeader?boolean—A coloured header (preset).
stickyFooter?boolean—Declared; not read by the standard or preset drawer.
variant?SmartDrawerVariant—Declared (SmartDrawerVariant); not read by the standard or preset drawer.
  • SmartDrawerVariant: 'empty' \| 'create-form' \| 'user-profile' \| 'contact-list' \| 'file-details'

Replacing the Implementation

SmartDrawer renders the component registered under the 'drawer' key of SmartProvider's components, and SmartDrawerStandard when nothing is registered there. Every SmartDrawer below the provider then renders the registered component, which receives the same props.

SmartDrawerPreset is the styled (preset) implementation: register it under the 'drawer' key of SmartProvider's components, render it directly in place of SmartDrawer, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.

The useDrawer hook

The behaviour every drawer variant shares: the open state, controlled through open / onOpenChange or kept internally from defaultOpen, and close(), which hides the drawer and reports onClosed.

ReturnsTypeDescription
openbooleanThe open state (controlled or internal).
setOpen(value: boolean) => voidSets the state and calls onOpenChange.
close() => voidCloses the drawer, calls onOpenChange(false) and then onClosed.
import {
  IDrawerOptions,
  SmartDrawer,
  SmartDrawerProps,
  SmartProvider,
  useDrawer,
} from '@smartsoft001/react';

/**
 * A custom drawer built on `useDrawer`.
 *
 * The hook owns the `open` state (controlled or not) and `close()`, which
 * hides the drawer and reports `onOpenChange(false)` and `onClosed`.
 */
export function CustomDrawer(props: SmartDrawerProps) {
  const { title, options, className } = props;
  const { open, close } = useDrawer(props);

  if (!open) return null;

  const panelClasses = [
    'docs-drawer__panel',
    options?.wide && 'docs-drawer__panel--wide',
    className,
  ]
    .filter(Boolean)
    .join(' ');

  return (
    <>
      {options?.withOverlay && (
        <div className="docs-drawer__overlay" onClick={close} />
      )}
      <aside
        role="dialog"
        aria-modal="true"
        className={panelClasses}
        data-position={options?.position ?? 'right'}
      >
        {title && (
          <header className="docs-drawer__header">
            <h2>{title}</h2>
            <button
              type="button"
              className="docs-drawer__close"
              aria-label="Close"
              onClick={close}
            >
              &times;
            </button>
          </header>
        )}
        {/* SmartDrawer passes its children on as `children`; this one
            renders a fixed body instead. */}
        <p className="docs-drawer__body">Your cart is empty.</p>
      </aside>
    </>
  );
}

// A module constant: a new object on every render would change the context.
const components = { drawer: CustomDrawer };

const options: IDrawerOptions = { position: 'right', withOverlay: true };

// Every <SmartDrawer> below the provider renders CustomDrawer.
export function DrawerCustomExample() {
  return (
    <SmartProvider components={components}>
      <SmartDrawer defaultOpen title="Shopping cart" options={options} />
    </SmartProvider>
  );
}

Styling

  • The standard drawer is unstyled markup (data-position, a .drawer-overlay backdrop); register or render SmartDrawerPreset for the sliding panel look with smart:dark: variants.
  • className is appended to the panel.

Source

The component lives in packages/shared/react/src/lib/components/drawer and is documented for Claude Code by the react-components-drawer skill.