@molecule/app-typing-indicator-angular
Feature · typing-indicator · App (browser) · v1.2.1 · Apache-2.0
Three-dot animated typing indicator for chat UIs
npm install @molecule/app-typing-indicator-angularHow it works
@molecule/app-typing-indicator-angular is a ready-made typing-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 { TypingIndicator } from '@molecule/app-typing-indicator-angular'
@Component({
selector: 'chat-view',
standalone: true,
imports: [TypingIndicator],
template: `<mol-typing-indicator [visible]="isTyping" ariaLabel="Alice is typing…" />`,
})
export class ChatView {
isTyping = true
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular three-dot typing indicator for chat UIs — the counterpart of
@molecule/app-typing-indicator-react: the same props (React names) and the
same DOM for the same input.
Exports <TypingIndicator> — CSS-only three-dot pulse animation.
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 { TypingIndicator } from '@molecule/app-typing-indicator-angular'
@Component({
selector: 'chat-view',
standalone: true,
imports: [TypingIndicator],
template: `<mol-typing-indicator [visible]="isTyping" ariaLabel="Alice is typing…" />`,
})
export class ChatView {
isTyping = true
}
Type
feature
Installation
npm install @molecule/app-typing-indicator-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
TypingIndicatorProps
Props accepted by TypingIndicator — the same props
@molecule/app-typing-indicator-react accepts.
interface TypingIndicatorProps {
/** Whether to render. Defaults to true. */
visible?: boolean
/** Dot diameter in pixels. Defaults to 6. */
dotSize?: number
/** Animation duration in ms. Defaults to 1200. */
durationMs?: number
/**
* Accessible label. Overrides the translated / `defaultValue` `'Typing…'`
* (prop > `t()` > default).
*/
ariaLabel?: string
/** Extra classes. */
className?: string
}
Classes
TypingIndicator
TypingIndicator component.
Three-dot "typing…" animation, CSS-only. React's root is the <span> when
visible and nothing when hidden, so the <span> renders in front of the
host's place and the host itself leaves the page (placeElementBefore +
setElementPresent). Each instance injects its own <style> tag with the
keyframes of its motion recipe (the ClassMap's typingPulse, else the
standard curve, read each time the indicator renders as React reads it per
render; plus a prefers-reduced-motion: reduce rule that stops the pulse
for users who ask for less motion) and renders three dots that pulse in
sequence.
The <style> element is not a template node (Angular's compiler strips
<style> elements from templates, and the rule's @keyframes text would
parse as a control-flow block): TypingStatusSpan inserts it as the
span's first child whenever the span comes into existence. The element
lives INSIDE the span, so it leaves the DOM with the view when visibility
turns off.
@Component({
selector: 'mol-typing-indicator',
standalone: true,
imports: [TypingStatusSpan],
hostDirectives: [MolPlacement],
inputs: ['visible', 'dotSize', 'durationMs', 'ariaLabel', 'className'],
template: `@if (isVisible()) {
<span
#root
mol-typing-status
role="status"
[attr.aria-label]="labelText()"
[class]="classes()"
[molTypingStylesheet]="stylesheet()"
>
<span aria-hidden="true" data-typing-dot [style]="dotStyle(0)"></span>
<span aria-hidden="true" data-typing-dot [style]="dotStyle(1)"></span>
<span aria-hidden="true" data-typing-dot [style]="dotStyle(2)"></span>
</span>
}`,
})
export class TypingIndicator {
/** Whether to render. Defaults to true at read time. */
visible?: boolean
/** Dot diameter in pixels. Defaults to 6 at read time. */
dotSize?: number
/** Animation duration in ms. Defaults to 1200 at read time. */
durationMs?: number
/**
* Accessible label. Overrides the translated / `defaultValue` `'Typing…'`
* (prop > `t()` > default), read at read time.
*/
ariaLabel?: string
/** Extra classes. */
className?: string
/** The i18n binding the translated label reads through. */
private readonly i18n = useTranslation()
/** The rendered `<span>` — React's root while visible. */
@ViewChild('root') private root?: ElementRef<HTMLElement>
/** The component's host element (React renders no element of its own). */
private readonly host = inject(ElementRef<HTMLElement>)
constructor() {
// React's root is the `<span>` itself (`visible: false` renders nothing): it renders in
// front of the host's place and the host leaves the page.
usePlacement(() => {
const root = this.root?.nativeElement
if (root) placeElementBefore(root, this.host.nativeElement)
setElementPresent(this.host.nativeElement, false)
})
}
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* Whether the indicator renders (React's default parameter: an absent or
* later-bound write of `undefined` must not hide it).
* @returns True when visible.
*/
isVisible(): boolean {
return this.visible ?? true
}
/**
* The accessible label: the prop when given, else the translated default,
* read in the template so a locale switch re-renders it.
* @returns The label.
*/
labelText(): string {
return (
this.ariaLabel ??
this.i18n.t('typingIndicator.aria.label', undefined, { defaultValue: 'Typing…' })
)
}
/**
* Computes the indicator's class list.
* @returns The class string.
*/
classes(): string {
return this.cm().cn(this.cm().flex({ align: 'center', gap: 'xs' }), this.className)
}
/**
* The motion recipe the indicator animates with: the ClassMap's `typingPulse`,
* else the standard curve. Read at each call, as React reads it per render.
* @returns The recipe.
*/
private pulse(): DotPulseMotion {
return this.cm().typingPulse ?? DEFAULT_TYPING_PULSE
}
/**
* The stylesheet for the current motion recipe: the pulse and its
* reduced-motion opt-out.
* @returns The CSS text.
*/
stylesheet(): string {
const pulse = this.pulse()
const { peakAt, restAt, dimOpacity, dimScale } = pulse
return `@keyframes ${keyframesName(pulse)} { 0%, ${restAt * 100}%, 100% { opacity: ${dimOpacity}; transform: scale(${dimScale}); } ${peakAt * 100}% { opacity: 1; transform: scale(1); } } @media (prefers-reduced-motion: reduce) { [data-typing-dot] { animation: none !important; } }`
}
/**
* Computes one dot's inline styles.
* @param index - The dot's position (0–2); each dot's delay staggers it.
* @returns The style map.
*/
dotStyle(index: number): Record<string, string> {
const pulse = this.pulse()
const durationMs = this.durationMs ?? 1200
// The original division preserves the exact serialized delay for fractional values.
const elapsed = index * durationMs
const delay =
pulse.stagger === DEFAULT_TYPING_PULSE.stagger ? elapsed / 6 : elapsed * pulse.stagger
return {
display: 'inline-block',
width: `${this.dotSize ?? 6}px`,
height: `${this.dotSize ?? 6}px`,
'border-radius': '50%',
background: 'currentColor',
animation: `${keyframesName(pulse)} ${durationMs}ms ease-in-out ${delay}ms infinite`,
}
}
}
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.9.0@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
Dots use currentColor, so the indicator inherits the surrounding text
color — wrap it in a muted-text container to dim it. The default
ariaLabel is the translated typingIndicator.aria.label (English
'Typing…', via @molecule/app-locales-typing-indicator); the ariaLabel
prop overrides it. Each instance injects its own <style> tag for the
keyframes (fine for a chat view; avoid hundreds at once). Props (documented
on the exported TypingIndicatorProps interface): visible (default true),
dotSize (px, default 6), durationMs (default 1200), ariaLabel, className.
Translations
Translation strings are provided by @molecule/app-locales-typing-indicator.