@molecule/app-empty-state-angular

Feature · empty-state · App (browser) · v1.1.4 · Apache-2.0

Angular empty-state and CTA-card primitives

npm install @molecule/app-empty-state-angular

npm · Source on GitHub

How it works

@molecule/app-empty-state-angular is a ready-made empty-state feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { Component } from '@angular/core'
import { Link, useTranslation } from '@molecule/app-angular'
import { EmptyState } from '@molecule/app-empty-state-angular'
import { Icon } from '@molecule/app-ui-angular'

@Component({
  selector: 'app-messages-empty',
  standalone: true,
  imports: [EmptyState, Icon, Link],
  template: `
    <section mol-empty-state [title]="t('messages.empty.title', 'No messages yet')">
      <svg mol-icon-root slot="icon" [name]="'mail'" [size]="40"></svg>
      <p slot="description">
        {{ t('messages.empty.description', 'Messages you send appear here.') }}
      </p>
      <a slot="action" molLink="/compose">{{ t('messages.empty.compose', 'Send one') }}</a>
    </section>
  `,
})
export class MessagesEmpty {
  private readonly i18n = useTranslation()

  t(key: string, defaultValue: string): string {
    return this.i18n.t(key, undefined, { defaultValue })
  }
}

Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular

Reference

Angular empty-state and CTA-card primitives — the counterpart of @molecule/app-empty-state-react: the same props and the same DOM for the same input.

Exports:

  • <EmptyState> — centred icon + title + description + action for lists, feeds, boards, or tables that have no rows to render yet.
  • <CtaCard> — horizontal or vertical promotional card for "next-step" actions inside a page body.

Both components accept a className input so apps can layer per-brand accent chrome (dashed borders, gradient CTAs, tinted backgrounds) on top of the structural layout.

A selected list view passes view={emptyByView[selection]}. Each entry pairs its translated title, optional description, and required action element. Keep those entries beside the view definitions so a personal or filtered list does not reuse the whole collection's empty message. The action can be a router link to another view or a button that clears filters. General empty states keep the existing title and optional action props.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { Component } from '@angular/core'
import { Link, useTranslation } from '@molecule/app-angular'
import { EmptyState } from '@molecule/app-empty-state-angular'
import { Icon } from '@molecule/app-ui-angular'

@Component({
  selector: 'app-messages-empty',
  standalone: true,
  imports: [EmptyState, Icon, Link],
  template: `
    <section mol-empty-state [title]="t('messages.empty.title', 'No messages yet')">
      <svg mol-icon-root slot="icon" [name]="'mail'" [size]="40"></svg>
      <p slot="description">
        {{ t('messages.empty.description', 'Messages you send appear here.') }}
      </p>
      <a slot="action" molLink="/compose">{{ t('messages.empty.compose', 'Send one') }}</a>
    </section>
  `,
})
export class MessagesEmpty {
  private readonly i18n = useTranslation()

  t(key: string, defaultValue: string): string {
    return this.i18n.t(key, undefined, { defaultValue })
  }
}

Type

feature

Installation

npm install @molecule/app-empty-state-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

EmptyStateProps

Props accepted by EmptyState — the same props @molecule/app-empty-state-react accepts. Node props are an input (a string, or a TemplateRef for a node value) or projected content: icon, title, description and action are selected by [slot=icon], [slot=title], [slot=description] and [slot=action].

interface EmptyStateProps {
  /** Visual — an icon node as a `TemplateRef`, or `[slot=icon]` projected content. */
  icon?: unknown
  /** Primary heading for a general, unselected collection. */
  title?: unknown
  /** Supporting description shown below the heading. */
  description?: unknown
  /** Optional action for a general empty state. */
  action?: unknown
  /**
   * The selected view's translated message and required recovery element, kept
   * together so a filtered or personal list never reuses the whole
   * collection's empty message. Replaces `title`, `description` and `action`
   * when given.
   */
  view?: {
    /** The selected view's translated heading. */
    title: unknown
    /** The selected view's supporting description. */
    description?: unknown
    /** The selected view's recovery element — a `TemplateRef` holding a router link or a button. */
    action: unknown
  }
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
  /** Override outer wrapper classes (for per-app dashed-border, background, padding, etc.). */
  className?: string
  /** Override the icon-badge wrapper classes. */
  iconWrapperClassName?: string
}

