@molecule/app-achievement-card-angular

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

Badge / achievement unlock card with icon + name + description + earned-at

npm install @molecule/app-achievement-card-angular

npm · Source on GitHub

How it works

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

@Component({
  selector: 'app-achievements',
  standalone: true,
  imports: [AchievementCard],
  template: `
    <div
      mol-achievement-card
      name="First Login"
      description="Signed in for the first time."
      earned="true"
      earnedAt="Jan 3, 2025"
      tier="Common"
    >
      <span slot="icon">🏆</span>
    </div>
  `,
})
export class Achievements {}

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

Reference

Angular badge / achievement unlock card — the Angular counterpart of @molecule/app-achievement-card-react, with the same props and the same DOM for the same input.

Exports <AchievementCard> — icon + name + description + earned state. The host IS the Card div (div[mol-achievement-card]), so its classes and inline style match React's root exactly. Locked achievements render greyed-out; in-progress ones show a progress bar.

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 { AchievementCard } from '@molecule/app-achievement-card-angular'

@Component({
  selector: 'app-achievements',
  standalone: true,
  imports: [AchievementCard],
  template: `
    <div
      mol-achievement-card
      name="First Login"
      description="Signed in for the first time."
      earned="true"
      earnedAt="Jan 3, 2025"
      tier="Common"
    >
      <span slot="icon">🏆</span>
    </div>
  `,
})
export class Achievements {}

Type

feature

Installation

npm install @molecule/app-achievement-card-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-i18n @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

AchievementCardProps

Props accepted by AchievementCard — the same props @molecule/app-achievement-card-react accepts. Node props (name, description, icon, earnedAt, tier) are typed unknown: pass a plain string as the input, or project content as [slot=<name>] children of the host element.

interface AchievementCardProps {
  /** Achievement name — a string input, or `[slot=name]` projected content. */
  name?: unknown
  /** Description / what it took to earn — a string input, or `[slot=description]` content. */
  description?: unknown
  /** Icon / illustration slot — `[slot=icon]` projected content (or a string input). */
  icon?: unknown
  /** Whether the user has earned this achievement. */
  earned?: boolean
  /** Earned-at display — a string input, or `[slot=earnedAt]` projected content. */
  earnedAt?: unknown
  /**
   * Label shown before `earnedAt` on earned achievements. Overrides the
   * translated / `defaultValue` `'Earned'` (prop > `t()` > default).
   */
  earnedLabel?: string
  /**
   * Label shown on locked achievements (not earned, no progress). Overrides
   * the translated / `defaultValue` `'Locked'` (prop > `t()` > default).
   */
  lockedLabel?: string
  /** Optional progress data (for in-progress achievements): the earned count out of a maximum. */
  progress?: { value: number; max: number }
  /** Optional rarity / tier label ("Legendary", "Common") — a string input or `[slot=tier]` content. */
  tier?: unknown
  /** Extra classes. */
  className?: string
}

Classes

AchievementCard

AchievementCard component.

Badge / achievement unlock card — icon + name + description + earned state. Locked achievements render greyed-out; in-progress ones show a progress bar. The host IS the Card div (div[mol-achievement-card]), matching React's root exactly — same classes, same inline style. Node props (name, description, icon, earnedAt, tier) are projected content ([slot=<name>]) or plain string inputs.

This is the Angular counterpart of @molecule/app-achievement-card-react.

