Stacked Layout

The <smart-stacked-layout> component provides a top-to-bottom application shell with a top navigation bar, an optional page header section, and a main content region. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract StackedLayoutBaseComponent defines the shared API — optional IStackedLayoutOptions and cssClass (alias class). StackedLayoutStandardComponent is a barebones placeholder concrete implementation. StackedLayoutComponent is the public wrapper that renders StackedLayoutStandardComponent by default and accepts a custom replacement via STACKED_LAYOUT_STANDARD_COMPONENT_TOKEN.


Usage

<ng-template #navTpl>
  <a href="#dashboard">Dashboard</a>
  <a href="#projects">Projects</a>
  <a href="#reports">Reports</a>
</ng-template>

<smart-stacked-layout [options]="options()">
  <p>You have 3 active projects this sprint.</p>
</smart-stacked-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

StackedLayoutComponent (<smart-stacked-layout>)

Main wrapper component. Renders StackedLayoutStandardComponent by default. When STACKED_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).

StackedLayoutStandardComponent (<smart-stacked-layout-standard>)

Barebones native-HTML implementation. Renders a wrapper <div data-container-width="…"> with a top <header> containing a <nav>, an optional second <header> for the page heading section (options.headerTpl when provided, otherwise <h1 data-role="title">{{ options.title }}</h1> when options.title is set), and a <main> element that projects <ng-content>. The external cssClass is applied to the wrapper. It does not include Tailwind UI styling.

StackedLayoutBaseComponent (abstract)

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

API

Inputs

InputTypeDefaultDescription
optionsInputSignal<IStackedLayoutOptions | undefined>-Optional configuration (title, navTpl, headerTpl, container)
classInputSignal<string>''External CSS classes (alias for cssClass)

IStackedLayoutOptions

FieldTypeDefaultDescription
titlestring-Page title, rendered as <h1 data-role="title"> when headerTpl is not set.
navTplTemplateRef<unknown>-Navigation at the top (inside the <nav>).
headerTplTemplateRef<unknown>-The page header beneath the navigation; wins over title.
containerWidthSmartStackedLayoutContainerWidth'xl'Width of the header and content containers in the preset (see the mapping below); the standard only exposes it as data-container-width.

SmartStackedLayoutContainerWidth is 'sm' | 'md' | 'lg' | 'xl' | 'full'.

STACKED_LAYOUT_STANDARD_COMPONENT_TOKEN

InjectionToken that allows replacing the default StackedLayoutStandardComponent with a custom implementation. Provide a component class extending StackedLayoutBaseComponent under STACKED_LAYOUT_STANDARD_COMPONENT_TOKEN; every <smart-stacked-layout> below that injector renders it.

Extending the base class

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

import {
  IStackedLayoutOptions,
  STACKED_LAYOUT_STANDARD_COMPONENT_TOKEN,
  StackedLayoutBaseComponent,
  StackedLayoutComponent,
} from '@smartsoft001/angular';

