@molecule/app-contact-display-angular

Feature · contact-display · App (browser) · v1.2.2 · Apache-2.0

Formatted contact display: name + avatar + email/phone with icons + optional address

npm install @molecule/app-contact-display-angular

npm · Source on GitHub

How it works

@molecule/app-contact-display-angular is a ready-made contact-display 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 { ContactDisplay } from '@molecule/app-contact-display-angular'

@Component({
  selector: 'app-profile',
  standalone: true,
  imports: [ContactDisplay],
  template: `
    <div
      mol-contact-display
      layout="row"
      [contact]="{
        name: 'Jane Smith',
        email: 'jane@example.com',
        phone: '+1 555 0100',
        role: 'Product Designer',
        company: 'Acme Corp',
      }"
      (click)="openProfile('jane')"
    ></div>
  `,
})
export class Profile {
  openProfile(id: string): void {}
}

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

Reference

Angular formatted contact display — the counterpart of @molecule/app-contact-display-react: the same props and the same DOM for the same input.

Exports <ContactDisplay> — avatar + name + role + email/phone/address with card/row/compact layouts.

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 { ContactDisplay } from '@molecule/app-contact-display-angular'

@Component({
  selector: 'app-profile',
  standalone: true,
  imports: [ContactDisplay],
  template: `
    <div
      mol-contact-display
      layout="row"
      [contact]="{
        name: 'Jane Smith',
        email: 'jane@example.com',
        phone: '+1 555 0100',
        role: 'Product Designer',
        company: 'Acme Corp',
      }"
      (click)="openProfile('jane')"
    ></div>
  `,
})
export class Profile {
  openProfile(id: string): void {}
}

Type

feature

Installation

npm install @molecule/app-contact-display-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

ContactFields

Fields describing a contact rendered by ContactDisplay.

