@molecule/app-forum-thread-row-angular

Feature · forum-thread-row · App (browser) · v1.1.3 · Apache-2.0

Discussion / forum thread row with vote score, reply count, pin/lock badges, tags

npm install @molecule/app-forum-thread-row-angular

npm · Source on GitHub

How it works

@molecule/app-forum-thread-row-angular is a ready-made forum-thread-row 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 { ForumThreadRow } from '@molecule/app-forum-thread-row-angular'

@Component({
  selector: 'app-thread',
  standalone: true,
  imports: [ForumThreadRow],
  template: `
    <article
      mol-forum-thread-row
      title="How do I reset my password?"
      excerpt="I tried the forgot-password link but never received an email."
      [voteScore]="42"
      [replyCount]="7"
      [viewCount]="320"
      author="alice"
      createdAt="2 hours ago"
      [onClick]="openThread"
    >
      <span slot="tags">help</span>
    </article>
  `,
})
export class Thread {
  openThread(): void {
    // navigate to the thread…
  }
}

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

Reference

Angular forum / discussion-board thread row — the counterpart of @molecule/app-forum-thread-row-react: the same props and the same DOM for the same input.

Exports ForumThreadRow — title, optional excerpt, vote score, reply/view counts, pin/lock badges, author, timestamp, tag chips, and an optional voteControls slot for inline up/down buttons.

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 { ForumThreadRow } from '@molecule/app-forum-thread-row-angular'

@Component({
  selector: 'app-thread',
  standalone: true,
  imports: [ForumThreadRow],
  template: `
    <article
      mol-forum-thread-row
      title="How do I reset my password?"
      excerpt="I tried the forgot-password link but never received an email."
      [voteScore]="42"
      [replyCount]="7"
      [viewCount]="320"
      author="alice"
      createdAt="2 hours ago"
      [onClick]="openThread"
    >
      <span slot="tags">help</span>
    </article>
  `,
})
export class Thread {
  openThread(): void {
    // navigate to the thread…
  }
}

Type

feature

Installation

npm install @molecule/app-forum-thread-row-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

ForumThreadRowProps

Props for ForumThreadRow — the same props @molecule/app-forum-thread-row-react accepts. Node-valued props (title, excerpt, author, createdAt, tags, voteControls) are projected content in Angular (an input cannot carry a node): pass a string value through the input, and element content in the host template as [slot=<name>] content.

interface ForumThreadRowProps {
  /** Thread title; element content is projected as `[slot=title]` content. */
  title?: unknown
  /** Optional snippet of the OP body; projected as `[slot=excerpt]` content. */
  excerpt?: unknown
  /** Aggregate vote score / upvotes. */
  voteScore?: number
  /** Reply count. */
  replyCount?: number
  /** View count. */
  viewCount?: number
  /** Optional pinned indicator. */
  pinned?: boolean
  /** Optional locked indicator. */
  locked?: boolean
  /** Author display; projected as `[slot=author]` content. */
  author?: unknown
  /** Created-at display; projected as `[slot=createdAt]` content. */
  createdAt?: unknown
  /** Tag chips; projected as `[slot=tags]` content. */
  tags?: unknown
  /** Right-side voting controls; projected as `[slot=voteControls]` content. */
  voteControls?: unknown
  /**
   * Activates the row: the whole row is clickable through a transparent native
   * button laid over it (Enter and Space activate it natively), named by the
   * title — the `<h3>` itself takes the generated id. The `voteControls` and
   * `tags` slots sit above that button and keep their own clicks. Called with
   * no arguments, the way React's transparent button calls it.
   */
  onClick?: () => void
  /** Extra classes. */
  className?: string
}

Classes

ForumThreadRow

ForumThreadRow component.

Forum / discussion-board thread row. Shows the title, optional excerpt, vote score + reply/view counts, pin/lock badges, author, and timestamp. With an onClick the whole row is clickable through a transparent native button laid over it (Enter and Space activate it natively), named by the title — the <h3> itself takes the generated id; the voteControls and tags wrappers sit above that button and keep their own clicks. The host IS the root <article> (article[mol-forum-thread-row]), matching React's root exactly. The marker labels ("Pinned" / "Locked", announced through role="img" + aria-label) and the counter labels ("votes", "{{count}} replies", "{{count}} views") go through t() with those English defaults — the same text, through the same keys, React renders.

The node props are projected slots: title, excerpt, author, createdAt, tags and voteControls each render inside the wrapper element React renders for them. String inputs render as text instead — React's truthiness branch applies: an empty string renders nothing. The capture wrappers reconcile against that in the placement function registered in the constructor (each wrapper renders its own text first, so the slot is read past that one leading node).