CtaCardProps

Props accepted by CtaCard — the same props @molecule/app-empty-state-react accepts. Node props are an input (a string, or a TemplateRef for a node value) or projected content: eyebrow, title, description, action and media are selected by [slot=eyebrow], [slot=title], [slot=description], [slot=action] and [slot=media].

interface CtaCardProps {
  /** Optional small eyebrow line above the title — a string, a `TemplateRef`, or `[slot=eyebrow]`. */
  eyebrow?: unknown
  /** Primary heading — a string, a `TemplateRef`, or `[slot=title]`. */
  title?: unknown
  /** Supporting copy — a string, a `TemplateRef`, or `[slot=description]`. */
  description?: unknown
  /** Primary call-to-action — a string, a `TemplateRef`, or `[slot=action]`. */
  action?: unknown
  /** Optional visual / illustration — a `TemplateRef`, or `[slot=media]`. */
  media?: unknown
  /** `'horizontal'` renders media beside text; `'vertical'` stacks them. Defaults to `'vertical'`. */
  layout?: 'vertical' | 'horizontal'
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
  /** Override outer wrapper classes. */
  className?: string
}

Classes

CtaCard

A "soft sell" card used to promote a next-step action inside a page body (e.g., "Connect your bank", "Invite teammates").

Differs from <EmptyState> in being positioned in a list of cards rather than filling the void. Supports a horizontal layout with the media slot beside the text.

The host IS the outer <section> (section[mol-cta-card]), matching React's root exactly. Node props are an input (a string, or a TemplateRef) or projected content: [slot=eyebrow], [slot=title], [slot=description], [slot=action] and [slot=media].

This is the Angular counterpart of @molecule/app-empty-state-react's CtaCard.

@Component({
  selector: 'section[mol-cta-card]',
  standalone: true,
  hostDirectives: [MolPlacement],
  imports: [NgTemplateOutlet],
  inputs: [
    'eyebrow',
    'title',
    'description',
    'action',
    'media',
    'layout',
    'dataMolId',
    'className',
  ],
  host: {
    '[class]': 'classes()',
    '[attr.data-mol-id]': 'dataMolId ?? null',
  },
  // prettier-ignore
  template: `<div #mediaEl [class]="mediaClasses()">@if (templateOf(media); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(media); as t) {{{ t }}}<ng-content select="[slot=media]"></ng-content></div><div [class]="bodyClasses()"><div #eyebrowEl [class]="eyebrowClasses()">@if (templateOf(eyebrow); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(eyebrow); as t) {{{ t }}}<ng-content select="[slot=eyebrow]"></ng-content></div><h3 [class]="titleClasses()">@if (templateOf(title); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(title); as t) {{{ t }}}<ng-content select="[slot=title]"></ng-content></h3><p #descriptionEl>@if (templateOf(description); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(description); as t) {{{ t }}}<ng-content select="[slot=description]"></ng-content></p><div #actionEl [class]="actionClasses()">@if (templateOf(action); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(action); as t) {{{ t }}}<ng-content select="[slot=action]"></ng-content></div></div>`,
})
export class CtaCard {
  /** Optional small eyebrow line above the title — a string, a `TemplateRef`, or `[slot=eyebrow]`. */
  eyebrow?: unknown
  /** Primary heading — a string, a `TemplateRef`, or `[slot=title]`. */
  title?: unknown
  /** Supporting copy — a string, a `TemplateRef`, or `[slot=description]`. */
  description?: unknown
  /** Primary call-to-action — a string, a `TemplateRef`, or `[slot=action]`. */
  action?: unknown
  /** Optional visual / illustration — a `TemplateRef`, or `[slot=media]`. */
  media?: unknown
  /** `'horizontal'` renders media beside text; `'vertical'` stacks them. Defaults to `'vertical'`. */
  layout?: CtaCardProps['layout']
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
  /** Override outer wrapper classes. */
  className?: string

