@molecule/app-subscription-plan-card-angular

Feature · subscription-plan-card · App (browser) · v1.1.3 · Apache-2.0

Pricing / plan card with features, price + interval, primary CTA, recommended badge

npm install @molecule/app-subscription-plan-card-angular

npm · Source on GitHub

How it works

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

@Component({
  selector: 'app-plans',
  standalone: true,
  imports: [SubscriptionPlanCard],
  template: `
    <div
      mol-subscription-plan-card
      name="Pro"
      price="$19"
      interval="/month"
      [features]="features"
      ctaLabel="Get started"
      [onCta]="checkout"
      [recommended]="true"
      badge="Most popular"
    ></div>
  `,
})
export class Plans {
  features = ['Unlimited projects', '10 GB storage', 'Priority support']
  checkout = (): void => navigate('/checkout/pro')
}

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

Reference

Angular pricing / subscription plan card — the counterpart of @molecule/app-subscription-plan-card-react: the same props and the same DOM for the same input.

Exports <SubscriptionPlanCard> — header (badge + name + description), price + interval, feature checklist, and a primary CTA (button or link).

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 { SubscriptionPlanCard } from '@molecule/app-subscription-plan-card-angular'

@Component({
  selector: 'app-plans',
  standalone: true,
  imports: [SubscriptionPlanCard],
  template: `
    <div
      mol-subscription-plan-card
      name="Pro"
      price="$19"
      interval="/month"
      [features]="features"
      ctaLabel="Get started"
      [onCta]="checkout"
      [recommended]="true"
      badge="Most popular"
    ></div>
  `,
})
export class Plans {
  features = ['Unlimited projects', '10 GB storage', 'Priority support']
  checkout = (): void => navigate('/checkout/pro')
}

Type

feature

Installation

npm install @molecule/app-subscription-plan-card-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

SubscriptionPlanCardProps

Props accepted by SubscriptionPlanCard — the same props @molecule/app-subscription-plan-card-react accepts. Node props (name, description, price, interval, ctaLabel, badge) are projected content in Angular (an input cannot carry a node), so they are typed unknown: pass node content as [slot=<name>] children of the host element, and plain strings as the input. A features entry may likewise be a projected node template instead of a string.

interface SubscriptionPlanCardProps {
  /** Plan name — a string input, or `[slot=name]` projected content. */
  name?: unknown
  /** Optional tagline / one-liner — a string input, or `[slot=description]` content. */
  description?: unknown
  /** Price string — a string input, or `[slot=price]` projected content. */
  price?: unknown
  /** Billing interval label — a string input, or `[slot=interval]` content. */
  interval?: unknown
  /** Bullet feature list; a node entry is a projected template. */
  features: unknown[]
  /** Primary CTA button label — a string input, or `[slot=ctaLabel]` content. */
  ctaLabel?: unknown
  /** Click / nav handler (receives the click event, as React's CTA does). */
  onCta?: (event?: Event) => void
  /** When set, the CTA renders inside a plain anchor to this URL. */
  ctaHref?: string
  /** Visually highlight as the recommended / popular plan. */
  recommended?: boolean
  /** Optional badge content — a string input, or `[slot=badge]` content. */
  badge?: unknown
  /** Extra classes on the card. */
  className?: string
}

Classes

SubscriptionPlanCard

SubscriptionPlanCard component.

Pricing / subscription plan card — header (badge + name + description), price + interval, feature checklist, and a primary CTA (button or link). The host IS the card <div> (div[mol-subscription-plan-card]), matching React's root exactly, so the card's ClassMap classes and the recommended outline style are the host's.

Node props (name, description, price, interval, ctaLabel, badge) are projected content ([slot=<name>]), and a features entry that is a node is a projected template; plain strings are inputs. The optional description / interval / badge wrappers and the CTA render only when React would render them — Angular projection needs always-mounted capture points, so SubscriptionPlanCard.reconcile takes an unrendered wrapper out of the DOM (setElementPresent) and renders the CTA where React nests it (placeElement).

