@molecule/app-habit-streak-card-angular

Feature · habit-streak-card · App (browser) · v1.1.2 · Apache-2.0

Habit / streak card with current streak, best streak, completion heatmap

npm install @molecule/app-habit-streak-card-angular

npm · Source on GitHub

How it works

@molecule/app-habit-streak-card-angular is a ready-made habit-streak-card 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 { HabitStreakCard } from '@molecule/app-habit-streak-card-angular'

@Component({
  selector: 'app-habit',
  standalone: true,
  imports: [HabitStreakCard],
  template: `
    <div
      mol-habit-streak-card
      [currentStreak]="14"
      [bestStreak]="30"
      [totalCompletions]="87"
      [heatmap]="recentDays"
    >
      <strong slot="name">Morning Run</strong>
      <span slot="icon">🏃</span>
    </div>
  `,
})
export class HabitView {
  recentDays = [
    { date: '2026-07-01', count: 1 },
    { date: '2026-07-02', count: 3 },
  ]
}

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

Reference

Angular habit / streak summary card — the counterpart of @molecule/app-habit-streak-card-react: the same props and the same DOM for the same input.

Exports <HabitStreakCard> — current streak, best streak, total completions, and an optional per-day heatmap strip. Use for habit trackers, meditation streaks, daily-task widgets.

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 { HabitStreakCard } from '@molecule/app-habit-streak-card-angular'

@Component({
  selector: 'app-habit',
  standalone: true,
  imports: [HabitStreakCard],
  template: `
    <div
      mol-habit-streak-card
      [currentStreak]="14"
      [bestStreak]="30"
      [totalCompletions]="87"
      [heatmap]="recentDays"
    >
      <strong slot="name">Morning Run</strong>
      <span slot="icon">🏃</span>
    </div>
  `,
})
export class HabitView {
  recentDays = [
    { date: '2026-07-01', count: 1 },
    { date: '2026-07-02', count: 3 },
  ]
}

Type

feature

Installation

npm install @molecule/app-habit-streak-card-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

StreakDay

Represents a single day's completion data for the heatmap strip.

interface StreakDay {
  /** ISO date (yyyy-mm-dd). */
  date: string
  /** Completion count for the day (0 = not done, >0 = intensity). */
  count: number
}

HabitStreakCardProps

Props accepted by HabitStreakCard — the same props @molecule/app-habit-streak-card-react accepts. Node props (name, icon) are projected content in Angular (an input cannot carry a node), so they are typed unknown: pass them as [slot=name] / [slot=icon] content, or as plain strings.

interface HabitStreakCardProps {
  /** Habit name, projected as `[slot=name]` content or a plain string. */
  name: unknown
  /** Optional leading icon, projected as `[slot=icon]` content or a plain string. */
  icon?: unknown
  /** Current streak (days). */
  currentStreak: number
  /** Best streak (days). */
  bestStreak?: number
  /** Total completions. */
  totalCompletions?: number
  /** Optional heatmap days — rendered as a strip of squares. */
  heatmap?: StreakDay[]
  /** Days the heatmap should display (truncates `heatmap` from the end). Defaults to 30. */
  heatmapDays?: number
  /** Extra classes on the card. */
  className?: string
}

Classes

HabitStreakCard

HabitStreakCard component.

Habit / streak summary card with current + best streak, total completions, and an optional heatmap strip. The host IS React's root <div> (div[mol-habit-streak-card]), carrying the Card classes exactly as React's Card does. name and icon are projected content ([slot=name], [slot=icon]) or plain string inputs; the stat labels and the heatmap's strip and day labels go through useTranslation() with React's exact keys and English defaults. heatmapDays truncates heatmap from the end (most recent days win).

@Component({
  selector: 'div[mol-habit-streak-card]',
  standalone: true,
  inputs: [
    'name',
    'icon',
    'currentStreak',
    'bestStreak',
    'totalCompletions',
    'heatmap',
    'heatmapDays',
    'className',
  ],
  host: {
    '[class]': 'cardClasses()',
  },
  // prettier-ignore
  template: `<div [class]="stackClasses()"><header [class]="headerClasses()"><ng-content select="[slot=icon]"></ng-content>@if (hasIcon) {<ng-container>{{ icon }}</ng-container>}<h3 [class]="nameClasses()">@if (hasName) {<ng-container>{{ name }}</ng-container>}<ng-content select="[slot=name]"></ng-content></h3></header><div [class]="statsClasses()"><div><div [class]="currentValueClasses()">{{ currentStreak }}</div><div [class]="labelClasses()">{{ currentLabel() }}</div></div>@if (bestStreak !== undefined) {<div><div [class]="secondaryValueClasses()">{{ bestStreak }}</div><div [class]="labelClasses()">{{ bestLabel() }}</div></div>}@if (totalCompletions !== undefined) {<div><div [class]="secondaryValueClasses()">{{ totalCompletions }}</div><div [class]="labelClasses()">{{ totalLabel() }}</div></div>}</div>@if (days().length > 0) {<div role="group" [class]="stripClasses()" [attr.aria-label]="stripLabel()">@for (day of days(); track day.date) {<span role="img" [attr.aria-label]="dayLabel(day)" [attr.title]="dayLabel(day)" [style.width]="'10px'" [style.height]="'10px'" [style.border-radius]="'2px'" [style.background]="dayBackground(day)"></span>}</div>}</div>`,
})
export class HabitStreakCard {
  /** Habit name — a string input, or `[slot=name]` projected content. */
  name?: unknown
  /** Optional leading icon — a string input, or `[slot=icon]` projected content. */
  icon?: unknown
  /** Current streak (days). */
  currentStreak?: number
  /** Best streak (days). */
  bestStreak?: number
  /** Total completions. */
  totalCompletions?: number
  /** Optional heatmap days — rendered as a strip of squares. */
  heatmap?: StreakDay[]
  /** Days the heatmap should display (defaults to 30 at read time). */
  heatmapDays?: number
  /** Extra classes on the card. */
  className?: string