@Component({
  selector: 'div[mol-achievement-card]',
  standalone: true,
  inputs: [
    'name',
    'description',
    'icon',
    'earned',
    'earnedAt',
    'earnedLabel',
    'lockedLabel',
    'progress',
    'tier',
    'className',
  ],
  hostDirectives: [MolPlacement],
  host: {
    '[class]': 'classes()',
    '[style]': 'hostStyleText()',
  },
  // prettier-ignore
  template: `<div [class]="rowClasses()"><div [class]="iconBoxClasses()" style="font-size: 36px">@if (hasIcon) {{{ icon }}}<ng-content select="[slot=icon]" /></div><div [class]="bodyClasses()"><header [class]="headerClasses()"><h3 [class]="nameClasses()">@if (hasName) {{{ name }}}<ng-content select="[slot=name]" /></h3><span #tierEl [class]="tierClasses()">@if (hasTier) {{{ tier }}}<ng-content select="[slot=tier]" /></span></header><p #descriptionEl [class]="descriptionClasses()">@if (hasDescription) {{{ description }}}<ng-content select="[slot=description]" /></p>@if (earned) {<span #earnedAtEl [class]="earnedAtClasses()">{{ earnedLine() }}@if (hasEarnedAt) {{{ earnedAt }}}<ng-content select="[slot=earnedAt]" /></span>} @else if (progress) {<div [class]="progressClasses()"><div [class]="progressBarClasses()" [style]="progressStyleText()"></div></div>} @else {<span [class]="lockedClasses()">{{ lockedText() }}</span>}</div></div>`,
})
export class AchievementCard {
  /** Achievement name — a string input, or `[slot=name]` projected content. */
  name?: unknown
  /** Description / what it took to earn — a string input, or `[slot=description]` content. */
  description?: unknown
  /** Icon / illustration slot — `[slot=icon]` projected content (or a string input). */
  icon?: unknown
  /** Whether the user has earned this achievement. */
  earned?: boolean
  /** Earned-at display — a string input, or `[slot=earnedAt]` projected content. */
  earnedAt?: unknown
  /** Label shown before `earnedAt` on earned achievements (overrides `t()`). */
  earnedLabel?: string
  /** Label shown on locked achievements (overrides `t()`). */
  lockedLabel?: string
  /** Optional progress data (for in-progress achievements). */
  progress?: AchievementCardProps['progress']
  /** Optional rarity / tier label — a string input, or `[slot=tier]` content. */
  tier?: unknown
  /** Extra classes. */
  className?: string

  /** The tier span (always in the header; detached while it has nothing to render). */
  @ViewChild('tierEl', { static: true }) private tierEl?: ElementRef<HTMLSpanElement>
  /** The description paragraph (always in the body; detached while it has nothing to render). */
  @ViewChild('descriptionEl', { static: true })
  private descriptionEl?: ElementRef<HTMLParagraphElement>
  /** The earned-at span (in the earned row; detached while it has nothing to render). */
  @ViewChild('earnedAtEl') private earnedAtEl?: ElementRef<HTMLSpanElement>

  /** The i18n handle (locale-reactive), read in an injection context. */
  private readonly i18n = useTranslation()

  constructor() {
    usePlacement((hasContent) => {
      const tier = this.tierEl?.nativeElement
      setElementPresent(tier, this.hasTier || (tier ? hasContent(tier) : false))
      const description = this.descriptionEl?.nativeElement
      setElementPresent(
        description,
        this.hasDescription || (description ? hasContent(description) : false),
      )
      const earnedAt = this.earnedAtEl?.nativeElement
      // The span interpolates its own label first, so only the children after
      // it can be the caller's projection.
      setElementPresent(earnedAt, this.hasEarnedAt || (earnedAt ? hasContent(earnedAt, 1) : false))
    })
  }

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

  /** Whether a text name input renders (a projected name is not). */
  get hasName(): boolean {
    return this.name !== undefined && this.name !== null
  }

  /** Whether a text icon input renders (a projected icon is not). */
  get hasIcon(): boolean {
    return this.icon !== undefined && this.icon !== null && this.icon !== ''
  }

  /** Whether a text tier input is present (React's `tier && …`). */
  get hasTier(): boolean {
    return this.tier !== undefined && this.tier !== null && this.tier !== false && this.tier !== ''
  }

  /** Whether a text description input is present (React's `description && …`). */
  get hasDescription(): boolean {
    return (
      this.description !== undefined &&
      this.description !== null &&
      this.description !== false &&
      this.description !== ''
    )
  }

