Sidebar Layout

The <smart-sidebar-layout> component provides a two-column application shell with a sidebar (left or right) and a main content region, with an optional top header. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract SidebarLayoutBaseComponent defines the shared API — optional ISidebarLayoutOptions and cssClass (alias class). SidebarLayoutStandardComponent is a barebones placeholder concrete implementation. SidebarLayoutComponent is the public wrapper that renders SidebarLayoutStandardComponent by default and accepts a custom replacement via SIDEBAR_LAYOUT_STANDARD_COMPONENT_TOKEN.


Usage

<ng-template #sidebar>
  <nav aria-label="Main">
    <a href="/dashboard">Dashboard</a>
    <a href="/projects">Projects</a>
    <a href="/team">Team</a>
  </nav>
</ng-template>

<smart-sidebar-layout [options]="options()">
  <h1>Dashboard</h1>
  <p>Welcome back. Here is what changed since yesterday.</p>
</smart-sidebar-layout>

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

Main wrapper component. Renders SidebarLayoutStandardComponent by default. When SIDEBAR_LAYOUT_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet and hands it the options and class inputs. Accepts main content via projected <ng-content>, which reaches the <ng-content /> of whichever implementation renders (the standard, the preset or a custom one).

Barebones placeholder concrete implementation. Renders a wrapper <div> containing an optional <header> (when options.headerTpl is provided), an <aside> for the sidebar, and a <main> element that projects <ng-content>. The order of <aside> and <main> swaps based on options.sidebarPosition ('left' default or 'right'). The external cssClass is applied to the wrapper. It does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.

Abstract base directive for extending custom sidebar-layout implementations. Exposes options as an InputSignal<ISidebarLayoutOptions | undefined> and cssClass as an InputSignal<string> (with alias class).

API

Inputs

InputTypeDefaultDescription
optionsInputSignal<ISidebarLayoutOptions | undefined>-Optional configuration (sidebar template, position, header)
classInputSignal<string>''External CSS classes (alias for cssClass)

ISidebarLayoutOptions

FieldTypeDefaultDescription
sidebarTplTemplateRef<unknown>-The sidebar content, rendered in the <aside>.
headerTplTemplateRef<unknown>-A header above the sidebar and the content.
sidebarPosition'left' | 'right''left''right' renders the sidebar after the content.
titlestring-Preset only: an <h1> in the header zone when headerTpl is not set. The standard ignores it.
condensedbooleanfalsePreset only: narrows the sidebar from w-64 to w-16 (the sidebar content is not changed). The standard ignores it.
mobileBreakpointSmartSidebarLayoutMobileBreakpoint-Not read by the built-in implementations; available to a custom implementation.

SmartSidebarLayoutMobileBreakpoint is 'sm' | 'md' | 'lg'.

InjectionToken that allows replacing the default SidebarLayoutStandardComponent with a custom implementation. Provide a component class extending SidebarLayoutBaseComponent under SIDEBAR_LAYOUT_STANDARD_COMPONENT_TOKEN; every <smart-sidebar-layout> below that injector renders it.

Extending the base class

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

import {
  ISidebarLayoutOptions,
  SIDEBAR_LAYOUT_STANDARD_COMPONENT_TOKEN,
  SidebarLayoutBaseComponent,
  SidebarLayoutComponent,
} from '@smartsoft001/angular';

