@molecule/app-footer-angular

Feature · footer · App (browser) · v1.1.2 · Apache-2.0

App-shell footer with About link, Privacy/Terms modals (i18n-loaded HTML), language picker, and version display

npm install @molecule/app-footer-angular

npm · Source on GitHub

How it works

@molecule/app-footer-angular is a ready-made footer 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 { AppFooter } from '@molecule/app-footer-angular'

@Component({
  selector: 'app-shell',
  standalone: true,
  imports: [AppFooter],
  template: `
    <mol-app-footer
      [appName]="'Bearing'"
      [aboutHref]="'https://bearing.example'"
      [loadContent]="loadLegal"
    />
  `,
})
export class Shell {
  // Lazy-load the app's legal HTML into the i18n catalog before a modal opens.
  readonly loadLegal = async (key: 'privacyPolicy' | 'termsOfService'): Promise<void> => {}
}

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

Reference

Angular app-shell footer — the counterpart of @molecule/app-footer-react: the same props and the same DOM for the same input. About link, Privacy and Terms surfaces (in-place modals or route links), a language-picker modal, and the version display.

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 { AppFooter } from '@molecule/app-footer-angular'

@Component({
  selector: 'app-shell',
  standalone: true,
  imports: [AppFooter],
  template: `
    <mol-app-footer
      [appName]="'Bearing'"
      [aboutHref]="'https://bearing.example'"
      [loadContent]="loadLegal"
    />
  `,
})
export class Shell {
  // Lazy-load the app's legal HTML into the i18n catalog before a modal opens.
  readonly loadLegal = async (key: 'privacyPolicy' | 'termsOfService'): Promise<void> => {}
}

Type

feature

Installation

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

API

Interfaces

AppFooterProps

Props for AppFooter — the same props @molecule/app-footer-react accepts. There are no node props: every prop is data (the component renders no slots).

interface AppFooterProps {
  /** Display name interpolated into the "About {{appName}}" link. */
  appName: string
  /**
   * URL or path for the About link. URLs starting with `http`/`https` are
   * rendered as `<a target="_blank">`; other values are rendered as an
   * internal anchor that navigates through the binding's router (React
   * renders a `react-router` `<Link>`).
   */
  aboutHref: string
  /**
   * How privacy/terms surfaces are presented:
   * - `'modal'` (default) — buttons that open in-place modals with HTML pulled
   *   from the bonded i18n catalog (`content.privacyPolicy` / `content.termsOfService`).
   *   Pass `loadContent` to lazy-load the catalog body before opening.
   * - `'route'` — internal anchors for `/privacy` and `/terms` (React renders
   *   `<Link to>` elements) for apps that render the legal pages on their own routes.
   */
  legalMode?: 'modal' | 'route'
  /**
   * Optional preloader called immediately before the privacy/terms modals
   * open. Only used when `legalMode === 'modal'`. Apps that lazy-load their
   * legal HTML pass `loadContent` from their config; apps that ship the
   * content statically can omit this. In Angular it is an input carrying the
   * function itself.
   */
  loadContent?: AppFooterLoadContent
  /** Path for the Privacy Policy route. Only used when `legalMode === 'route'`. Default: `/privacy`. */
  privacyTo?: string
  /** Path for the Terms of Service route. Only used when `legalMode === 'route'`. Default: `/terms`. */
  termsTo?: string
  /** Extra className on the outer `<footer>` (composed with `cm.footerBar`). */
  className?: string
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
}

Types

AppFooterLoadContent

The preloader React accepts as loadContent — called immediately before the privacy/terms modals open, so an app can lazy-load its legal HTML into the i18n catalog. Only used when legalMode === 'modal'.

type AppFooterLoadContent = (key: 'privacyPolicy' | 'termsOfService') => Promise<void> | void

Classes

AppFooter

AppFooter component.

App-shell footer — About link, Privacy/Terms modals, language picker, version. React's root is a FRAGMENT (the <footer> plus up to three modals portaled into document.body), so the host's content renders in front of the host's place and the host itself leaves the page (placeContentBefore + setElementPresent), matching React's sibling list.

The Privacy/Terms modal bodies render whatever HTML the bonded i18n catalog holds under content.privacyPolicy / content.termsOfService as RAW HTML — React's dangerouslySetInnerHTML trust model (the catalog is app-supplied). The [innerHTML] binding deliberately BYPASSES Angular's sanitizer (bypassSecurityTrustHtml): sanitizing would strip markup and render a different DOM than React. The appName interpolated into that HTML is HTML-escaped first, exactly as React does.

Until the app registers legal content the modals show the footer.legalNotConfigured placeholder — never a silently-blank modal, and never fabricated legal text.

