@molecule/app-trend-chip-angular

Feature · trend-chip · App (browser) · v1.1.3 · Apache-2.0

Standalone trend delta chip (▲ 12%) for inline placement in tables, headers, cards

npm install @molecule/app-trend-chip-angular

npm · Source on GitHub

How it works

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

@Component({
  selector: 'app-row',
  standalone: true,
  imports: [TrendChip],
  template: `
    <tr>
      <td><span mol-trend-chip [delta]="12"></span></td>
      <td><span mol-trend-chip [delta]="-4.5" variant="pill"></span></td>
    </tr>
  `,
})
export class Row {}

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

Reference

Angular standalone trend delta chip (▲ 12%) — the counterpart of @molecule/app-trend-chip-react, with the same props and the same DOM for the same input.

Exports <TrendChip>: an inline ▲ 12% chip for tables, headers and cards, styled entirely through the ClassMap bond.

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 { TrendChip } from '@molecule/app-trend-chip-angular'

@Component({
  selector: 'app-row',
  standalone: true,
  imports: [TrendChip],
  template: `
    <tr>
      <td><span mol-trend-chip [delta]="12"></span></td>
      <td><span mol-trend-chip [delta]="-4.5" variant="pill"></span></td>
    </tr>
  `,
})
export class Row {}

Type

feature

Installation

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

API

Interfaces

TrendChipProps

Props accepted by TrendChip — the same props @molecule/app-trend-chip-react accepts. Node-valued prefix content is projected in Angular (an input cannot carry a node), so it is typed unknown: pass a string or number value through the input, and element content in the host template as [slot=prefix] content.

interface TrendChipProps {
  /** Numeric delta to display. Sign drives direction unless `direction` is set. */
  delta: number
  /** Explicit direction override. */
  direction?: 'up' | 'down' | 'flat'
  /** Suffix appended to the delta. Defaults to '%'. */
  suffix?: string
  /**
   * Optional prefix for the value. A string or number feeds the default aria
   * label and renders as text; element content is projected as
   * `[slot=prefix]` content instead.
   */
  prefix?: unknown
  /** Style preset. `'subtle'` = inline plain, `'pill'` = colored pill. Defaults to `'subtle'`. */
  variant?: 'subtle' | 'pill'
  /** Optional accessible label override. */
  ariaLabel?: string
  /** Extra classes. */
  className?: string
}

Classes

TrendChip

TrendChip component.

Standalone trend delta chip — ▲ 12% style display for inline placement in row/header/cell contexts. The host IS the root <span> (span[mol-trend-chip]), matching React's root exactly. Colors come from the ClassMap bond's semantic tones and follow the app theme; only the pill's padding and radius are inline, through host style bindings (the CSSOM, as react-dom does). Same props, same DOM as @molecule/app-trend-chip-react's TrendChip. Node-valued prefix content is projected from [slot=prefix]; a string or number prefix input renders as text and feeds the default aria label.

@Component({
  selector: 'span[mol-trend-chip]',
  standalone: true,
  inputs: ['delta', 'direction', 'suffix', 'prefix', 'variant', 'ariaLabel', 'className'],
  host: {
    '[class]': 'classes()',
    '[style.padding]': 'stylePadding()',
    '[style.border-radius]': 'styleRadius()',
    '[attr.aria-label]': 'label()',
  },
  template: `@if (hasPrefix) {
      <ng-container>{{ prefixValue }}</ng-container>
    }
    <ng-content select="[slot=prefix]"></ng-content><span aria-hidden="true">{{ arrow() }}</span
    ><span>{{ abs() }}{{ suffixValue() }}</span>`,
})
export class TrendChip {
  /** Numeric delta to display. Sign drives direction unless `direction` is set. */
  delta = 0
  /** Explicit direction override. */
  direction?: 'up' | 'down' | 'flat'
  /** Suffix appended to the delta. */
  suffix = '%'
  /** Prefix value: rendered as text; a node prefix is projected content instead. */
  prefix?: string | number
  /** Style preset. */
  variant = 'subtle'
  /** Optional accessible label override. */
  ariaLabel?: string
  /** Extra classes. */
  className?: string

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

