@molecule/app-presence-indicator-angular
Feature · presence-indicator · App (browser) · v1.1.2 · Apache-2.0
Online/offline dot + presence overlay for avatars and user chips
npm install @molecule/app-presence-indicator-angularHow it works
@molecule/app-presence-indicator-angular is a ready-made presence-indicator 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 { AvatarWithPresence, PresenceDot } from '@molecule/app-presence-indicator-angular'
@Component({
selector: 'app-user',
standalone: true,
imports: [PresenceDot, AvatarWithPresence],
template: `
<span>{{ name }} <span mol-presence-dot status="online"></span></span>
<span mol-avatar-with-presence status="away" corner="bottom-right">
<img [src]="avatarUrl" [alt]="name" width="40" height="40" />
</span>
`,
})
export class User {
name = 'Ada'
avatarUrl = '/avatar.png'
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular presence indicator primitives — the counterpart of
@molecule/app-presence-indicator-react, with the same props and the same
DOM for the same input.
Exports:
<PresenceDot>— small colored status dot (online/away/busy/offline).<AvatarWithPresence>— wraps any avatar and overlays a presence dot.PresenceStatustype.
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.tsJSDoc, not this file.
Quick Start
import { Component } from '@angular/core'
import { AvatarWithPresence, PresenceDot } from '@molecule/app-presence-indicator-angular'
@Component({
selector: 'app-user',
standalone: true,
imports: [PresenceDot, AvatarWithPresence],
template: `
<span>{{ name }} <span mol-presence-dot status="online"></span></span>
<span mol-avatar-with-presence status="away" corner="bottom-right">
<img [src]="avatarUrl" [alt]="name" width="40" height="40" />
</span>
`,
})
export class User {
name = 'Ada'
avatarUrl = '/avatar.png'
}
Type
feature
Installation
npm install @molecule/app-presence-indicator-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
PresenceDotProps
Props accepted by PresenceDot — the same props React's PresenceDot accepts.
interface PresenceDotProps {
/** The presence state to display. */
status: PresenceStatus
/** Diameter in pixels. Defaults to 10. */
size?: number
/** Position — `'inline'` default; `'overlay'` positions absolutely for avatar overlays. */
position?: 'inline' | 'overlay'
/** Overlay corner when `position="overlay"`. Defaults to `'bottom-right'`. */
corner?: 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left'
/** Accessible label override; defaults to `t('presenceIndicator.aria.presence', …)`. */
ariaLabel?: string
/** Extra classes. */
className?: string
}
AvatarWithPresenceProps
Props accepted by AvatarWithPresence — the same props React's
AvatarWithPresence accepts. The decorated avatar (children) is
projected content in Angular (an input cannot carry a node), so it is typed
unknown: pass it in the host template, not as a value.
interface AvatarWithPresenceProps {
/** The avatar / media to decorate, projected as the element's default content. */
children?: unknown
/** Presence status; omit to hide the dot. */
status?: PresenceStatus
/** Corner placement of the dot. Defaults to `'bottom-right'`. */
corner?: 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left'
/** Dot size. Defaults to 10. */
dotSize?: number
/** Extra classes on the outer wrapper. */
className?: string
}
Types
PresenceStatus
Union of supported user-presence states displayed by the dot.
type PresenceStatus = 'online' | 'away' | 'busy' | 'offline'
Classes
AvatarWithPresence
AvatarWithPresence component.
Wraps any avatar/image and overlays a presence dot at a corner.
Non-destructive — just positions the dot; the child is untouched. The host
IS the root <span> (span[mol-avatar-with-presence]), matching React's
root exactly. The avatar is projected content (the element's default
projection); the dot is rendered after it only while status is set, as
React renders it only when status is truthy. Same props, same DOM as
@molecule/app-presence-indicator-react's AvatarWithPresence.
@Component({
selector: 'span[mol-avatar-with-presence]',
standalone: true,
imports: [PresenceDot],
inputs: ['status', 'corner', 'dotSize', 'className'],
host: {
'[class]': 'classes()',
'[style.display]': '"inline-block"',
},
template: `<ng-content></ng-content>
@if (showDot()) {
<span
mol-presence-dot
[status]="status"
[position]="'overlay'"
[corner]="cornerValue()"
[size]="dotSize"
></span>
}`,
})
export class AvatarWithPresence {
/** Presence status; omit to hide the dot. */
status?: PresenceStatus
/** Corner placement of the dot. Defaults to `'bottom-right'`. */
corner?: 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left'
/** Dot size. Defaults to 10. */
dotSize?: number
/** Extra classes on the outer wrapper. */
className?: string
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* Computes the wrapper's class list (React's `cm.position('relative')` plus
* the caller's classes).
* @returns The class string.
*/
classes(): string {
return this.cm().cn(this.cm().position('relative'), this.className)
}
/**
* Whether the dot renders: React's `{status && <PresenceDot />}` truthiness.
* @returns True while a status is set.
*/
showDot(): boolean {
return Boolean(this.status)
}
/**
* The dot's corner (React's `corner = 'bottom-right'` default parameter).
* @returns The corner placement.
*/
cornerValue(): 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left' {
return this.corner ?? 'bottom-right'
}
}
PresenceDot
PresenceDot component.
Small colored circle indicating user presence. Use inline next to a name, or
with position="overlay" attached to the corner of an avatar. The host IS
the root <span> (span[mol-presence-dot]), matching React's root exactly;
every inline declaration is applied through host style bindings (the CSSOM,
as react-dom does). Same props, same DOM as
@molecule/app-presence-indicator-react's PresenceDot.
The default aria-label resolves through t() with the
presenceIndicator.aria.presence key (an explicitly translated status word
per presenceIndicator.status.* key), so it follows the active locale;
ariaLabel overrides it.
@Component({
selector: 'span[mol-presence-dot]',
standalone: true,
inputs: ['status', 'size', 'position', 'corner', 'ariaLabel', 'className'],
host: {
role: 'status',
'[class]': 'classes()',
'[attr.aria-label]': 'label()',
'[style.display]': '"inline-block"',
'[style.width]': 'sizePx()',
'[style.height]': 'sizePx()',
'[style.border-radius]': '"50%"',
'[style.box-shadow]': 'overlayValue("0 0 0 2px var(--color-surface)")',
'[style.position]': 'overlayValue("absolute")',
'[style.top]': 'cornerValue("top")',
'[style.bottom]': 'cornerValue("bottom")',
'[style.right]': 'cornerValue("right")',
'[style.left]': 'cornerValue("left")',
},
template: '',
})
export class PresenceDot {
/** The presence state to display. */
status?: PresenceStatus
/** Diameter in pixels. Defaults to 10. */
size?: number
/** Position — `'inline'` default; `'overlay'` positions absolutely. */
position?: 'inline' | 'overlay'
/** Overlay corner when `position="overlay"`. Defaults to `'bottom-right'`. */
corner?: 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left'
/** Accessible label override; defaults to `t('presenceIndicator.aria.presence', …)`. */
ariaLabel?: string
/** Extra classes. */
className?: string
/** The i18n provider access (locale-reactive through the notifications signal). */
private readonly i18n = useTranslation()
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* Computes the dot's class list.
* @returns The class string.
*/
classes(): string {
return this.cm().cn(this.statusClass(), this.className)
}
/**
* The class that fills the dot for the current status (React's tone
* mapping): the theme's solid success/warning/error tone for
* online/away/busy, the theme's neutral border grey for offline — never a
* hardcoded hex. An absent status adds no class, matching React's missing
* background declaration.
* @returns The tone class, or null when no status is bound.
*/
statusClass(): string | null {
const cm = this.cm()
switch (this.status) {
case 'online':
return cm.progressColor('success')
case 'away':
return cm.progressColor('warning')
case 'busy':
return cm.progressColor('error')
case 'offline':
return cm.bgBorder
default:
return null
}
}
/**
* The translated word for one presence state (React's `statusLabel`): one
* literal `t()` call per value of `PresenceStatus`, so molecule's i18n
* gate sees each key exist. Every `presenceIndicator.status.*` key ships in
* the `@molecule/app-locales-presence-indicator` bond. An absent status keeps
* React's `Presence: undefined` shape for the label built from it.
* @returns The status's word in the active locale.
*/
statusLabel(): string {
const t = this.i18n.t
switch (this.status) {
case 'online':
return t('presenceIndicator.status.online', undefined, { defaultValue: 'online' })
case 'away':
return t('presenceIndicator.status.away', undefined, { defaultValue: 'away' })
case 'busy':
return t('presenceIndicator.status.busy', undefined, { defaultValue: 'busy' })
case 'offline':
return t('presenceIndicator.status.offline', undefined, { defaultValue: 'offline' })
default:
return `${this.status}`
}
}
/**
* The accessible label (React's
* `ariaLabel ?? t('presenceIndicator.aria.presence', …)`).
* @returns The label text.
*/
label(): string {
return (
this.ariaLabel ??
this.i18n.t(
'presenceIndicator.aria.presence',
{ status: this.statusLabel() },
{ defaultValue: 'Presence: {{status}}' },
)
)
}
/**
* The dot's diameter (React's `size = 10` default parameter).
* @returns The width/height, in pixels.
*/
sizePx(): string {
return `${this.size ?? 10}px`
}
/**
* Whether the dot is positioned absolutely for an avatar overlay (React's
* `position === 'overlay'`).
* @returns True for the overlay position.
*/
isOverlay(): boolean {
return (this.position ?? 'inline') === 'overlay'
}
/**
* One overlay-only declaration: its value when the dot is an overlay, or
* null (removed) when it is inline.
* @param value - The declaration's value for the overlay position.
* @returns The value, or null.
*/
overlayValue(value: string): string | null {
return this.isOverlay() ? value : null
}
/**
* One corner edge declaration (React's `corner.includes(edge)` checks).
* @param edge - The edge to set when the corner includes it.
* @returns `'0px'` when the edge applies, otherwise null.
*/
cornerValue(edge: 'top' | 'bottom' | 'right' | 'left'): string | null {
if (!this.isOverlay()) return null
return (this.corner ?? 'bottom-right').includes(edge) ? '0px' : null
}
}
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.5.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
The default aria-label is the English string "Presence: <status>" — pass
ariaLabel (e.g. from t()) in localized apps; the package has no locale
bond. position="overlay" positions absolutely, so the dot must sit inside
a relatively-positioned parent — <AvatarWithPresence> provides that
wrapper. Status colors are fixed semantic hues (green/yellow/red/gray),
identical in both themes; the overlay ring color follows
var(--color-surface). The host element IS the component's root <span>;
the avatar decorated by <AvatarWithPresence> is projected content.
Translations
Translation strings are provided by @molecule/app-locales-presence-indicator.