@Component({
  selector: 'article[mol-forum-thread-row]',
  standalone: true,
  hostDirectives: [MolPlacement],
  inputs: [
    'title',
    'excerpt',
    'voteScore',
    'replyCount',
    'viewCount',
    'pinned',
    'locked',
    'author',
    'createdAt',
    'tags',
    'voteControls',
    'onClick',
    'className',
  ],
  host: {
    '[class]': 'classes()',
  },
  template: `@if (onClick) {
      <button
        type="button"
        [attr.aria-labelledby]="nameId"
        data-mol-id="forum-thread-row-open"
        (click)="handleClick()"
        [class]="openButtonClasses()"
        style="background: transparent; border: medium; padding: 0px"
      ></button>
    }
    <div #voteControlsWrap [class]="voteControlsClasses()">
      {{ voteControlsText() }}
      <ng-content select="[slot=voteControls]"></ng-content>
    </div>
    <div #scoreWrap [class]="scoreClasses()">
      <span [class]="scoreValueClasses()">{{ voteScore }}</span>
      <span [class]="scoreLabelClasses()">{{ votesText() }}</span>
    </div>
    <div [class]="stackClasses()">
      <header [class]="headerClasses()">
        @if (pinned) {
          <span role="img" [attr.aria-label]="pinnedText()" [title]="pinnedText()">📌</span>
        }
        @if (locked) {
          <span role="img" [attr.aria-label]="lockedText()" [title]="lockedText()">🔒</span>
        }
        <h3 [attr.id]="onClick ? nameId : null" [class]="titleClasses()">
          {{ titleText() }}
          <ng-content select="[slot=title]"></ng-content>
        </h3>
      </header>
      <p #excerptWrap [class]="excerptClasses()">
        {{ excerptText() }}
        <ng-content select="[slot=excerpt]"></ng-content>
      </p>
      <div [class]="metaClasses()">
        <span #authorWrap [class]="authorClasses()">
          {{ authorText() }}
          <ng-content select="[slot=author]"></ng-content>
        </span>
        <span #createdAtWrap [class]="createdAtClasses()">
          · {{ createdAtText() }}
          <ng-content select="[slot=createdAt]"></ng-content>
        </span>
        @if (repliesText() !== undefined) {
          <span [class]="countClasses()">· {{ repliesText() }}</span>
        }
        @if (viewsText() !== undefined) {
          <span [class]="countClasses()">· {{ viewsText() }}</span>
        }
      </div>
      <div #tagsWrap [class]="tagsClasses()">
        {{ tagsText() }}
        <ng-content select="[slot=tags]"></ng-content>
      </div>
    </div>`,
})
export class ForumThreadRow {
  title?: unknown
  excerpt?: unknown
  voteScore?: number
  replyCount?: number
  viewCount?: number
  pinned?: boolean
  /** Optional locked indicator. */
  locked?: boolean
  author?: unknown
  createdAt?: unknown
  tags?: unknown
  voteControls?: unknown
  onClick?: () => void
  /** Extra classes. */
  className?: string

  readonly nameId = `forum-thread-row-${nextNameId++}`

  @ViewChild('voteControlsWrap') voteControlsWrap?: ElementRef<HTMLElement>
  @ViewChild('scoreWrap') scoreWrap?: ElementRef<HTMLElement>
  @ViewChild('excerptWrap') excerptWrap?: ElementRef<HTMLElement>
  @ViewChild('authorWrap') authorWrap?: ElementRef<HTMLElement>
  @ViewChild('createdAtWrap') createdAtWrap?: ElementRef<HTMLElement>
  @ViewChild('tagsWrap') tagsWrap?: ElementRef<HTMLElement>

  private readonly i18n = useTranslation()

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

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

  classes(): string {
    return this.cm().cn(
      this.cm().flex({ align: 'start', gap: 'sm' }),
      this.cm().sp('p', 3),
      this.onClick ? this.cm().position('relative') : undefined,
      this.className,
    )
  }

  openButtonClasses(): string {
    return this.cm().cn(this.cm().position('absolute'), this.cm().inset0, this.cm().cursorPointer)
  }

  voteControlsClasses(): string {
    return this.cm().cn(
      this.cm().shrink0,
      this.onClick ? this.cm().position('relative') : undefined,
    )
  }

  scoreClasses(): string {
    return this.cm().cn(this.cm().shrink0, this.cm().textCenter, this.cm().stack(0))
  }

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