@Component({
  selector: 'docs-custom-stacked-layout',
  template: `
    <div [class]="containerClasses()">
      <header class="docs-stacked-layout__nav">
        @if (options()?.navTpl) {
          <nav>
            <ng-container [ngTemplateOutlet]="options()!.navTpl!" />
          </nav>
        }
      </header>

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

      <!-- The content projected into <smart-stacked-layout> lands here. -->
      <main class="docs-stacked-layout__main">
        <ng-content />
      </main>
    </div>
  `,
  imports: [NgTemplateOutlet],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomStackedLayoutComponent extends StackedLayoutBaseComponent {
  containerClasses = computed(() =>
    [
      'docs-stacked-layout',
      `docs-stacked-layout--${this.options()?.containerWidth ?? 'full'}`,
      this.cssClass(),
    ]
      .filter(Boolean)
      .join(' '),
  );
}

@Component({
  selector: 'docs-stacked-layout-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [StackedLayoutComponent],
  // The token swaps the standard layout for the custom one everywhere below
  // this component, so consumers keep writing `<smart-stacked-layout>`.
  providers: [
    {
      provide: STACKED_LAYOUT_STANDARD_COMPONENT_TOKEN,
      useValue: CustomStackedLayoutComponent,
    },
  ],
  template: `
    <ng-template #navTpl>
      <a href="#dashboard">Dashboard</a>
      <a href="#team">Team</a>
      <a href="#projects">Projects</a>
    </ng-template>

    <smart-stacked-layout [options]="options()">
      <p>Main content of the page.</p>
    </smart-stacked-layout>
  `,
})
export class StackedLayoutCustomExampleComponent {
  private navTpl = viewChild.required<TemplateRef<unknown>>('navTpl');

  // The navigation slot is a TemplateRef, so it is read from the host view.
  // computed() keeps the object identity stable between checks.
  options = computed<IStackedLayoutOptions>(() => ({
    title: 'Projects',
    containerWidth: 'xl',
    navTpl: this.navTpl(),
  }));
}

HyperUI preset

StackedLayoutPresetComponent (<smart-stacked-layout-preset>) is the HyperUI-styled drop-in for StackedLayoutStandardComponent. It uses the same IStackedLayoutOptions API — no interface changes, no new options fields — and delivers the page scaffold in the HyperUI container rhythm.

  • Page root (data-role="root"): full-height gray surface — smart:min-h-full smart:bg-gray-50 smart:dark:bg-gray-900. The external cssClass is merged here.
  • Header zone: white bar (smart:bg-white smart:shadow-sm smart:dark:bg-gray-800 smart:dark:border-b smart:dark:border-gray-700) whose inner container (data-role="header", smart:py-4) renders navTpl (data-role="nav"), then headerTpl if present, else title as an <h1 data-role="title"> fallback.
  • Main content (data-role="content", smart:py-8): the container wraps a bordered content card (smart:rounded-lg smart:border smart:bg-white smart:p-4 smart:shadow-sm smart:sm:p-6 smart:dark:bg-gray-800) that projects <ng-content> — identical projection semantics to the standard component.

containerWidth mapping

Both the header and content containers share the base smart:mx-auto smart:px-4 smart:sm:px-6 smart:lg:px-8 plus a max-width from options.containerWidth, as listed below.

containerWidthmax-width class
smsmart:max-w-3xl
mdsmart:max-w-5xl
lgsmart:max-w-6xl
xl (default/unset)smart:max-w-7xl
fullsmart:max-w-none

Token registration

Provide StackedLayoutPresetComponent under STACKED_LAYOUT_STANDARD_COMPONENT_TOKEN to restyle every <smart-stacked-layout>, or register every preset of the library at once with provideSmartPresets(). The preset declares cssClass without the class alias: bind [cssClass] when you use <smart-stacked-layout-preset> directly; on <smart-stacked-layout> pass class as usual.

Documented gaps

The preset delivers the page scaffold only. For "content + image" sections, project <smart-section-heading> blocks (with the section-heading preset) into the stacked-layout content region.

Source

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

SmartStackedLayout stacks a page vertically: navigation on top (options.navTpl, typically SmartNavbar), a header (headerTpl, or title as a fallback) and the main content (children). options.containerWidth sets the width of the content container in the preset (xl by default; the standard exposes it as data-container-width). The preset wraps children in a bordered content card.


Usage

import { IStackedLayoutOptions, SmartStackedLayout } from '@smartsoft001/react';

const options: IStackedLayoutOptions = {
  title: 'Projects',
  navTpl: (
    <>
      <a href="#dashboard">Dashboard</a>
      <a href="#projects">Projects</a>
      <a href="#reports">Reports</a>
    </>
  ),
};

export function StackedLayoutUsageExample() {
  return (
    <SmartStackedLayout options={options}>
      <p>You have 3 active projects this sprint.</p>
    </SmartStackedLayout>
  );
}

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
SmartStackedLayoutcomponentRenders the implementation registered as components['stacked-layout'] on SmartProvider, SmartStackedLayoutStandard by default.
SmartStackedLayoutPresetcomponentHyperUI-styled stacked-layout variation (preset).
SmartStackedLayoutStandardcomponentBarebones native-HTML stacked layout.

The preset's class helpers (getStackedLayoutRootClasses, getStackedLayoutHeaderZoneClasses, getStackedLayoutContainerClasses, getStackedLayoutTitleClasses, getStackedLayoutContentCardClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartStackedLayoutProps

PropTypeDefaultDescription
options?IStackedLayoutOptions—Navigation, header and width.
className?string—Classes on the root element.
children?ReactNode—The main content.

IStackedLayoutOptions

FieldTypeDefaultDescription
title?string—Page title (<h1 data-role="title">) when headerTpl is not set.
navTpl?ReactNode—Navigation at the top.
headerTpl?ReactNode—The header; wins over title.
containerWidth?SmartStackedLayoutContainerWidth'xl'Width of the content container (preset).
  • SmartStackedLayoutContainerWidth: 'sm' \| 'md' \| 'lg' \| 'xl' \| 'full'

Replacing the Implementation

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

SmartStackedLayoutPreset is the styled (preset) implementation: register it under the 'stacked-layout' key of SmartProvider's components, render it directly in place of SmartStackedLayout, 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 {
  IStackedLayoutOptions,
  SmartProvider,
  SmartStackedLayout,
  SmartStackedLayoutProps,
} from '@smartsoft001/react';

// The stacked layout has no behaviour hook: an implementation only renders
// its props, and children reach it like every other prop.
export function CustomStackedLayout({
  options,
  className,
  children,
}: SmartStackedLayoutProps) {
  const containerClasses = [
    'docs-stacked-layout',
    `docs-stacked-layout--${options?.containerWidth ?? 'full'}`,
    className,
  ]
    .filter(Boolean)
    .join(' ');

  return (
    <div className={containerClasses}>
      <header className="docs-stacked-layout__nav">
        {options?.navTpl && <nav>{options.navTpl}</nav>}
      </header>

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

      <main className="docs-stacked-layout__main">{children}</main>
    </div>
  );
}

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

const options: IStackedLayoutOptions = {
  title: 'Projects',
  containerWidth: 'xl',
  navTpl: (
    <>
      <a href="#dashboard">Dashboard</a>
      <a href="#team">Team</a>
      <a href="#projects">Projects</a>
    </>
  ),
};

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

Styling

  • The standard rendering is barebones HTML (header > nav, main, data-container-width); the preset adds the gray page, the white header zone and the content card, with smart:dark: variants.

Source

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