@molecule/app-list-item-row-angular

Feature · list-item-row · App (browser) · v1.2.2 · Apache-2.0

Thumbnail + title + subtitle + metadata + actions row (nav lists, mobile menus)

npm install @molecule/app-list-item-row-angular

npm · Source on GitHub

How it works

@molecule/app-list-item-row-angular is a ready-made list-item-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 { ListItemRow } from '@molecule/app-list-item-row-angular'

@Component({
  selector: 'project-list',
  standalone: true,
  imports: [ListItemRow],
  template: `
    <div
      mol-list-item-row
      title="Project Alpha"
      subtitle="Last edited 2 hours ago"
      metadata="3 collaborators · 12 files"
      [selected]="true"
      [onClick]="openProject"
    >
      <img slot="leading" src="/icons/folder.svg" alt="" width="32" height="32" />
    </div>
  `,
})
export class ProjectList {
  openProject(): void {
    // navigate('/projects/alpha')
  }
}

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

Reference

Angular generic list-item row.

Exports <ListItemRow> — leading slot (icon/avatar/thumbnail) + up to three text lines (title / subtitle / metadata) + right-side actions. Inputs: title, subtitle?, metadata?, leading?, actions?, toggle?, onClick?, selected?, disabled?, density? ('comfortable' default | 'compact'), className?. Use for nav lists, mobile menus, search results, picker dialogs, inbox threads. For table rows use <RowWithActions> from @molecule/app-data-table-ui-angular instead — this component is not a <tr>. It is the Angular counterpart of @molecule/app-list-item-row-react: same inputs and the same DOM for the same input.

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 { ListItemRow } from '@molecule/app-list-item-row-angular'

@Component({
  selector: 'project-list',
  standalone: true,
  imports: [ListItemRow],
  template: `
    <div
      mol-list-item-row
      title="Project Alpha"
      subtitle="Last edited 2 hours ago"
      metadata="3 collaborators · 12 files"
      [selected]="true"
      [onClick]="openProject"
    >
      <img slot="leading" src="/icons/folder.svg" alt="" width="32" height="32" />
    </div>
  `,
})
export class ProjectList {
  openProject(): void {
    // navigate('/projects/alpha')
  }
}

Type

feature

Installation

npm install @molecule/app-list-item-row-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

ListItemRowProps

Props accepted by the ListItemRow component (its inputs).

interface ListItemRowProps {
  /** Title — first line. A string/number renders as text; nodes are `[slot=title]` projected content. */
  title: string | number
  /** Optional second line (excerpt, description). A string/number renders as text; nodes are `[slot=subtitle]` content. */
  subtitle?: string | number
  /** Optional third line (metadata — timestamps, counts, tags). A string/number renders as text; nodes are `[slot=metadata]` content. */
  metadata?: string | number
  /** Optional leading slot — icon, avatar, thumbnail image (`[slot=leading]` content, or text). */
  leading?: string | number
  /** Optional right-side actions (buttons, action menu; `[slot=actions]` content, or text). */
  actions?: string | number
  /** Loaded boolean action rendered as its own native button, independently of read-only metadata. */
  toggle?: {
    /** The loaded server value. */
    value: boolean
    /** Saves the desired boolean and resolves with the server-confirmed boolean. */
    commit: (desired: boolean) => Promise<boolean>
    /** Label when the displayed value is true. */
    activeLabel?: string | number
    /** Label when the displayed value is false. */
    inactiveLabel?: string | number
    /** Receives a failed save after the toggle restored the last confirmed value. */
    onError?: (error: unknown) => void
    /** Button variant. */
    variant?: ButtonVariant
    /** Button color. */
    color?: ColorVariant
    /** Button size. */
    size?: Size
    /** Whether the button stretches to fill its container. */
    fullWidth?: boolean
    /** Disables the toggle (permissions, never a pending save). */
    disabled?: boolean
    /** Extra classes. */
    className?: string
    /** `data-testid`. */
    testId?: string
  }
  /**
   * Called when the row is activated (called bare, the way React forwards the
   * open button's click). The whole row is clickable through a transparent
   * native button over it, named by the title; the inner controls (the
   * `actions` slot) sit above it and keep their own clicks.
   */
  onClick?: () => void
  /** When true, sets `aria-current="true"` on the row — no built-in visual highlight; style it via `className` or host CSS. */
  selected?: boolean
  /** When true, renders in a disabled visual state. */
  disabled?: boolean
  /** Dense vs comfortable spacing. Defaults to `'comfortable'`. */
  density?: 'comfortable' | 'compact'
  /** Extra classes. */
  className?: string
}

Classes

ListItemRow

ListItemRow component.

Generic "thumbnail + text + actions" row — used everywhere: navigation lists, mobile menus, inbox-style threads, search results, picker dialogs, bookmark lists, etc. The host IS the root <div> (div[mol-list-item-row]), matching React's root exactly; the disabled row's dimmed opacity is applied inline through a host style binding (the CSSOM, as react-dom does).