  /**
   * The effective direction: the override, or the delta's sign.
   * @returns `'up'`, `'down'` or `'flat'`.
   */
  dir(): 'up' | 'down' | 'flat' {
    return this.direction ?? (this.delta > 0 ? 'up' : this.delta < 0 ? 'down' : 'flat')
  }

  /**
   * Whether the pill preset is active.
   * @returns True for `variant: 'pill'`.
   */
  isPill(): boolean {
    return this.variant === 'pill'
  }

  /**
   * The semantic tone of the current direction.
   * @returns The `ColorVariant` tone.
   */
  tone(): ColorVariant {
    return TONE[this.dir()]
  }

  /**
   * The tone classes: the theme's inverse text on the tone's fill for the
   * pill preset, the tone as text colour otherwise.
   * @returns The class string.
   */
  toneClasses(): string {
    return this.isPill()
      ? this.cm().cn(this.cm().bgTone(this.tone()), this.cm().textOnTone)
      : this.cm().textTone(this.tone())
  }

  /**
   * Computes the chip's class list.
   * @returns The class string.
   */
  classes(): string {
    return this.cm().cn(
      this.cm().flex({ align: 'center', gap: 'xs' }),
      this.cm().textSize('xs'),
      this.cm().fontWeight('semibold'),
      this.toneClasses(),
      this.className,
    )
  }

  /**
   * The pill's horizontal padding (absent for the subtle preset).
   * @returns The padding, or null to clear the property.
   */
  stylePadding(): string | null {
    return this.isPill() ? '2px 6px' : null
  }

  /**
   * The pill's full rounding (absent for the subtle preset).
   * @returns The radius, or null to clear the property.
   */
  styleRadius(): string | null {
    return this.isPill() ? '999px' : null
  }

  /**
   * Whether a string or number prefix is present (a projected node prefix is
   * not).
   * @returns True when the prefix input renders as text.
   */
  get hasPrefix(): boolean {
    return this.prefix !== undefined && this.prefix !== null && this.prefix !== ''
  }

  /**
   * The prefix value to render as text.
   * @returns The prefix, or `''` when absent.
   */
  get prefixValue(): string | number {
    return this.prefix === undefined || this.prefix === null || this.prefix === ''
      ? ''
      : this.prefix
  }

  /**
   * The accessible label: the override, or the value the chip renders.
   * @returns The label text.
   */
  label(): string {
    return (
      this.ariaLabel ?? `${this.prefixValue}${ARROW[this.dir()]} ${this.abs()}${this.suffixValue()}`
    )
  }

  /**
   * The arrow of the effective direction.
   * @returns The arrow character.
   */
  arrow(): string {
    return ARROW[this.dir()]
  }

  /**
   * The delta's magnitude.
   * @returns `Math.abs(delta)`.
   */
  abs(): number {
    return Math.abs(this.delta)
  }

  /**
   * The suffix in effect (React's default parameter: a `undefined` binding
   * must not erase the `'%'` default).
   * @returns The suffix.
   */
  suffixValue(): string {
    return this.suffix ?? '%'
  }
}

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.5.0 || ^4.0.0
  • @molecule/app-ui ^1.4.0
  • @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

Colors come from the ClassMap bond's semantic tones and follow the app theme: subtle text is cm.textTone of success (up), error (down) or secondary (flat); the pill preset fills with cm.bgTone of the same tone and reads cm.textOnTone (the theme's inverse text). Up is always green / down always red: there is no inversion knob. The number renders as Math.abs(delta) + suffix ('%' by default) — the sign only picks the arrow; direction overrides sign-detection. Props (documented on the exported TrendChipProps interface): delta, direction ('up' | 'down' | 'flat'), suffix, prefix, variant ('subtle' | 'pill'), ariaLabel, className. No data-mol-id prop. The host element IS the chip's <span> (span[mol-trend-chip]); a node-valued prefix is projected content selected by [slot=prefix], while a string or number prefix input renders as text and feeds the default aria label — pass ariaLabel with a projected prefix, since the default label of a non-string prefix is not meaningful. Without i18n: the chip carries no user-visible text of its own.