@Component({
  selector: 'div[mol-subscription-plan-card]',
  standalone: true,
  hostDirectives: [MolPlacement],
  imports: [Button, NgTemplateOutlet],
  inputs: [
    'name',
    'description',
    'price',
    'interval',
    'features',
    'ctaLabel',
    'onCta',
    'ctaHref',
    'recommended',
    'badge',
    'className',
  ],
  host: {
    '[class]': 'cardClasses()',
    '[style]': 'hostStyle()',
  },
  // prettier-ignore
  template: `<div [class]="cm().stack(4)"><header [class]="cm().stack(1)"><span #badgeWrap [class]="badgeClass()">@if (badgeProvided()) {<ng-container>{{ badge }}</ng-container>}<span #badgeCapture><ng-content select="[slot=badge]"></ng-content></span>@if (badgeDefault()) {<ng-container>{{ recommendedBadge() }}</ng-container>}</span><h3 [class]="nameClass()">@if (hasName()) {<ng-container>{{ name }}</ng-container>}<ng-content select="[slot=name]"></ng-content></h3><p #descriptionWrap [class]="cm().textSize('sm')">@if (hasDescription()) {<ng-container>{{ description }}</ng-container>}<ng-content select="[slot=description]"></ng-content></p></header><div [class]="cm().flex({ align: 'baseline', gap: 'xs' })"><span [class]="priceClass()">@if (hasPrice()) {<ng-container>{{ price }}</ng-container>}<ng-content select="[slot=price]"></ng-content></span><span #intervalWrap [class]="cm().textSize('sm')">@if (hasInterval()) {<ng-container>{{ interval }}</ng-container>}<ng-content select="[slot=interval]"></ng-content></span></div><ul [class]="cm().stack(2)">@for (feature of features; track $index) {<li [class]="cm().flex({ align: 'start', gap: 'sm' })"><span aria-hidden="true">✓</span><span [class]="cm().textSize('sm')">@if (isTemplate(feature)) {<ng-container [ngTemplateOutlet]="asTemplate(feature)"></ng-container>} @else {<ng-container>{{ feature }}</ng-container>}</span></li>}</ul><a #ctaAnchor [attr.href]="ctaHref"></a><button #ctaButton mol-button [variant]="'solid'" [color]="ctaColor()" (click)="onCtaClick($event)"><span #ctaLabelCapture><ng-content select="[slot=ctaLabel]"></ng-content></span>@if (hasCtaLabel()) {<ng-container>{{ ctaLabel }}</ng-container>}</button></div>`,
})
export class SubscriptionPlanCard {
  name?: unknown
  description?: unknown
  price?: unknown
  interval?: unknown
  features: unknown[] = []
  ctaLabel?: unknown
  onCta?: (event?: Event) => void
  ctaHref?: string
  /** Visually highlight as the recommended / popular plan. */
  recommended?: boolean
  badge?: unknown
  /** Extra classes on the card. */
  className?: string

  @ViewChild('badgeWrap') private badgeWrap?: ElementRef<HTMLElement>
  /** The optional description paragraph. */
  @ViewChild('descriptionWrap') private descriptionWrap?: ElementRef<HTMLElement>
  /** The optional interval span. */
  @ViewChild('intervalWrap') private intervalWrap?: ElementRef<HTMLElement>
  /** The CTA anchor (present only when `ctaHref` is set). */
  @ViewChild('ctaAnchor') private ctaAnchor?: ElementRef<HTMLAnchorElement>
  @ViewChild('ctaButton', { read: ElementRef }) private ctaButton?: ElementRef<HTMLButtonElement>
  @ViewChild('badgeCapture') private badgeCapture?: ElementRef<HTMLElement>
  @ViewChild('ctaLabelCapture') private ctaLabelCapture?: ElementRef<HTMLElement>

  private readonly i18n = useTranslation()

  private readonly badgeSlotRead = signal(false)
  /** Whether the description slot holds content. */
  private readonly descriptionSlot = signal(false)
  /** Whether the interval slot holds content. */
  private readonly intervalSlot = signal(false)
  /** Whether the badge slot holds content. */
  private readonly badgeSlot = signal(false)
  /** Whether the CTA label slot holds content. */
  private readonly ctaLabelSlot = signal(false)

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

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

  cardClasses(): string {
    const cm = this.cm()
    return cm.cn(cm.card({ variant: 'elevated' }), cm.cardPadding('md'), this.className)
  }

  hostStyle(): string | null {
    return styleText(
      this.recommended ? { outline: '2px solid currentColor', outlineOffset: -2 } : undefined,
    )
  }

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

  nameClass(): string {
    return this.cm().cn(this.cm().textSize('xl'), this.cm().fontWeight('bold'))
  }

  priceClass(): string {
    return this.cm().cn(this.cm().textSize('4xl'), this.cm().fontWeight('bold'))
  }