  /** The optional media wrapper (the projected media lands here). */
  @ViewChild('mediaEl') private mediaEl?: ElementRef<HTMLElement>
  /** The optional eyebrow wrapper (the projected eyebrow lands here). */
  @ViewChild('eyebrowEl') private eyebrowEl?: ElementRef<HTMLElement>
  /** The optional description paragraph (the projected description lands here). */
  @ViewChild('descriptionEl') private descriptionEl?: ElementRef<HTMLElement>
  /** The optional action wrapper (the projected action lands here). */
  @ViewChild('actionEl') private actionEl?: ElementRef<HTMLElement>

  /** Whether a `[slot=media]` projection landed. */
  private readonly mediaProjected = signal(false)
  /** Whether a `[slot=eyebrow]` projection landed. */
  private readonly eyebrowProjected = signal(false)
  /** Whether a `[slot=description]` projection landed. */
  private readonly descriptionProjected = signal(false)
  /** Whether a `[slot=action]` projection landed. */
  private readonly actionProjected = signal(false)

  constructor() {
    usePlacement((hasContent) => this.reconcile(hasContent))
  }

  /**
   * The current class map.
   * @returns The UIClassMap.
   */
  cm(): UIClassMap {
    return getClassMap()
  }

  /**
   * The layout direction (React's `layout === 'horizontal' ? 'row' : 'col'`).
   * @returns True for the horizontal layout.
   */
  horizontal(): boolean {
    return this.layout === 'horizontal'
  }

  /**
   * The host's class list (React's root `<section>` classes).
   * @returns The class string.
   */
  classes(): string {
    const cm = this.cm()
    return cm.cn(
      cm.flex({
        direction: this.horizontal() ? 'row' : 'col',
        align: this.horizontal() ? 'center' : 'stretch',
        gap: 'md',
      }),
      cm.sp('p', 6),
      this.className,
    )
  }

  /**
   * The media wrapper's class list.
   * @returns The class string.
   */
  mediaClasses(): string {
    return this.cm().cn(this.cm().shrink0)
  }

  /**
   * The text column's class list.
   * @returns The class string.
   */
  bodyClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.flex1, cm.stack(2))
  }

  /**
   * The eyebrow's class list.
   * @returns The class string.
   */
  eyebrowClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('xs'), cm.fontWeight('semibold'))
  }

  /**
   * The heading's class list.
   * @returns The class string.
   */
  titleClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('xl'), cm.fontWeight('bold'))
  }

  /**
   * The action wrapper's class list.
   * @returns The class string.
   */
  actionClasses(): string {
    return this.cm().sp('mt', 2)
  }

  /**
   * A node value as a template, when the caller passed one.
   * @param value - The prop value.
   * @returns The template, or null for text.
   */
  templateOf(value: unknown): TemplateRef<unknown> | null {
    return isTemplate(value) ? value : null
  }

  /**
   * A node value as text, when the caller passed one.
   * @param value - The prop value.
   * @returns The text, or null for a template.
   */
  textOf(value: unknown): string | null {
    return textOf(value)
  }

  /**
   * Whether the media wrapper renders.
   * @returns True when a media node or a projected media is present.
   */
  showMedia(): boolean {
    return rendersNode(this.media) || this.mediaProjected()
  }

  /**
   * Whether the eyebrow renders.
   * @returns True when an eyebrow node or a projected eyebrow is present.
   */
  showEyebrow(): boolean {
    return rendersNode(this.eyebrow) || this.eyebrowProjected()
  }

  /**
   * Whether the description renders.
   * @returns True when a description node or a projected description is present.
   */
  showDescription(): boolean {
    return rendersNode(this.description) || this.descriptionProjected()
  }

  /**
   * Whether the action renders.
   * @returns True when an action node or a projected action is present.
   */
  showAction(): boolean {
    return rendersNode(this.action) || this.actionProjected()
  }

  /**
   * Reads the projected capture points and reconciles the optional wrappers.
   *
   * @param hasContent - Reads whether a slot has content.
   */
  reconcile(hasContent: SlotReader): void {
    const media = this.mediaEl?.nativeElement
    if (media) this.mediaProjected.set(hasContent(media))
    const eyebrow = this.eyebrowEl?.nativeElement
    if (eyebrow) this.eyebrowProjected.set(hasContent(eyebrow))
    const description = this.descriptionEl?.nativeElement
    if (description) this.descriptionProjected.set(hasContent(description))
    const action = this.actionEl?.nativeElement
    if (action) this.actionProjected.set(hasContent(action))
    setElementPresent(media, this.showMedia())
    setElementPresent(eyebrow, this.showEyebrow())
    setElementPresent(description, this.showDescription())
    setElementPresent(action, this.showAction())
  }
}