  /** The i18n provider above the card (the stat labels). */
  private readonly i18n = useTranslation()

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

  /**
   * Computes the card class list — React's `Card` with the default `elevated`
   * variant and `md` padding, plus `className`.
   * @returns The class string.
   */
  cardClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.card({ variant: 'elevated' }), cm.cardPadding('md'), this.className)
  }

  /**
   * The outer stack class list.
   * @returns The class string.
   */
  stackClasses(): string {
    return this.cm().stack(3)
  }

  /**
   * The name row class list.
   * @returns The class string.
   */
  headerClasses(): string {
    return this.cm().flex({ align: 'center', gap: 'sm' })
  }

  /**
   * The habit-name heading class list.
   * @returns The class string.
   */
  nameClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('base'), cm.fontWeight('semibold'))
  }

  /**
   * The stats row class list.
   * @returns The class string.
   */
  statsClasses(): string {
    return this.cm().flex({ align: 'baseline', gap: 'lg' })
  }

  /**
   * The current-streak number class list.
   * @returns The class string.
   */
  currentValueClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('3xl'), cm.fontWeight('bold'))
  }

  /**
   * The best-streak / total-completions number class list.
   * @returns The class string.
   */
  secondaryValueClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('lg'), cm.fontWeight('semibold'))
  }

  /**
   * The stat label class list.
   * @returns The class string.
   */
  labelClasses(): string {
    return this.cm().textSize('xs')
  }

  /**
   * The heatmap strip class list.
   * @returns The class string.
   */
  stripClasses(): string {
    return this.cm().flex({ align: 'center', gap: 'xs' })
  }

  /**
   * The heatmap days in the rendered window (React's `slice(-heatmapDays)`).
   * @returns The days to render.
   */
  days(): StreakDay[] {
    return (this.heatmap ?? []).slice(-(this.heatmapDays ?? 30))
  }

  /**
   * The largest count in the rendered window.
   * @returns The maximum completion count.
   */
  maxCount(): number {
    return this.days().reduce((max, day) => Math.max(max, day.count), 0)
  }

  /**
   * The heatmap strip's accessible label.
   * @returns The translated strip label.
   */
  stripLabel(): string {
    return this.i18n.t('habit.aria.recentActivity', {}, { defaultValue: 'Recent activity' })
  }

  /**
   * One heatmap square's label and tooltip (`<date>: <count>`).
   * @param day - The day.
   * @returns Its label.
   */
  dayLabel(day: StreakDay): string {
    return this.i18n.t(
      'habit.cell.tooltip',
      { date: day.date, count: day.count },
      { defaultValue: '{{date}}: {{count}}' },
    )
  }

  /**
   * One heatmap square's background color.
   * @param day - The day.
   * @returns The CSS background color.
   */
  dayBackground(day: StreakDay): string {
    return intensityColor(day.count, this.maxCount())
  }

  /**
   * Whether `name` arrives as a text input (projected content otherwise).
   * @returns True when `name` is a non-empty string.
   */
  get hasName(): boolean {
    return typeof this.name === 'string' && this.name.length > 0
  }

  /**
   * Whether `icon` arrives as a text input (projected content otherwise).
   * @returns True when `icon` is a non-empty string.
   */
  get hasIcon(): boolean {
    return typeof this.icon === 'string' && this.icon.length > 0
  }

  /**
   * The current-streak label.
   * @returns The translated text.
   */
  currentLabel(): string {
    return this.i18n.t('habit.currentStreak', {}, { defaultValue: 'day streak' })
  }

  /**
   * The best-streak label.
   * @returns The translated text.
   */
  bestLabel(): string {
    return this.i18n.t('habit.bestStreak', {}, { defaultValue: 'best' })
  }

  /**
   * The total-completions label.
   * @returns The translated text.
   */
  totalLabel(): string {
    return this.i18n.t('habit.total', {}, { defaultValue: 'total' })
  }
}

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

  • Requires the Angular binding's i18n provider (useTranslation() THROWS without it) and a bonded ClassMap for getClassMap(). Stat labels come from the @molecule/app-locales-habit-streak-card companion bond.

  • The heatmap strip uses a fixed green ramp with a light-only zero color (rgba(0,0,0,0.08)) rendered as inline styles — on dark themes the empty cells are nearly invisible. For a theme-aware year grid use @molecule/app-heatmap-angular with a custom colorScale instead.

  • heatmapDays truncates heatmap from the END (most recent days win).

  • Node props are projected content: name and icon are selected by [slot=name] / [slot=icon], or passed as plain string inputs.

Translations

Translation strings are provided by @molecule/app-locales-habit-streak-card.