  hasName(): boolean {
    return this.name !== undefined && this.name !== null && this.name !== false
  }

  hasDescription(): boolean {
    return rendersNode(this.description)
  }

  /** Whether the price input holds a value. */
  hasPrice(): boolean {
    return this.price !== undefined && this.price !== null && this.price !== false
  }

  hasInterval(): boolean {
    return rendersNode(this.interval)
  }

  hasCtaLabel(): boolean {
    return rendersNode(this.ctaLabel)
  }

  badgeProvided(): boolean {
    return rendersNode(this.badge)
  }

  /** React's `(badge || recommended)`. */
  showBadge(): boolean {
    return Boolean(this.badge) || this.badgeSlot() || Boolean(this.recommended)
  }

  badgeDefault(): boolean {
    return (
      this.badgeSlotRead() &&
      Boolean(this.recommended) &&
      !this.badgeProvided() &&
      !this.badgeSlot()
    )
  }

  /** The translated default badge text. */
  recommendedBadge(): string {
    return this.i18n.t('plan.recommended', {}, { defaultValue: 'Recommended' })
  }

  /** React's `description && <p>`. */
  showDescription(): boolean {
    return Boolean(this.description) || this.descriptionSlot()
  }

  /** React's `interval && <span>`. */
  showInterval(): boolean {
    return Boolean(this.interval) || this.intervalSlot()
  }

  showCta(): boolean {
    return Boolean(this.ctaLabel) || this.ctaLabelSlot()
  }

  /** The CTA button's ClassMap color. */
  ctaColor(): 'primary' | 'secondary' {
    return this.recommended ? 'primary' : 'secondary'
  }

  /** Whether a `features` entry is a projected template. */
  isTemplate(value: unknown): value is TemplateRef<unknown> {
    return isTemplate(value)
  }

  /** The entry as a template (call under `isTemplate`). */
  asTemplate(value: unknown): TemplateRef<unknown> {
    return value as TemplateRef<unknown>
  }

  onCtaClick(event: Event): void {
    if (!this.ctaHref) this.onCta?.(event)
  }

  private reconcile(hasContent: SlotReader): void {
    const badge = this.badgeWrap?.nativeElement
    const description = this.descriptionWrap?.nativeElement
    const interval = this.intervalWrap?.nativeElement
    const badgeCapture = this.badgeCapture?.nativeElement
    if (badgeCapture) {
      this.badgeSlot.set(hasContent(badgeCapture))
      this.badgeSlotRead.set(true)
    }
    if (description) this.descriptionSlot.set(hasContent(description))
    if (interval) this.intervalSlot.set(hasContent(interval))
    // port's content: read the label's capture, not the button.
    const ctaLabelCapture = this.ctaLabelCapture?.nativeElement
    this.ctaLabelSlot.set(hasContent(ctaLabelCapture))
    for (const capture of [badgeCapture, ctaLabelCapture]) {
      placeContentBefore(capture, capture)
      setElementPresent(capture, false)
    }
    setElementPresent(badge, this.showBadge())
    setElementPresent(description, this.showDescription())
    setElementPresent(interval, this.showInterval())
    this.syncCta()
  }

  private syncCta(): void {
    const anchor = this.ctaAnchor?.nativeElement
    const button = this.ctaButton?.nativeElement
    if (!anchor || !button) return
    if (!this.showCta()) {
      setElementPresent(button, false)
      setElementPresent(anchor, false)
      return
    }
    const href = Boolean(this.ctaHref)
    setElementPresent(button, true)
    setElementPresent(anchor, href)
    placeElement(button, href ? anchor : null)
  }
}

(Member comments are shortened to their first sentence, and the 33 longest are left out to fit; the full declaration is in node_modules/@molecule/app-subscription-plan-card-angular/dist/subscription-plan-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.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

  • Requires the app's i18n and ClassMap providers (useTranslation() / getClassMap() fall back to the bonded providers, and throw when neither is wired).

  • Prefer onCta with your router's navigate function for SPA navigation; ctaHref renders a plain anchor and causes a full page load.

  • recommended highlights the card (outline + primary CTA color) and, when badge is omitted, shows a "Recommended" badge via the plan.recommended i18n key.

  • price/interval are opaque display nodes — the app owns currency formatting and localization.

  • Node props are projected content: name, description, price, interval, ctaLabel and badge are selected by [slot=<name>]; plain strings may also be passed as inputs.

Translations

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