Page

The <smart-page> component provides a flexible page-header/layout wrapper with a map-based variant dispatch mechanism. It renders a default PageStandardComponent which can be extended with additional variants via PAGE_VARIANT_COMPONENTS_TOKEN. Projection is driven by TemplateRef slots declared on IPageOptions, plus a default <ng-content> fallback for the body.


Usage

<smart-page [options]="options">
  <p>12 people have access to this workspace.</p>
</smart-page>

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

PageComponent (<smart-page>)

Main wrapper component. Always renders via NgComponentOutlet, forwarding options and the class. Looks up the target variant component from a merged map of baseMap + the optional PAGE_VARIANT_COMPONENTS_TOKEN map, keyed by options.variant (default 'standard'). Falls back to PageStandardComponent when the variant is unknown. Captures <ng-content> into a TemplateRef and passes it to the target component as options.bodyTpl unless the caller provided an explicit bodyTpl.

PageStandardComponent (<smart-page-standard>)

Default concrete implementation and the value for baseMap['standard']. Renders a Tailwind-styled header with the translated title, optional back button, optional search input, endButtons via <smart-button>, and a body section driven by options.bodyTpl. Header and body sit in one root element (data-role="page") that takes the class (cssClass, declared without the alias like the preset's); of the slot templates it renders only bodyTpl.

PageBaseComponent (abstract)

Abstract base directive for extending custom page variants. Exposes options, cssClass (input alias class), back() (Location.back()), isMobile, and a contentTpl view child for variants that need to re-project the main content. It sets the host height to 100%.

API

Inputs

InputTypeDefaultDescription
optionsInputSignal<IPageOptions|null>-Page configuration (see IPageOptions)
classInputSignal<string>''External CSS classes (alias for cssClass), forwarded to the variant; the standard and preset variants put them on their root (data-role="page")

SmartPageVariant

Variant identifier used to select a concrete page component from the merged variant map. The intersection with (string & {}) keeps 'standard' as a suggested literal while allowing arbitrary custom keys.

IPageOptions

FieldTypeDefaultDescription
titlestringrequiredPage title, passed through TranslatePipe (a key or text).
hideHeaderboolean-Hides the header block (title, buttons, search; in the preset also the breadcrumbs, meta and filters rows).
showBackButtonboolean-Renders a back arrow that calls Location.back().
endButtonsArray<IIconButtonOptions>[]Action buttons rendered via <smart-button> (secondary, md).
search{ text: Signal<string>; set: (txt: string) => void }-Inline search input bound to text / set (placeholder: the search translation).
variantSmartPageVariant'standard'Selects which variant component to render.
bodyTplTemplateRef<unknown>the contentExplicit body template; falls back to the projected <ng-content>.
hideMenuButtonboolean-Preset only: hides the decorative menu (hamburger) button, which has no action of its own.
breadcrumbsTplTemplateRef<unknown>-Preset only: breadcrumbs row at the top of the header.
subtitleTplTemplateRef<unknown>-Preset only: subtitle under the title.
avatarTplTemplateRef<unknown>-Preset only: avatar next to the title.
logoTplTemplateRef<unknown>-Preset only: logo next to the title.
metaTplTemplateRef<unknown>-Preset only: meta row (status, timestamps, ...) under the title.
statsTplTemplateRef<unknown>-Preset only: stats, in the meta row.
bannerTplTemplateRef<unknown>-Preset only: full-width strip above the header.
filtersTplTemplateRef<unknown>-Preset only: filters bar under the header.
sidebarTplTemplateRef<unknown>-Preset only: an <aside> next to the body card (lg and up).
navTplTemplateRef<unknown>-Not read by the built-in implementations; available to a custom implementation.

IIconButtonOptions

FieldTypeDefaultDescription
iconstringrequiredIdentifier of the button (the @for track key, so keep it unique).
textstring-Button label (translated).
handler() => void-Click handler.
numbernumber-A count badge.
disabled$Observable<boolean>-Disables the button while it emits true.
componentany-Not read by the built-in implementations; available to a custom implementation (e.g. a popover body).
type'default' | 'popover'-Not read by the built-in implementations; available to a custom implementation.

PAGE_VARIANT_COMPONENTS_TOKEN

InjectionToken from @smartsoft001/angular, of type Partial<Record<SmartPageVariant, Type<PageBaseComponent>>>. Provide a map to register additional variants. The map is merged on top of baseMap (which contains the default { standard: PageStandardComponent }), so you can both add new variants and override 'standard'.

Extending the base class

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

import {
  IPageOptions,
  PAGE_VARIANT_COMPONENTS_TOKEN,
  PageBaseComponent,
  PageComponent,
  SmartPageVariant,
} from '@smartsoft001/angular';

/**
 * A custom page shell built on `PageBaseComponent`.
 *
 * The base contributes the `options` and `class` inputs, the `back()` helper
 * that delegates to `Location`, and the `appService` / `hardwareService`
 * injections; the implementation owns the chrome around the body.
 */
@Component({
  selector: 'docs-custom-page',
  template: `
    <div [class]="containerClasses()">
      @if (!options()?.hideHeader) {
        @if (options()?.breadcrumbsTpl) {
          <nav class="docs-page__breadcrumbs" aria-label="Breadcrumb">
            <ng-container [ngTemplateOutlet]="options()!.breadcrumbsTpl!" />
          </nav>
        }

        <header class="docs-page__header">
          @if (options()?.showBackButton) {
            <button
              type="button"
              class="docs-page__back"
              aria-label="Go back"
              (click)="back()"
            >
              &larr;
            </button>
          }
          <h1 class="docs-page__title">{{ options()?.title }}</h1>
        </header>
      }

      <!--
        smart-page wraps its own ng-content in a TemplateRef and passes it down
        as options.bodyTpl, so the implementation decides where the projected
        content goes (the other wrappers hand it to the default ng-content).
      -->
      <section class="docs-page__body">
        @if (options()?.bodyTpl; as bodyTpl) {
          <ng-container [ngTemplateOutlet]="bodyTpl" />
        }
      </section>
    </div>
  `,
  imports: [NgTemplateOutlet],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomPageComponent extends PageBaseComponent {
  containerClasses = computed(() =>
    ['docs-page', this.isMobile ? 'docs-page--mobile' : '', this.cssClass()]
      .filter(Boolean)
      .join(' '),
  );
}

/**
 * The page wrapper resolves its shell from a map of variants rather than from
 * a single standard-component token, so the implementation is registered under
 * the variant name that `IPageOptions.variant` asks for. The map is merged
 * over the built-in one, so `'standard'` keeps working for everything else.
 */
const DOCS_PAGE_VARIANT_COMPONENTS: Partial<
  Record<SmartPageVariant, Type<PageBaseComponent>>
> = { docs: CustomPageComponent };

@Component({
  selector: 'docs-page-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [PageComponent],
  providers: [
    {
      provide: PAGE_VARIANT_COMPONENTS_TOKEN,
      useValue: DOCS_PAGE_VARIANT_COMPONENTS,
    },
  ],
  template: `
    <smart-page [options]="options()">
      <p>Account settings and permissions</p>
    </smart-page>

    <ng-template #breadcrumbsTpl>
      <a href="#">Users</a>
      <span aria-hidden="true">/</span>
      <span>Alice Johnson</span>
    </ng-template>
  `,
})
export class PageCustomExampleComponent {
  breadcrumbsTpl = viewChild<TemplateRef<unknown>>('breadcrumbsTpl');

  options = computed<IPageOptions>(() => ({
    title: 'Alice Johnson',
    variant: 'docs',
    showBackButton: true,
    breadcrumbsTpl: this.breadcrumbsTpl(),
  }));
}

Preset

PagePresetComponent (<smart-page-preset>) is a styled 'preset' variant that extends PageStandardComponent. It renders a full application-shell layout instead of the plain standard header: a bordered <header>, a gray page body and a content card. Every utility is smart:-prefixed with explicit smart:dark:* twins.

Registration

The preset is dispatched by map key 'preset'. Register the ready-made map PAGE_PRESET_VARIANT_COMPONENTS ({ preset: PagePresetComponent }) for PAGE_VARIANT_COMPONENTS_TOKEN and set variant: 'preset' on the pages that should use it; the built-in 'standard' variant is untouched. provideSmartPresets() instead registers the preset for both 'standard' and 'preset', so every page renders it.

Zones (all keyed by data-role)

data-roleSourceNotes
pageouter wrapperbg-gray-50 dark:bg-gray-900; picks up cssClass.
bannerbannerTplFull-width strip above the header.
headerheader shellSkipped entirely when hideHeader is true.
breadcrumbsbreadcrumbsTplRow at the top of the header container.
titletitle (h1) + subtitleTplTitle row also holds back button, avatar/logo, actions.
actionssearch + endButtonsRight side of the title row; hidden when both are absent.
metametaTpl + statsTplRow under the title; hidden when both are absent.
filtersfiltersTplBar under the header.
sidebarsidebarTplRendered as <aside> in a flex row (lg: and up).
bodybodyTpl / <ng-content>Rendered inside a bordered content card.

The back button (button[data-role="back"]) appears only when showBackButton is true and calls the inherited back(). A hamburger button[data-role="menu-button"] renders unless hideMenuButton is true.

cssClass

The preset declares cssClass without the class alias: on the <smart-page-preset> selector bind [cssClass]; on <smart-page> pass class as usual. External classes land on the data-role="page" wrapper.

Documented gaps

  • hideMenuButton only toggles a decorative hamburger button; there is no menu panel wired to it.
  • Unused slots (bannerTpl, breadcrumbsTpl, metaTpl, statsTpl, filtersTpl, sidebarTpl, avatarTpl, logoTpl, subtitleTpl) simply render nothing when omitted; navTpl is not consumed by this preset (nor by the standard variant).

Source

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

SmartPage lays out a screen: a header with an optional back button, the translated title, an optional search input and the endButtons, followed by the body (children, or options.bodyTpl). Which component renders it depends on options.variant: the component registered under getPageVariantKey(variant) ('page' for 'standard', 'page:<variant>' for the others), else SmartPageStandard. SmartPagePreset is a full application-shell layout that also renders the breadcrumbs, avatar / logo, subtitle, meta, stats, filters, banner and sidebar slots. CRUD list and item screens are built on SmartPage.


Usage

import { useState } from 'react';

import { SmartPage } from '@smartsoft001/react';

export function PageUsageExample() {
  const [searchText, setSearchText] = useState('');

  // The back button goes back through the navigation adapter of SmartProvider.
  return (
    <SmartPage
      options={{
        title: 'Team members',
        showBackButton: true,
        search: { text: searchText, set: setSearchText },
      }}
    >
      <p>12 people have access to this workspace.</p>
    </SmartPage>
  );
}

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
SmartPagecomponentRenders the component registered for options.variant ('standard' when omitted) under getPageVariantKey(variant) on SmartProvider, SmartPageStandard when nothing is registered for it.
SmartPagePresetcomponentStyled page variation (preset).
SmartPageStandardcomponentThe default page rendering: a header with the optional back button, the translated title, the search input and the end buttons, followed by options.bodyTpl.
usePagehookThe page's logic: back() goes to the previous location, through the navigation adapter.
getPageVariantKeyfunctionThe registry key of a page variant: 'page' for 'standard', 'page:<variant>' otherwise.
getPageButtonOptionsfunctionThe SmartButton options of an end button (secondary, md, running its handler).
PAGE_PRESET_VARIANT_COMPONENTSconstStyled page variant preset, keyed by getPageVariantKey(variant).

The preset's class helpers (getPagePageClasses, getPageHeaderClasses, getPageContainerClasses, getPageTitleClasses, getPageBodyCardClasses, getPageIconButtonClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartPageProps

Extends SmartPageVariantProps.

PropTypeDefaultDescription
children?ReactNode—The page body, used when options.bodyTpl is not set.

SmartPageVariantProps

The props of a page variant (what <SmartPage> hands to the resolved component): the options, with bodyTpl already merged with the wrapper's children, and the CSS class.

PropTypeDefaultDescription
options?IPageOptions | null—The page options, with bodyTpl already set from children.
className?string—Classes of the page root (data-role="page").

IPageOptions

FieldTypeDefaultDescription
titlestringrequiredThe page title, passed through the translations (a key or text).
hideHeader?boolean—Hides the header (title, buttons, search).
hideMenuButton?boolean—Preset: hides the menu button (which has no action of its own).
showBackButton?boolean—Shows a back button that calls navigation.back().
endButtons?Array<IIconButtonOptions>[]Buttons at the end of the header: each renders a SmartButton (secondary, md) running handler, labelled with the translated text and a number badge. icon is used as the React key, so keep it unique.
search?{ text: string; set: (txt: string) => void }—A search input bound to text / set (the placeholder is the search translation).
variant?SmartPageVariant'standard'Picks the registered component ('page' or 'page:<variant>').
bodyTpl?ReactNodechildrenThe body; wins over children.
breadcrumbsTpl?ReactNode—Preset: breadcrumbs above the title.
metaTpl?ReactNode—Preset: meta row.
avatarTpl?ReactNode—Preset: avatar next to the title.
bannerTpl?ReactNode—Preset: banner strip above the header.
filtersTpl?ReactNode—Preset: filters bar under the header.
logoTpl?ReactNode—Preset: logo next to the title.
statsTpl?ReactNode—Preset: stats row.
subtitleTpl?ReactNode—Preset: subtitle under the title.
navTpl?ReactNode—Declared; neither SmartPageStandard nor SmartPagePreset renders it.
sidebarTpl?ReactNode—Preset: an <aside> next to the body card.

IIconButtonOptions

A page button.

FieldTypeDefaultDescription
iconstringrequiredIdentifier of the button (the React key of the standard rendering).
text?string—Label (translated).
handler?() => void—Click handler.
component?any—For implementations of your own (e.g. a popover body).
type?'default' | 'popover'—For implementations of your own ('popover').
disabled?boolean—Disables the button.
number?number—A count badge.
  • SmartPageVariant: 'standard' \| (string & {}) — 'standard' or the name of a variant you register.

Replacing the Implementation

SmartPage resolves its component per variant:

options.variantRegistry keyFallback
'standard' (or unset)'page'SmartPageStandard
any other, e.g. 'preset''page:<variant>', e.g. 'page:preset'SmartPageStandard

PAGE_PRESET_VARIANT_COMPONENTS registers SmartPagePreset under 'page:preset' only, so pages opt in with variant: 'preset'. SMART_PRESET_COMPONENTS registers it under 'page' too, so every page renders the preset.

A page variant receives SmartPageVariantProps: the options with bodyTpl already merged from children, and className. Translate options.title yourself (useTranslate()) if the variant should match the standard one.

The usePage hook

The page's logic: back() goes to the previous location, through the navigation adapter.

import {
  IPageOptions,
  SmartPage,
  SmartPageVariantProps,
  SmartProvider,
  usePage,
  useTranslate,
} from '@smartsoft001/react';

/**
 * A custom page shell built on `usePage`: the hook provides `back()`, which
 * goes back through the navigation adapter; the implementation owns the
 * chrome around the body.
 */
export function CustomPage({ options, className }: SmartPageVariantProps) {
  const { back } = usePage();
  const t = useTranslate();

  return (
    <div className={['docs-page', className].filter(Boolean).join(' ')}>
      {!options?.hideHeader && (
        <>
          {options?.breadcrumbsTpl && (
            <nav className="docs-page__breadcrumbs" aria-label="Breadcrumb">
              {options.breadcrumbsTpl}
            </nav>
          )}

          <header className="docs-page__header">
            {options?.showBackButton && (
              <button
                type="button"
                className="docs-page__back"
                aria-label="Go back"
                onClick={back}
              >
                &larr;
              </button>
            )}
            <h1 className="docs-page__title">{t(options?.title ?? '')}</h1>
          </header>
        </>
      )}

      {/* SmartPage hands its children over as options.bodyTpl. */}
      <section className="docs-page__body">{options?.bodyTpl}</section>
    </div>
  );
}

// The page resolves its component per variant: 'page' for 'standard',
// 'page:<variant>' for the others, so 'standard' keeps SmartPageStandard.
// A module constant: a new object on every render would change the context.
const components = { 'page:docs': CustomPage };

const options: IPageOptions = {
  title: 'Alice Johnson',
  variant: 'docs',
  showBackButton: true,
  breadcrumbsTpl: (
    <>
      <a href="#">Users</a>
      <span aria-hidden="true">/</span>
      <span>Alice Johnson</span>
    </>
  ),
};

export function PageCustomExample() {
  return (
    <SmartProvider components={components}>
      <SmartPage options={options}>
        <p>Account settings and permissions</p>
      </SmartPage>
    </SmartProvider>
  );
}
ReturnsTypeDescription
back() => voidGoes to the previous location through the navigation adapter.

Styling

  • SmartPageStandard renders the header and the body in one root element (data-role="page") and puts className on it.
  • SmartPagePreset appends className to its root and renders a gray page body with the content in a card, with smart:dark: variants.

Source

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