EmptyState

Generic centred empty-state panel for lists, feeds, boards, and tables.

Renders a vertical stack of [icon, title, description, action]. Typography and spacing come from the wired ClassMap; per-app accent chrome (dashed borders, tinted backgrounds, gradient CTAs) is passed via className on the outer element.

The host IS the outer <section> (section[mol-empty-state]), matching React's root exactly. Node props are an input (a string, or a TemplateRef) or projected content: [slot=icon], [slot=title], [slot=description] and [slot=action].

This is the Angular counterpart of @molecule/app-empty-state-react.

@Component({
  selector: 'section[mol-empty-state]',
  standalone: true,
  hostDirectives: [MolPlacement],
  imports: [NgTemplateOutlet],
  inputs: [
    'icon',
    'title',
    'description',
    'action',
    'view',
    'dataMolId',
    'className',
    'iconWrapperClassName',
  ],
  host: {
    '[class]': 'classes()',
    '[attr.data-mol-id]': 'dataMolId ?? null',
  },
  // prettier-ignore
  template: `<div #iconEl [class]="iconWrapperClasses()">@if (templateOf(icon); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(icon); as t) {{{ t }}}<ng-content select="[slot=icon]"></ng-content></div><h3 [class]="titleClasses()">@if (templateOf(content().title); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(content().title); as t) {{{ t }}}<ng-content select="[slot=title]"></ng-content></h3><p #descriptionEl [class]="descriptionClasses()">@if (templateOf(content().description); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(content().description); as t) {{{ t }}}<ng-content select="[slot=description]"></ng-content></p><div #actionEl>@if (templateOf(content().action); as tpl) {<ng-container [ngTemplateOutlet]="tpl" />} @else if (textOf(content().action); as t) {{{ t }}}<ng-content select="[slot=action]"></ng-content></div>`,
})
export class EmptyState {
  /** Visual — an icon node as a `TemplateRef`, a string, or `[slot=icon]` content. */
  icon?: unknown
  /** Primary heading for a general, unselected collection. */
  title?: unknown
  /** Supporting description shown below the heading. */
  description?: unknown
  /** Optional action for a general empty state. */
  action?: unknown
  /** The selected view's translated message and required recovery element. */
  view?: EmptyStateProps['view']
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
  /** Override outer wrapper classes (for per-app dashed-border, background, padding, etc.). */
  className?: string
  /** Override the icon-badge wrapper classes. */
  iconWrapperClassName?: string

  /** The optional icon badge (the projected icon lands here). */
  @ViewChild('iconEl') private iconEl?: ElementRef<HTMLElement>
  /** The optional description paragraph (the projected description lands here). */
  @ViewChild('descriptionEl') private descriptionEl?: ElementRef<HTMLElement>
  /** The action's capture point (the projected action lands here). */
  @ViewChild('actionEl') private actionEl?: ElementRef<HTMLElement>

  /** Whether a `[slot=icon]` projection landed. */
  private readonly iconProjected = signal(false)
  /** Whether a `[slot=description]` projection landed. */
  private readonly descriptionProjected = signal(false)
  /** Whether a `[slot=action]` projection landed. */
  private readonly actionProjected = signal(false)

  constructor() {
    usePlacement((hasContent) => this.reconcile(hasContent))
  }

  /**
   * The current class map.
   * @returns The UIClassMap.
   */
  cm(): UIClassMap {
    return getClassMap()
  }

  /**
   * The host's class list (React's root `<section>` classes).
   * @returns The class string.
   */
  classes(): string {
    const cm = this.cm()
    return cm.cn(
      cm.flex({ direction: 'col', align: 'center', justify: 'center' }),
      cm.textCenter,
      cm.sp('p', 12),
      this.className,
    )
  }