The row's open action lives on a native open button — an empty, transparent <button type="button"> stretched over the whole row (data-mol-id="list-item-row-open", aria-labelledby the title), the way React renders it while the row has an onClick; Enter / Space on it run the same handler mouse clicks run. An @if in the template puts it in the DOM only while the row has an onClick (React renders no button at all otherwise), and the actions wrapper sits above it and keeps its own clicks. The projected body renders directly in the host, so the wrappers never move.

The node props are projected slots: title renders inside the title line, subtitle inside its line, metadata inside its line, leading inside the leading <div> and actions inside the right-side <div>. String inputs render as text instead — React's truthiness branch applies: an empty string renders nothing. The conditionally-rendered wrappers are taken out of the DOM when React renders nothing (setElementPresent) in ListItemRow.reconcile.

@Component({
  selector: 'div[mol-list-item-row]',
  standalone: true,
  hostDirectives: [MolPlacement],
  imports: [OptimisticToggleButton],
  inputs: [
    'title',
    'subtitle',
    'metadata',
    'leading',
    'actions',
    'toggle',
    'onClick',
    'selected',
    'disabled',
    'density',
    'className',
  ],
  host: {
    '[class]': 'classes()',
    '[attr.aria-current]': 'this.selected ? "true" : null',
    '[attr.aria-disabled]': 'this.disabled ?? null',
    '[style.opacity]': 'this.disabled ? 0.5 : null',
  },
  template: `@if (onClick) {
      <button
        type="button"
        [attr.aria-labelledby]="nameId"
        [attr.disabled]="disabled ? '' : null"
        data-mol-id="list-item-row-open"
        (click)="handleClick()"
        [class]="openButtonClasses()"
        style="background: transparent; border: medium; padding: 0px"
      ></button>
    }
    <div #leadingWrap [class]="leadingClass()">
      @if (leadingText()) {
        {{ leadingText() }}
      }
      <ng-content select="[slot=leading]"></ng-content>
    </div>
    <div [class]="stackClass()">
      <div [attr.id]="onClick ? nameId : null" [class]="titleClass()">
        @if (titleText()) {
          {{ titleText() }}
        }
        <ng-content select="[slot=title]"></ng-content>
      </div>
      <div #subtitleWrap [class]="subtitleClass()">
        @if (subtitleText()) {
          {{ subtitleText() }}
        }
        <ng-content select="[slot=subtitle]"></ng-content>
      </div>
      <div #metadataWrap [class]="metadataClass()">
        @if (metadataText()) {
          {{ metadataText() }}
        }
        <ng-content select="[slot=metadata]"></ng-content>
      </div>
    </div>
    <div #actionsWrap [class]="actionsClass()">
      @if (toggle) {
        <button
          mol-optimistic-toggle-button
          [value]="toggle.value"
          [commit]="toggle.commit"
          [onError]="toggle.onError"
          [variant]="toggle.variant"
          [color]="toggle.color"
          [size]="toggle.size"
          [fullWidth]="toggle.fullWidth ?? false"
          [disabled]="toggle.disabled ?? false"
          [className]="toggle.className"
          [testId]="toggle.testId"
        >
          <span slot="activeLabel">{{ toggle.activeLabel }}</span>
          <span slot="inactiveLabel">{{ toggle.inactiveLabel }}</span>
        </button>
      }
      @if (actionsText()) {
        {{ actionsText() }}
      }
      <ng-content select="[slot=actions]"></ng-content>
    </div>`,
})
export class ListItemRow {
  /** Title — first line (string/number renders as text; nodes are `[slot=title]` content). */
  title?: unknown
  /** Optional second line (string/number as text; nodes are `[slot=subtitle]` content). */
  subtitle?: unknown
  /** Optional third line (string/number as text; nodes are `[slot=metadata]` content). */
  metadata?: unknown
  /** Optional leading slot — icon, avatar, thumbnail (`[slot=leading]` content, or text). */
  leading?: unknown
  /** Optional right-side actions (`[slot=actions]` content, or text). */
  actions?: unknown
  toggle?: ListItemRowProps['toggle']
  /** Called when the row is activated (React's `onClick`, called bare). */
  onClick?: () => void
  /** When true, sets `aria-current="true"` on the row — no built-in visual highlight. */
  selected?: boolean
  /** When true, renders in a disabled visual state and disables the open button. */
  disabled?: boolean
  /** Dense vs comfortable spacing. */
  density?: 'comfortable' | 'compact'
  /** Extra classes. */
  className?: string

  /** Next value of the module-wide instance counter (React `useId()`'s counterpart). */
  private static nextNameId = 0