role, address and company are node-valued in React: pass a TemplateRef (the kit's form) or plain text.

interface ContactFields {
  /** Display name. */
  name: string
  /** Email address, rendered as a `mailto:` link in the card and row layouts. */
  email?: string
  /** Phone number, rendered as a `tel:` link in the card and row layouts. */
  phone?: string
  /** Role / title, shown beside the name: a `TemplateRef` or text. */
  role?: unknown
  /** Avatar image URL; without one the name's initials are shown. */
  avatarSrc?: string
  /** Postal address, shown under the phone line: a `TemplateRef` or text. */
  address?: unknown
  /** Company name, shown under the name line: a `TemplateRef` or text. */
  company?: unknown
}

ContactDisplayProps

Props accepted by the ContactDisplay component.

interface ContactDisplayProps {
  /** The contact to display. */
  contact: ContactFields
  /** Layout preset. Defaults to `'card'`. */
  layout?: 'card' | 'row' | 'compact'
  /** Optional right-side actions, projected as `[slot=actions]` content. */
  actions?: unknown
  /**
   * Activates the contact: the whole row becomes clickable through a
   * transparent native button covering it, named by the contact name (the
   * name span), so Enter and Space activate it natively. The row's inner
   * controls — the mail/tel links and the `actions` slot — sit above that
   * button and keep their own clicks.
   */
  onClick?: () => void
  /** Extra classes. */
  className?: string
}

Classes

ContactDisplay

ContactDisplay component.

Formatted contact display — avatar + name + role + email/phone with leading glyphs + optional address and company. Three layouts for different densities. The host IS the root <div> (div[mol-contact-display]), matching React's root exactly. With onClick a transparent native button covering the whole row is its first child (a click anywhere on it, Enter or Space activates the contact) and is named by the contact-name span; the mail/tel links and the actions slot sit above it and keep their own clicks. The optional right-side actions are projected ([slot=actions]); the node-valued contact.role, contact.address and contact.company arrive as TemplateRefs and render through ContactNodeOutlet, or as text. Same props, same DOM as @molecule/app-contact-display-react's ContactDisplay.

@Component({
  selector: 'div[mol-contact-display]',
  standalone: true,
  hostDirectives: [MolPlacement],
  imports: [Avatar, ContactNodeOutlet],
  inputs: ['contact', 'layout', 'onClick', 'className'],
  host: {
    '[class]': 'classes()',
  },
  // prettier-ignore
  template: `@if (hasOnClick()) {<button type="button" [attr.aria-labelledby]="nameId" data-mol-id="contact-display-open" (click)="handleClick()" [class]="openButtonClass()" [style.background]="'transparent'" [style.border]="'none'" [style.padding]="'0'"></button>}<div [class]="avatarWrapClass()"><div mol-avatar [src]="avatarSrc()" [alt]="contactName()" [name]="contactName()" [size]="avatarSize()"></div></div>
    <div [class]="detailWrapClass()">
      <div [class]="nameRowClass()"><span [attr.id]="hasOnClick() ? nameId : null" [class]="nameClass()">{{ contactName() }}</span>@if (hasRole()) {<span [class]="roleClass()">{{ roleText }}<ng-container [molContactNode]="roleTemplate()"></ng-container></span>}</div>
      @if (hasCompany()) {<div [class]="companyClass()">{{ companyText }}<ng-container [molContactNode]="companyTemplate()"></ng-container></div>}
      @if (showEmail()) {<div [class]="hasOnClick() ? raisedDetailRowClass() : detailRowClass()"><span aria-hidden="true">✉</span><a [attr.href]="'mailto:' + contactEmail()" [class]="linkClass()">{{ contactEmail() }}</a></div>}
      @if (showPhone()) {<div [class]="hasOnClick() ? raisedDetailRowClass() : detailRowClass()"><span aria-hidden="true">☎</span><a [attr.href]="'tel:' + contactPhone()" [class]="linkClass()">{{ contactPhone() }}</a></div>}
      @if (showAddress()) {<div [class]="detailRowClass()"><span aria-hidden="true">⌂</span><span>{{ addressText }}<ng-container [molContactNode]="addressTemplate()"></ng-container></span></div>}
    </div><div #actionsWrap [class]="actionsWrapClass()"><ng-content select="[slot=actions]"></ng-content></div>`,
})
export class ContactDisplay {
  /** The contact to display. */
  contact?: ContactFields
  /** Layout preset. */
  layout?: 'card' | 'row' | 'compact'
  onClick?: () => void
  /** Extra classes on the outer wrapper. */
  className?: string

  /** The actions slot's always-mounted wrapper (projection needs the capture point). */
  @ViewChild('actionsWrap') private actionsWrapRef?: ElementRef<HTMLDivElement>

  /** The host element (the root `<div>`), the actions' bare parent. */
  private readonly host = inject(ElementRef)

  readonly nameId = `contact-display-name-${nextNameId++}`

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

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

  /** The active layout (React's `layout = 'card'` default). */
  activeLayout(): 'card' | 'row' | 'compact' {
    return this.layout ?? 'card'
  }

  /** Whether the compact layout hides the contact details. */
  isCompact(): boolean {
    return this.activeLayout() === 'compact'
  }

  /** The contact's display name. */
  contactName(): string {
    return fieldText(this.contact?.name)
  }

  /** The contact's email address. */
  contactEmail(): string {
    return fieldText(this.contact?.email)
  }

  /** The contact's phone number. */
  contactPhone(): string {
    return fieldText(this.contact?.phone)
  }

  /** The avatar image URL, when the contact has one. */
  avatarSrc(): string | undefined {
    return this.contact?.avatarSrc
  }

  /** The avatar size preset for the layout. */
  avatarSize(): 'sm' | 'md' {
    return this.isCompact() ? 'sm' : 'md'
  }

  /** Whether the role renders (React's `role && …` truthiness). */
  hasRole(): boolean {
    return Boolean(this.contact?.role)
  }

  /** Whether the company renders. */
  hasCompany(): boolean {
    return Boolean(this.contact?.company)
  }

  /** Whether the email line renders (React's `!isCompact && email`). */
  showEmail(): boolean {
    return !this.isCompact() && Boolean(this.contactEmail())
  }

  /** Whether the phone line renders. */
  showPhone(): boolean {
    return !this.isCompact() && Boolean(this.contactPhone())
  }

  /** Whether the address line renders. */
  showAddress(): boolean {
    return !this.isCompact() && Boolean(this.contact?.address)
  }

  /** The role as a template, when the caller passed a node. */
  roleTemplate(): TemplateRef<unknown> | null {
    return asTemplate(this.contact?.role)
  }

  /** The role's text (React renders a string role as text). */
  get roleText(): string {
    return fieldText(this.contact?.role)
  }

  /** The company as a template, when the caller passed a node. */
  companyTemplate(): TemplateRef<unknown> | null {
    return asTemplate(this.contact?.company)
  }

  /** The company's text. */
  get companyText(): string {
    return fieldText(this.contact?.company)
  }

  /** The address as a template, when the caller passed a node. */
  addressTemplate(): TemplateRef<unknown> | null {
    return asTemplate(this.contact?.address)
  }

  /** The address's text. */
  get addressText(): string {
    return fieldText(this.contact?.address)
  }

  classes(): string {
    return this.cm().cn(
      this.cm().flex({
        align: this.activeLayout() === 'card' ? 'start' : 'center',
        gap: this.isCompact() ? 'sm' : 'md',
        direction: this.activeLayout() === 'card' ? 'col' : 'row',
      }),
      this.hasOnClick() ? this.cm().position('relative') : undefined,
      this.className,
    )
  }

  /** Whether the open button renders (React's `onClick ? …`). */
  hasOnClick(): boolean {
    return Boolean(this.onClick)
  }

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

  /** The avatar column's class (`cm.flex1` + `cm.stack(1)`). */
  detailWrapClass(): string {
    return this.cm().cn(this.cm().flex1, this.cm().stack(1))
  }

  /** The name line's class (`cm.flex({ align: 'baseline', gap: 'sm' })`). */
  nameRowClass(): string {
    return this.cm().flex({ align: 'baseline', gap: 'sm' })
  }

  /** The name span's class (size by layout + semibold). */
  nameClass(): string {
    return this.cm().cn(
      this.cm().textSize(this.isCompact() ? 'sm' : 'base'),
      this.cm().fontWeight('semibold'),
    )
  }

  /** The role span's class (`cm.textSize('xs')`). */
  roleClass(): string {
    return this.cm().textSize('xs')
  }

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

  /** One detail line's class (`cm.flex({ align: 'center', gap: 'xs' })` + `cm.textSize('sm')`). */
  detailRowClass(): string {
    return this.cm().cn(this.cm().flex({ align: 'center', gap: 'xs' }), this.cm().textSize('sm'))
  }

  raisedDetailRowClass(): string {
    return this.cm().cn(this.detailRowClass(), this.cm().position('relative'))
  }

  /** The mailto/tel link's class (`cm.link`). */
  linkClass(): string {
    return this.cm().cn(this.cm().link)
  }

  /** The open button's class (`cm.position('absolute')` + `cm.inset0` + `cm.cursorPointer`). */
  openButtonClass(): string {
    return this.cm().cn(this.cm().position('absolute'), this.cm().inset0, this.cm().cursorPointer)
  }

  actionsWrapClass(): string {
    return this.hasOnClick() ? this.cm().position('relative') : ''
  }

  private syncActionsSlot(hasContent: SlotReader): void {
    const wrapper = this.actionsWrapRef?.nativeElement
    if (!wrapper) return
    if (this.hasOnClick() && hasContent(wrapper)) {
      setElementPresent(wrapper, true)
      placeContent(wrapper, null)
      return
    }
    // No wrapper for React's render (no `onClick`, or nothing projected): the
    // projected nodes render bare at the wrapper's place, and the empty
    // wrapper leaves the DOM.
    placeContent(wrapper, this.host.nativeElement, wrapper)
    setElementPresent(wrapper, false)
  }

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

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

contact fields are display-only data — email/phone render as mailto:/tel: links; there is no formatting/validation. The email/phone/ address markers are text glyphs (✉ ☎ ⌂), not themed SVG icons. role, address, and company are node-valued in React: in Angular pass a TemplateRef (rendered through the package's [molContactNode] outlet) or plain text. The right-side actions are projected as [slot=actions] content. When onClick is provided the whole row becomes clickable through a transparent native button covering it, named by the contact name (the name span); the mail/tel links and the actions slot sit above that button and keep their own clicks.