  /** Whether a text earned-at input is present (React's `earnedAt && …`). */
  get hasEarnedAt(): boolean {
    return (
      this.earnedAt !== undefined &&
      this.earnedAt !== null &&
      this.earnedAt !== false &&
      this.earnedAt !== ''
    )
  }

  /** The earned state's label (prop > `t()` > default). */
  earnedText(): string {
    return (
      this.earnedLabel ??
      this.i18n.t('achievementCard.earned', undefined, { defaultValue: 'Earned' })
    )
  }

  /** The locked state's label (prop > `t()` > default). */
  lockedText(): string {
    return (
      this.lockedLabel ??
      this.i18n.t('achievementCard.locked', undefined, { defaultValue: 'Locked' })
    )
  }

  /** The earned-at line's leading text, with React's separating space. */
  earnedLine(): string {
    return `${this.earnedText()} `
  }

  /** The progress bar's inline style (React's `{ width: '<pct>%' }`). */
  progressStyleText(): string | null {
    const progress = this.progress
    if (!progress) return null
    const percent = Math.min(100, (progress.value / progress.max) * 100)
    return styleText({ width: `${percent}%` })
  }

  hostStyleText(): string | null {
    return this.earned ? null : styleText({ filter: 'grayscale(0.6)', opacity: 0.5 })
  }

  /** The host's class list (React's Card classes plus `className`). */
  classes(): string {
    const cm = this.cm()
    return cm.cn(cm.card({ variant: 'elevated' }), cm.cardPadding('md'), this.className)
  }

  /** The icon row's class list (React's `cm.flex({ align: 'start', gap: 'md' })`). */
  rowClasses(): string {
    const cm = this.cm()
    return cm.flex({ align: 'start', gap: 'md' })
  }

  /** The icon box's class list (React's `cm.shrink0`). */
  iconBoxClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.shrink0)
  }

  /** The body column's class list (React's `cm.cn(cm.flex1, cm.stack(1))`). */
  bodyClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.flex1, cm.stack(1))
  }

  /** The header row's class list (React's `cm.flex({ align: 'baseline', gap: 'sm' })`). */
  headerClasses(): string {
    const cm = this.cm()
    return cm.flex({ align: 'baseline', gap: 'sm' })
  }

  /** The name heading's class list (React's `cm.cn(cm.textSize('base'), cm.fontWeight('bold'))`). */
  nameClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('base'), cm.fontWeight('bold'))
  }

  /** The tier span's class list (React's `cm.cn(cm.textSize('xs'), cm.fontWeight('semibold'))`). */
  tierClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('xs'), cm.fontWeight('semibold'))
  }

  /** The description paragraph's class list (React's `cm.textSize('sm')`). */
  descriptionClasses(): string {
    return this.cm().textSize('sm')
  }

  /** The earned-at span's class list (React's `cm.textSize('xs')`). */
  earnedAtClasses(): string {
    return this.cm().textSize('xs')
  }

  /** The progress track's class list (React's `cm.cn(cm.progress(), cm.progressHeight('sm'))`). */
  progressClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.progress(), cm.progressHeight('sm'))
  }

  progressBarClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.progressBar(), cm.progressColor('primary'))
  }

  lockedClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.textSize('xs'), cm.fontWeight('semibold'))
  }
}

(Member comments are shortened to their first sentence, and the 4 longest are left out to fit; the full declaration is in node_modules/@molecule/app-achievement-card-angular/dist/achievement-card.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-i18n ^1.0.1
  • @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-i18n
  • @molecule/app-ui
  • @molecule/app-ui-angular

The "Earned"/"Locked" state labels flow through t() with English defaultValue fallbacks under the achievementCard.* keys, so the @molecule/app-locales-achievement-card companion bond (or the host app's own locale) can translate them. Each is also overridable per-instance via the earnedLabel / lockedLabel inputs (prop > t() > default). The labels are read through useTranslation(), so they follow a locale switch. Node props are projected content: name, description, icon, earnedAt and tier are selected by [slot=<name>], and plain strings may also be passed as inputs.

Translations

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