@Component({
  selector: 'docs-custom-sidebar-layout',
  template: `
    <div
      [class]="containerClasses()"
      [attr.data-position]="options()?.sidebarPosition ?? 'left'"
    >
      <aside class="docs-sidebar-layout__sidebar">
        @if (sidebarTpl()) {
          <ng-container [ngTemplateOutlet]="sidebarTpl()!" />
        }
      </aside>

      <main class="docs-sidebar-layout__main">
        @if (headerTpl()) {
          <header class="docs-sidebar-layout__header">
            <ng-container [ngTemplateOutlet]="headerTpl()!" />
          </header>
        } @else if (options()?.title) {
          <h1 class="docs-sidebar-layout__title">{{ options()?.title }}</h1>
        }

        <!-- The content projected into <smart-sidebar-layout> lands here. -->
        <div class="docs-sidebar-layout__body">
          <ng-content />
        </div>
      </main>
    </div>
  `,
  imports: [NgTemplateOutlet],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomSidebarLayoutComponent extends SidebarLayoutBaseComponent {
  readonly sidebarTpl = computed(
    () => this.options()?.sidebarTpl as TemplateRef<unknown> | undefined,
  );

  readonly headerTpl = computed(
    () => this.options()?.headerTpl as TemplateRef<unknown> | undefined,
  );

  readonly containerClasses = computed(() => {
    const classes = ['docs-sidebar-layout'];
    if (this.options()?.condensed)
      classes.push('docs-sidebar-layout--condensed');
    const extra = this.cssClass();
    if (extra) classes.push(extra);
    return classes.join(' ');
  });
}

@Component({
  selector: 'docs-sidebar-layout-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [SidebarLayoutComponent],
  // The token swaps the standard layout for the custom one everywhere below
  // this component, so consumers keep writing `<smart-sidebar-layout>`.
  providers: [
    {
      provide: SIDEBAR_LAYOUT_STANDARD_COMPONENT_TOKEN,
      useValue: CustomSidebarLayoutComponent,
    },
  ],
  template: `
    <ng-template #sidebar>
      <nav aria-label="Main">
        <a href="#">Overview</a>
        <a href="#">Team</a>
        <a href="#">Projects</a>
      </nav>
    </ng-template>

    <smart-sidebar-layout [options]="buildOptions(sidebar)">
      <p>Main content of the page.</p>
    </smart-sidebar-layout>
  `,
})
export class SidebarLayoutCustomExampleComponent {
  // A factory because an Angular template expression cannot spread the
  // TemplateRef declared above into an object literal.
  buildOptions(sidebar: TemplateRef<unknown>): ISidebarLayoutOptions {
    return {
      title: 'Dashboard',
      sidebarTpl: sidebar,
      sidebarPosition: 'left',
      condensed: false,
    };
  }
}

Preset

SidebarLayoutPresetComponent (smart-sidebar-layout-preset) is a styled, drop-in replacement for SidebarLayoutStandardComponent. It extends the standard component (reusing isRightSidebar) and applies a Tailwind shell where every utility is smart:-prefixed with explicit smart:dark:* variants.

The structure is listed below.

  • Root: full-height gray page (smart:min-h-full smart:bg-gray-50 smart:dark:bg-gray-900); cssClass is merged onto it.
  • Optional header zone (data-role="header"): rendered only when options.headerTpl or options.title is set. Styled like the stacked-layout preset header (white bg, smart:border-b, dark gray-800). Falls back to an <h1> (data-role="title") when only title is given.
  • Row (data-role="row"): a flex container. sidebarPosition: 'right' adds smart:flex-row-reverse.
  • Sidebar <aside> (data-role="sidebar"): white, smart:shrink-0, smart:w-64 (or smart:w-16 when options.condensed). Border is smart:border-e (left sidebar) or smart:border-s (right sidebar).
  • Content <main> (data-role="content"): gray page surface with padding; projects <ng-content>.

No new ISidebarLayoutOptions fields — the preset consumes the existing title, headerTpl, sidebarTpl, sidebarPosition, and condensed.

The preset declares cssClass without the class alias: bind [cssClass] when you use <smart-sidebar-layout-preset> directly. On <smart-sidebar-layout> pass class as usual.

The class recipes are internal to the preset and not exported.

Provide SidebarLayoutPresetComponent under SIDEBAR_LAYOUT_STANDARD_COMPONENT_TOKEN to restyle every <smart-sidebar-layout>, or register every preset of the library at once with provideSmartPresets().

Documented gap: options.mobileBreakpoint is not read by the preset nor by the standard component it extends.

Source

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

SmartSidebarLayout places a sidebar (options.sidebarTpl, typically SmartSidebarNavigation) beside the main content (children), with an optional header zone (headerTpl, or title in the preset). sidebarPosition: 'right' puts the sidebar after the content; condensed narrows it in the preset. The standard rendering is semantic markup (header, aside, main).


Usage

import { ISidebarLayoutOptions, SmartSidebarLayout } from '@smartsoft001/react';

const options: ISidebarLayoutOptions = {
  // The preset shows the title in a header above the sidebar and content.
  title: 'Acme',
  // The sidebar is a plain React node passed inside the options.
  sidebarTpl: (
    <nav aria-label="Main">
      <a href="/dashboard">Dashboard</a>
      <a href="/projects">Projects</a>
      <a href="/team">Team</a>
    </nav>
  ),
};

export function SidebarLayoutUsageExample() {
  // The children become the main content.
  return (
    <SmartSidebarLayout options={options}>
      <h1>Dashboard</h1>
      <p>Welcome back. Here is what changed since yesterday.</p>
    </SmartSidebarLayout>
  );
}

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
SmartSidebarLayoutcomponentRenders the implementation registered as components['sidebar-layout'] on SmartProvider, SmartSidebarLayoutStandard by default.
SmartSidebarLayoutPresetcomponentStyled sidebar-layout variation (preset).
SmartSidebarLayoutStandardcomponentThe default sidebar layout: an optional <header> (options.headerTpl), an <aside> (options.sidebarTpl) and a <main> with children.

The preset's class helpers (getSidebarLayoutRootClasses, getSidebarLayoutHeaderClasses, getSidebarLayoutTitleClasses, getSidebarLayoutRowClasses, getSidebarLayoutSidebarClasses, getSidebarLayoutMainClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartSidebarLayoutProps

PropTypeDefaultDescription
options?ISidebarLayoutOptions—Sidebar, header and sizes.
className?string—Classes on the root element.
children?ReactNode—The main content.

ISidebarLayoutOptions

FieldTypeDefaultDescription
title?string—Heading of the header zone when headerTpl is not set (preset).
sidebarTpl?ReactNode—The sidebar content.
headerTpl?ReactNode—The header zone.
sidebarPosition?'left' | 'right''left'right renders the sidebar after the content.
mobileBreakpoint?SmartSidebarLayoutMobileBreakpoint—Not read by the built-in implementations; available to a custom implementation.
condensed?booleanfalsePreset only: narrows the sidebar from w-64 to w-16 (the sidebar content is not changed).
  • SmartSidebarLayoutMobileBreakpoint: 'sm' \| 'md' \| 'lg'

Replacing the Implementation

SmartSidebarLayout renders the component registered under the 'sidebar-layout' key of SmartProvider's components, and SmartSidebarLayoutStandard when nothing is registered there. Every SmartSidebarLayout below the provider then renders the registered component, which receives the same props.

SmartSidebarLayoutPreset is the styled (preset) implementation: register it under the 'sidebar-layout' key of SmartProvider's components, render it directly in place of SmartSidebarLayout, 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.

import {
  cn,
  ISidebarLayoutOptions,
  SmartProvider,
  SmartSidebarLayout,
  SmartSidebarLayoutProps,
} from '@smartsoft001/react';

// There is no sidebar layout hook: the custom component takes the same props
// as SmartSidebarLayout, the slots and the children included.
export function CustomSidebarLayout({
  options,
  className,
  children,
}: SmartSidebarLayoutProps) {
  return (
    <div
      className={cn(
        'docs-sidebar-layout',
        options?.condensed && 'docs-sidebar-layout--condensed',
        className,
      )}
      data-position={options?.sidebarPosition ?? 'left'}
    >
      <aside className="docs-sidebar-layout__sidebar">
        {options?.sidebarTpl}
      </aside>

      <main className="docs-sidebar-layout__main">
        {options?.headerTpl ? (
          <header className="docs-sidebar-layout__header">
            {options.headerTpl}
          </header>
        ) : (
          options?.title && (
            <h1 className="docs-sidebar-layout__title">{options.title}</h1>
          )
        )}

        <div className="docs-sidebar-layout__body">{children}</div>
      </main>
    </div>
  );
}

// A module constant: a new object on every render would change the context.
const components = { 'sidebar-layout': CustomSidebarLayout };

const options: ISidebarLayoutOptions = {
  title: 'Dashboard',
  sidebarPosition: 'left',
  condensed: false,
  sidebarTpl: (
    <nav aria-label="Main">
      <a href="#">Overview</a>
      <a href="#">Team</a>
      <a href="#">Projects</a>
    </nav>
  ),
};

export function SidebarLayoutCustomExample() {
  // Every SmartSidebarLayout below the provider renders CustomSidebarLayout.
  return (
    <SmartProvider components={components}>
      <SmartSidebarLayout options={options}>
        <p>Main content of the page.</p>
      </SmartSidebarLayout>
    </SmartProvider>
  );
}

Styling

  • The preset renders a full-height gray page, a white header zone and a bordered white sidebar, with smart:dark: variants; the standard rendering has no layout styles.

Source

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