  scoreLabelClasses(): string {
    return this.cm().cn(this.cm().textSize('xs'))
  }

  pinnedText(): string {
    return this.i18n.t('forumThreadRow.aria.pinned', undefined, { defaultValue: 'Pinned' })
  }

  lockedText(): string {
    return this.i18n.t('forumThreadRow.aria.locked', undefined, { defaultValue: 'Locked' })
  }

  votesText(): string {
    return this.i18n.t('forumThreadRow.label.votes', undefined, { defaultValue: 'votes' })
  }

  repliesText(): string | undefined {
    return this.replyCount === undefined
      ? undefined
      : this.i18n.t(
          'forumThreadRow.label.replies',
          { count: this.replyCount },
          {
            defaultValue: '{{count}} replies',
          },
        )
  }

  viewsText(): string | undefined {
    return this.viewCount === undefined
      ? undefined
      : this.i18n.t(
          'forumThreadRow.label.views',
          { count: this.viewCount },
          {
            defaultValue: '{{count}} views',
          },
        )
  }

  stackClasses(): string {
    return this.cm().cn(this.cm().flex1, this.cm().stack(1))
  }

  headerClasses(): string {
    return this.cm().flex({ align: 'center', gap: 'sm', wrap: 'wrap' })
  }

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

  excerptClasses(): string {
    return this.cm().cn(this.cm().textSize('sm'))
  }

  metaClasses(): string {
    return this.cm().flex({ align: 'center', gap: 'sm', wrap: 'wrap' })
  }

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

  createdAtClasses(): string {
    return this.cm().cn(this.cm().textSize('xs'))
  }

  countClasses(): string {
    return this.cm().cn(this.cm().textSize('xs'))
  }

  tagsClasses(): string {
    return this.cm().cn(
      this.cm().flex({ align: 'center', gap: 'xs', wrap: 'wrap' }),
      this.onClick ? this.cm().position('relative') : undefined,
    )
  }

  private textOf(value: unknown): string {
    return typeof value === 'string' || typeof value === 'number' ? String(value) : ''
  }

  /** The title input's text. */
  titleText(): string {
    return this.textOf(this.title)
  }

  /** The excerpt input's text. */
  excerptText(): string {
    return this.textOf(this.excerpt)
  }

  /** The author input's text. */
  authorText(): string {
    return this.textOf(this.author)
  }

  createdAtText(): string {
    return this.textOf(this.createdAt)
  }

  /** The tags input's text. */
  tagsText(): string {
    return this.textOf(this.tags)
  }

  voteControlsText(): string {
    return this.textOf(this.voteControls)
  }

  private hasVoteControls(hasContent: SlotReader): boolean {
    return this.voteControlsText() !== '' || hasContent(this.voteControlsWrap?.nativeElement, 1)
  }

  handleClick(): void {
    this.onClick?.()
  }

  private reconcile(hasContent: SlotReader): void {
    const hasVoteControls = this.hasVoteControls(hasContent)
    setElementPresent(this.voteControlsWrap?.nativeElement, hasVoteControls)
    setElementPresent(
      this.scoreWrap?.nativeElement,
      this.voteScore !== undefined && !hasVoteControls,
    )
    const excerpt = this.excerptWrap?.nativeElement
    const author = this.authorWrap?.nativeElement
    const createdAt = this.createdAtWrap?.nativeElement
    const tags = this.tagsWrap?.nativeElement
    setElementPresent(excerpt, this.excerptText() !== '' || hasContent(excerpt, 1))
    setElementPresent(author, this.authorText() !== '' || hasContent(author, 1))
    setElementPresent(createdAt, this.createdAtText() !== '' || hasContent(createdAt, 1))
    setElementPresent(tags, this.tagsText() !== '' || hasContent(tags, 1))
  }
}

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

  • Styling routes through getClassMap() — a ClassMap bond (e.g. @molecule/app-ui-tailwind) must be wired or rendering throws.

  • KNOWN GAP (same as React): the counter labels ("votes", "replies", "views") and the pin/lock aria-labels are hardcoded English (there is no companion locale bond yet). For localized apps, pass pre-formatted content via tags / voteControls or wrap the row until the package routes text through t().

  • The row has no data-mol-id support yet; add your own wrapper attribute if AI-agent/e2e selectors need to target it.

  • Node-valued props are projected content: title, excerpt, author, createdAt, tags and voteControls are selected by [slot=<name>]; string inputs render as text with React's truthiness branch (an empty string renders nothing).

Translations

Translation strings are provided by @molecule/app-locales-forum-thread-row.