  /**
   * The icon badge's class list.
   * @returns The class string.
   */
  iconWrapperClasses(): string {
    const cm = this.cm()
    return cm.cn(
      cm.w(20),
      cm.h(20),
      cm.roundedFull,
      cm.flex({ align: 'center', justify: 'center' }),
      cm.sp('mb', 6),
      this.iconWrapperClassName,
    )
  }

  /**
   * The heading's class list.
   * @returns The class string.
   */
  titleClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('2xl'), cm.fontWeight('bold'), cm.sp('mb', 2))
  }

  /**
   * The description paragraph's class list (React's `mb` follows a present action).
   * @returns The class string.
   */
  descriptionClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.maxW('md'), cm.sp('mb', this.showAction() ? 6 : 0))
  }

  /**
   * The message to render: the selected view, or the general props.
   * @returns The title, description and action nodes.
   */
  content(): { title?: unknown; description?: unknown; action?: unknown } {
    return this.view ?? { title: this.title, description: this.description, action: this.action }
  }

  /**
   * A node value as a template, when the caller passed one.
   * @param value - The prop value.
   * @returns The template, or null for text.
   */
  templateOf(value: unknown): TemplateRef<unknown> | null {
    return isTemplate(value) ? value : null
  }

  /**
   * A node value as text, when the caller passed one.
   * @param value - The prop value.
   * @returns The text, or null for a template.
   */
  textOf(value: unknown): string | null {
    return textOf(value)
  }

  /**
   * Whether the icon badge renders.
   * @returns True when an icon text/template input or a projected icon is present.
   */
  showIcon(): boolean {
    return rendersNode(this.icon) || this.iconProjected()
  }

  /**
   * Whether the description paragraph renders.
   * @returns True when a description content node or a projected description is present.
   */
  showDescription(): boolean {
    return rendersNode(this.content().description) || this.descriptionProjected()
  }

  /**
   * Whether the action renders (React's truthiness check on `content.action`).
   * @returns True when an action content node or a projected action is present.
   */
  showAction(): boolean {
    return rendersNode(this.content().action) || this.actionProjected()
  }

  /**
   * Reads the projected capture points and reconciles the optional wrappers.
   *
   * @param hasContent - Reads whether a slot has content.
   */
  reconcile(hasContent: SlotReader): void {
    const icon = this.iconEl?.nativeElement
    if (icon) this.iconProjected.set(hasContent(icon))
    const description = this.descriptionEl?.nativeElement
    if (description) this.descriptionProjected.set(hasContent(description))
    const action = this.actionEl?.nativeElement
    if (action) this.actionProjected.set(hasContent(action))
    setElementPresent(icon, this.showIcon())
    setElementPresent(description, this.showDescription())
    // React renders `{content.action}` bare: the action's content stands in the capture
    // point's place and the point itself leaves the page.
    if (action) {
      placeContentBefore(action, action)
      setElementPresent(action, false)
    }
  }
}

Injection Notes

Requirements

Peer dependencies:

  • @angular/common ^22.0.0
  • @angular/core ^22.0.0
  • @angular/platform-browser ^22.0.0
  • @molecule/app-angular ^3.14.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-angular ^1.1.0

Runtime Dependencies

  • @angular/common

  • @angular/core

  • @angular/platform-browser

  • @molecule/app-angular

  • @molecule/app-ui

  • @molecule/app-ui-angular

  • Name collision: @molecule/app-ui-angular also exports an EmptyState (the ClassMap-token variant driven by cm.emptyState*). Use THAT one for plain framework-styled empty states; use THIS package when you want the circular icon badge (iconWrapperClassName), per-brand chrome via className, a dataMolId, or the companion <CtaCard>. If you import both packages, alias one import to avoid the clash.

  • All text arrives via props — translate with your t() calls; this package has no locale bond of its own.

  • Styling resolves through getClassMap() — requires a wired ClassMap bond (standard molecule app setup).

  • Node props are inputs (a string, or a TemplateRef) or projected content selected by [slot=<name>]; components accept either.