@Component({
  selector: 'mol-app-footer',
  standalone: true,
  imports: [Icon, Link, Modal],
  hostDirectives: [MolPlacement],
  inputs: [
    'appName',
    'aboutHref',
    'legalMode',
    'loadContent',
    'privacyTo',
    'termsTo',
    'className',
    'dataMolId',
  ],
  template: `<footer [class]="footerClasses()" [attr.data-mol-id]="dataMolId ?? null">
      @if (isExternalAbout()) {
        <a [href]="aboutHref" target="_blank" rel="noopener noreferrer" [class]="linkClasses()">
          {{ aboutLabel() }}
        </a>
      } @else {
        <a [molLink]="aboutHref" [class]="linkClasses()">
          {{ aboutLabel() }}
        </a>
      }
      @if (isModalMode()) {
        <button type="button" (click)="openPrivacy()" [class]="buttonClasses()">
          {{ privacyLabel() }}
        </button>
        <button type="button" (click)="openTerms()" [class]="buttonClasses()">
          {{ termsLabel() }}
        </button>
      } @else {
        <a [molLink]="privacyToValue()" [class]="buttonClasses()">
          {{ privacyLabel() }}
        </a>
        <a [molLink]="termsToValue()" [class]="buttonClasses()">
          {{ termsLabel() }}
        </a>
      }
      <button
        type="button"
        (click)="openLanguage()"
        [class]="buttonClasses()"
        [attr.aria-label]="languageLabel()"
      >
        <svg mol-icon-root [name]="globeIcon" [size]="14"></svg>
        {{ activeLocaleName() }}
      </button>
      <span [class]="linkClasses()">{{ versionText() }}</span>
    </footer>
    @if (isModalMode()) {
      <mol-modal
        [open]="privacyOpen()"
        [title]="privacyLabel()"
        [size]="'lg'"
        (close)="closePrivacy()"
      >
        @if (hasLegalHtml(privacyHtml())) {
          <div [class]="proseClasses()" [innerHTML]="legalTrusted(privacyHtml())"></div>
        } @else {
          <p [class]="proseClasses()">{{ legalNotConfigured() }}</p>
        }
      </mol-modal>
      <mol-modal [open]="termsOpen()" [title]="termsLabel()" [size]="'lg'" (close)="closeTerms()">
        @if (hasLegalHtml(termsHtml())) {
          <div [class]="proseClasses()" [innerHTML]="legalTrusted(termsHtml())"></div>
        } @else {
          <p [class]="proseClasses()">{{ legalNotConfigured() }}</p>
        }
      </mol-modal>
    }
    <mol-modal
      [open]="languageOpen()"
      [title]="languageLabel()"
      [size]="'lg'"
      (close)="closeLanguage()"
    >
      <div [class]="gridClasses()">
        @for (locale of sortedLocales(); track locale.code) {
          <button
            type="button"
            (click)="pickLocale(locale.code)"
            [class]="localeOptionClasses(locale.code)"
          >
            {{ locale.name }}
          </button>
        }
      </div>
    </mol-modal>`,
})
export class AppFooter {
  appName = ''
  aboutHref = ''
  legalMode: 'modal' | 'route' = 'modal'
  loadContent?: AppFooterLoadContent
  privacyTo?: string
  termsTo?: string
  className?: string
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string

  /** The glyph before the current locale name. */
  readonly globeIcon: IconName = 'globe'

  /** Whether the privacy modal is open. */
  readonly privacyOpen = signal(false)

  /** Whether the terms modal is open. */
  readonly termsOpen = signal(false)

  /** Whether the language modal is open. */
  readonly languageOpen = signal(false)

  readonly i18n = useTranslation()

  readonly version = useVersion()

  private readonly sanitizer = inject(DomSanitizer)

  private readonly trustedCache = new Map<string, SafeHtml>()

  private readonly host: ElementRef<HTMLElement> = inject(ElementRef)

  constructor() {
    usePlacement(() => {
      placeContentBefore(this.host.nativeElement, this.host.nativeElement)
      setElementPresent(this.host.nativeElement, false)
    })
  }

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

  footerClasses(): string {
    return this.cm().cn(this.cm().footerBar, this.className)
  }

  linkClasses(): string {
    return this.cm().cn(this.cm().footerLink)
  }

  buttonClasses(): string {
    return this.cm().cn(this.cm().footerButton)
  }

  /** The legal content's class (`cm.prose`). */
  proseClasses(): string {
    return this.cm().cn(this.cm().prose)
  }

  /** The language grid's class (`cm.languageGrid`). */
  gridClasses(): string {
    return this.cm().cn(this.cm().languageGrid)
  }

  localeOptionClasses(code: string): string {
    return this.cm().cn(
      code === this.currentLocale() ? this.cm().languageActive : this.cm().languageOption,
    )
  }

  isModalMode(): boolean {
    return this.legalMode !== 'route'
  }

  isExternalAbout(): boolean {
    return isExternalHref(this.aboutHref)
  }