  /** The title line's id — the open button's `aria-labelledby` (React's `useId`). */
  readonly nameId = `list-item-row-title-${ListItemRow.nextNameId++}`

  /** The leading wrapper (absent when no leading value and the slot is empty). */
  @ViewChild('leadingWrap') leadingWrap?: ElementRef<HTMLElement>
  /** The subtitle line (absent when no subtitle value and the slot is empty). */
  @ViewChild('subtitleWrap') subtitleWrap?: ElementRef<HTMLElement>
  /** The metadata line (absent when no metadata value and the slot is empty). */
  @ViewChild('metadataWrap') metadataWrap?: ElementRef<HTMLElement>
  /** The actions wrapper (absent when no actions value and the slot is empty). */
  @ViewChild('actionsWrap') actionsWrap?: ElementRef<HTMLElement>

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

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

  classes(): string {
    return this.cm().cn(
      this.cm().flex({ align: 'center', gap: 'sm' }),
      this.cm().sp('px', 3),
      this.cm().sp('py', this.padY()),
      this.hasOpenAction() ? this.cm().position('relative') : undefined,
      this.className,
    )
  }

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

  /** Computes the middle stack's class (`cm.flex1` + `cm.stack(0)`). */
  stackClass(): string {
    return this.cm().cn(this.cm().flex1, this.cm().stack(0))
  }

  /** The leading wrapper's class (`cm.shrink0`). */
  leadingClass(): string {
    return this.cm().cn(this.cm().shrink0)
  }

  /** The subtitle line's class (`cm.textSize('sm')`). */
  subtitleClass(): string {
    return this.cm().cn(this.cm().textSize('sm'))
  }

  /** The metadata line's class (`cm.textSize('xs')`). */
  metadataClass(): string {
    return this.cm().cn(this.cm().textSize('xs'))
  }

  actionsClass(): string {
    return this.cm().cn(this.cm().shrink0, this.cm().position('relative'))
  }

  /** Computes the title line's class (`cm.textSize('sm')` + `cm.fontWeight('semibold')`). */
  titleClass(): string {
    return this.cm().cn(this.cm().textSize('sm'), this.cm().fontWeight('semibold'))
  }

  hasOpenAction(): boolean {
    return Boolean(this.onClick)
  }

  padY(): 2 | 3 {
    return this.density === 'compact' ? 2 : 3
  }

  titleText(): string {
    return typeof this.title === 'string' || typeof this.title === 'number'
      ? String(this.title)
      : ''
  }

  /** The subtitle input's text (React's `{subtitle}` for a text child). */
  subtitleText(): string {
    return typeof this.subtitle === 'string' || typeof this.subtitle === 'number'
      ? String(this.subtitle)
      : ''
  }

  /** The metadata input's text (React's `{metadata}` for a text child). */
  metadataText(): string {
    return typeof this.metadata === 'string' || typeof this.metadata === 'number'
      ? String(this.metadata)
      : ''
  }

  /** The leading input's text (React's `{leading}` for a text child). */
  leadingText(): string {
    return typeof this.leading === 'string' || typeof this.leading === 'number'
      ? String(this.leading)
      : ''
  }

  /** The actions input's text (React's `{actions}` for a text child). */
  actionsText(): string {
    return typeof this.actions === 'string' || typeof this.actions === 'number'
      ? String(this.actions)
      : ''
  }

  /** Runs the row's open action, the way React forwards the open button's click (bare, no event). */
  handleClick(): void {
    if (this.disabled) return
    this.onClick?.()
  }

  private reconcile(hasContent: SlotReader): void {
    const leading = this.leadingWrap?.nativeElement
    const subtitle = this.subtitleWrap?.nativeElement
    const metadata = this.metadataWrap?.nativeElement
    const actions = this.actionsWrap?.nativeElement
    setElementPresent(leading, this.leadingText() !== '' || hasContent(leading))
    setElementPresent(subtitle, this.subtitleText() !== '' || hasContent(subtitle))
    setElementPresent(metadata, this.metadataText() !== '' || hasContent(metadata))
    setElementPresent(
      actions,
      this.actionsText() !== '' || hasContent(actions) || Boolean(this.toggle),
    )
  }
}

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

  • selected only sets the aria-current="true" attribute — no built-in highlight. Pass a highlight class via className (or target [aria-current="true"] in host CSS) to make selection visible.

  • With onClick the whole row is clickable through a transparent native button over it, named by the title (aria-labelledby); Enter / Space on that button run the same handler a click anywhere on the row runs, and the inner controls (the actions slot) sit above the button and keep their own clicks.

  • disabled halves the opacity and disables the open button (no pointer cursor, no activation); there is no data-mol-id input.

  • Styling resolves through getClassMap() — wire a ClassMap bond first.

  • The host element IS React's root <div> (div[mol-list-item-row]); node props are projected slots ([slot=title], [slot=leading], …), and string inputs render as text.