  privacyToValue(): string {
    return this.privacyTo ?? '/privacy'
  }

  /** The Terms route path (React's default parameter). */
  termsToValue(): string {
    return this.termsTo ?? '/terms'
  }

  aboutLabel(): string {
    return this.i18n.t(
      'footer.about',
      { appName: this.appName },
      { defaultValue: 'About {{appName}}' },
    )
  }

  /** The Privacy Policy button/modal-title label. */
  privacyLabel(): string {
    return this.i18n.t('footer.privacyPolicy', {}, { defaultValue: 'Privacy Policy' })
  }

  /** The Terms of Service button/modal-title label. */
  termsLabel(): string {
    return this.i18n.t('footer.termsOfService', {}, { defaultValue: 'Terms of Service' })
  }

  languageLabel(): string {
    return this.i18n.t('footer.language', {}, { defaultValue: 'Language' })
  }

  versionText(): string {
    return this.i18n.t(
      'footer.version',
      { version: this.version.state().version || '1.0.0' },
      { defaultValue: 'v{{version}}' },
    )
  }

  legalNotConfigured(): string {
    return this.i18n.t(
      'footer.legalNotConfigured',
      {},
      {
        defaultValue: 'This content has not been configured yet. The app owner must provide it.',
      },
    )
  }

  privacyHtml(): string {
    return this.i18n.t(
      'content.privacyPolicy',
      { appName: escapeHtml(this.appName) },
      { defaultValue: '' },
    )
  }

  termsHtml(): string {
    return this.i18n.t(
      'content.termsOfService',
      { appName: escapeHtml(this.appName) },
      { defaultValue: '' },
    )
  }

  hasLegalHtml(html: string): boolean {
    return html.trim().length > 0
  }

  legalTrusted(html: string): SafeHtml {
    const hit = this.trustedCache.get(html)
    if (hit !== undefined) return hit
    if (this.trustedCache.size >= TRUSTED_CACHE_LIMIT) this.trustedCache.clear()
    const trusted = this.sanitizer.bypassSecurityTrustHtml(html)
    this.trustedCache.set(html, trusted)
    return trusted
  }

  activeLocaleName(): string | null {
    return this.i18n.locales().find((locale) => locale.code === this.currentLocale())?.name ?? null
  }

  sortedLocales(): { code: string; name: string }[] {
    return [...this.i18n.locales()].sort((a, b) => a.name.localeCompare(b.name))
  }

  /** The active locale code. */
  currentLocale(): string {
    return this.i18n.locale()
  }

  async openPrivacy(): Promise<void> {
    if (this.loadContent) await this.loadContent('privacyPolicy')
    this.privacyOpen.set(true)
  }

  async openTerms(): Promise<void> {
    if (this.loadContent) await this.loadContent('termsOfService')
    this.termsOpen.set(true)
  }

  /** Opens the language modal. */
  openLanguage(): void {
    this.languageOpen.set(true)
  }

  /** Closes the Privacy modal (React's `onClose`). */
  closePrivacy(): void {
    this.privacyOpen.set(false)
  }

  /** Closes the Terms modal (React's `onClose`). */
  closeTerms(): void {
    this.termsOpen.set(false)
  }

  /** Closes the language modal (React's `onClose`). */
  closeLanguage(): void {
    this.languageOpen.set(false)
  }

  async pickLocale(code: string): Promise<void> {
    await this.i18n.setLocale(code)
    this.languageOpen.set(false)
  }
}

(Member comments are shortened to their first sentence, and the 35 longest are left out to fit; the full declaration is in node_modules/@molecule/app-footer-angular/dist/app-footer.component.d.ts.)

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.13.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

  • Must render inside the binding's router (provideRouter) when it shows an internal About link or the legalMode="route" anchors — those are the binding's Link (<a molLink>, react-router's <Link> contract), which throws outside one, as react-router's does — and inside the binding's i18n (provideI18n or provideMolecule) for useTranslation(). Styling needs a bonded ClassMap (e.g. @molecule/app-ui-tailwind); version display works unbonded (the version core falls back to a web provider).

  • The privacy/terms modals render whatever HTML the i18n catalog holds under content.privacyPolicy / content.termsOfService as raw HTML — the same trust model as React's dangerouslySetInnerHTML (the [innerHTML] binding bypasses the sanitizer for exactly this content). The appName interpolated into that HTML is HTML-escaped first, so a markup-carrying app name arrives as inert entities. Those keys are EMPTY by default (the app supplies its real legal HTML); until it does, the modal shows the footer.legalNotConfigured placeholder instead of a silently-blank modal — no fabricated legal text is ever shipped.

  • The language picker lists every locale registered on the i18n provider, sorted by name; picking one switches the locale and closes the modal.

Translations

Translation strings are provided by @molecule/app-locales-footer.