@molecule/app-onboarding-modal-angular
Feature · onboarding-modal · App (browser) · v1.1.3 · Apache-2.0
Multi-step welcome / onboarding overlay with prev/next + skip
npm install @molecule/app-onboarding-modal-angularHow it works
@molecule/app-onboarding-modal-angular is a ready-made onboarding-modal 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, signal } from '@angular/core'
import { OnboardingModal, type OnboardingStep } from '@molecule/app-onboarding-modal-angular'
@Component({
selector: 'app-onboarding',
standalone: true,
imports: [OnboardingModal],
template: `
<mol-onboarding-modal
[open]="open()"
[steps]="steps"
[onClose]="close"
[onComplete]="close"
></mol-onboarding-modal>
`,
})
export class Onboarding {
readonly steps: OnboardingStep[] = [
{ id: 'welcome', title: 'Welcome!', body: 'Let us show you around.' },
{ id: 'features', title: 'Key Features', body: 'Build apps in minutes.' },
{ id: 'done', title: "You're all set", body: 'Start your first project.' },
]
readonly open = signal(true)
readonly close = (): void => this.open.set(false)
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular multi-step onboarding overlay.
Exports <OnboardingModal> and the OnboardingStep type. It is the Angular
counterpart of @molecule/app-onboarding-modal-react: the same props (React
names), the same DOM for the same input, and the same onClose /
onComplete calls, so an app switches framework by changing only the
package name in its imports.
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, signal } from '@angular/core'
import { OnboardingModal, type OnboardingStep } from '@molecule/app-onboarding-modal-angular'
@Component({
selector: 'app-onboarding',
standalone: true,
imports: [OnboardingModal],
template: `
<mol-onboarding-modal
[open]="open()"
[steps]="steps"
[onClose]="close"
[onComplete]="close"
></mol-onboarding-modal>
`,
})
export class Onboarding {
readonly steps: OnboardingStep[] = [
{ id: 'welcome', title: 'Welcome!', body: 'Let us show you around.' },
{ id: 'features', title: 'Key Features', body: 'Build apps in minutes.' },
{ id: 'done', title: "You're all set", body: 'Start your first project.' },
]
readonly open = signal(true)
readonly close = (): void => this.open.set(false)
}
Type
feature
Installation
npm install @molecule/app-onboarding-modal-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
OnboardingStep
A single step in an onboarding flow, with a title, body, and optional media. Node-valued fields arrive as a template (the conformance kit's data-prop node value), or as plain text.
interface OnboardingStep {
/** Stable identity, used as the step dot's key. */
id: string
/** Step heading: text, or a template. */
title: string | TemplateRef<unknown>
/** Step body: text, or a template. */
body: string | TemplateRef<unknown>
/** Optional media / illustration: text, or a template. */
media?: string | TemplateRef<unknown>
}
OnboardingModalProps
Props accepted by OnboardingModal — the same props @molecule/app-onboarding-modal-react accepts.
interface OnboardingModalProps {
/** Whether the modal is open. */
open: boolean
/** Called when closing (skip / X / completion). React passes the click event for Skip and the chrome close button. */
onClose?: (event?: unknown) => void
/** Onboarding steps. */
steps: OnboardingStep[]
/** Called when the user clicks "Done" on the last step. */
onComplete?: () => void
/** Show "Skip" link in the footer. Defaults to true. */
allowSkip?: boolean
/** Initial step index (uncontrolled). */
defaultStep?: number
}
Classes
OnboardingModal
OnboardingModal component.
Multi-step onboarding overlay — title + body + media, with prev/next
navigation and an optional Skip link. React's root is the Modal's
document.body portal (a fragment), so nothing of the host's own remains in
the page: the host's content renders in front of the host's place and the
host leaves the page (placeContentBefore + setElementPresent); the dialog
itself is <mol-modal>, which portals to the body exactly as React's does.
Tracks its own step state (React's useState(defaultStep)), so the position
persists across close/reopen.
onComplete fires only from the final-step button; closing via Skip or the
chrome close button calls onClose alone — persist "onboarding seen" in
onClose if skipping should count as done.
@Component({
selector: 'mol-onboarding-modal',
standalone: true,
imports: [Button, Modal, NgTemplateOutlet],
hostDirectives: [MolPlacement],
inputs: ['open', 'onClose', 'steps', 'onComplete', 'allowSkip', 'defaultStep'],
// prettier-ignore
template: `<mol-modal [open]="open && total() > 0" (close)="close($event)" [attr.aria-labelledby]="titleId">@if (total() > 0) {<div [class]="cm().stack(4)">@if (hasMedia()) {<div [class]="mediaClasses()">@if (mediaTemplate(); as tpl) {<ng-container [ngTemplateOutlet]="tpl"></ng-container>} @else {{{ mediaText() }}}</div>}<h2 [id]="titleId" [class]="titleClasses()">@if (titleTemplate(); as tpl) {<ng-container [ngTemplateOutlet]="tpl"></ng-container>} @else {{{ titleText() }}}</h2><div [class]="bodyClasses()">@if (bodyTemplate(); as tpl) {<ng-container [ngTemplateOutlet]="tpl"></ng-container>} @else {{{ bodyText() }}}</div><footer [class]="footerClasses()"><div [class]="dotsClasses()">@for (s of steps; track s.id; let i = $index) {<span aria-hidden="true" [style.width]="'6px'" [style.height]="'6px'" [style.border-radius]="'50%'" [style.background]="dotBackground(i)"></span>}</div><div [class]="buttonsClasses()">@if (allowSkipEnabled() && !isLastStep()) {<button mol-button [variant]="'ghost'" [size]="'sm'" (click)="close($event)">{{ skipLabel() }}</button>}@if (stepIndex() > 0) {<button mol-button [variant]="'ghost'" [size]="'sm'" (click)="back()">{{ backLabel() }}</button>}<button mol-button [variant]="'solid'" [color]="'primary'" (click)="next()">{{ primaryLabel() }}</button></div></footer></div>}</mol-modal>`,
})
export class OnboardingModal implements OnInit {
/** Whether the modal is open. */
open = false
/** Called when closing (skip / X / completion). */
onClose?: (event?: unknown) => void
/** Onboarding steps. */
steps: OnboardingStep[] = []
/** Called when the user clicks "Done" on the last step. */
onComplete?: () => void
/** Show "Skip" link in the footer (defaults to true at read time). */
allowSkip?: boolean
/** Initial step index (React's `useState` initial value). */
defaultStep?: number
readonly titleId = `mol-onboarding-modal-title-${++nextTitleId}`
/** The current step index (React's `useState(defaultStep)`), written after the inputs bind. */
private readonly step = signal(0)
/** i18n state; its `t` reads the provider on every call. */
private readonly i18n = useTranslation()
/** The component's host element (React renders no element of its own). */
private readonly host: ElementRef<HTMLElement> = inject(ElementRef)
constructor() {
// React's root is the body portal (a fragment): nothing of the host's own stays, so the
// bare modal renders in front of the host's place and the host leaves the page.
usePlacement(() => {
placeContentBefore(this.host.nativeElement, this.host.nativeElement)
setElementPresent(this.host.nativeElement, false)
})
}
/** Seeds the step index from `defaultStep` once, exactly as React's `useState(defaultStep)` does — a later `defaultStep` write is ignored. */
ngOnInit(): void {
this.step.set(this.defaultStep ?? 0)
}
/** The current class map. */
cm(): UIClassMap {
return getClassMap()
}
/** The number of steps. */
total(): number {
return this.steps?.length ?? 0
}
/** The current step index, unclamped (React's raw `step`). */
stepIndex(): number {
return this.step()
}
/** The step the content shows, clamped into the list (React's `Math.max`/`Math.min`). */
current(): OnboardingStep | undefined {
return this.steps[Math.max(0, Math.min(this.step(), this.total() - 1))]
}
/** React's `isLast = step >= total - 1`, on the raw index. */
isLastStep(): boolean {
return this.step() >= this.total() - 1
}
/** React's `allowSkip = true` default: only an explicit `false` hides Skip. */
allowSkipEnabled(): boolean {
return this.allowSkip !== false
}
/** Advance to the next step, or complete and close if on the last step. */
next(): void {
if (this.isLastStep()) {
this.onComplete?.()
this.onClose?.()
} else this.step.update((value) => value + 1)
}
/** Step back one position (never below the starting index). */
back(): void {
this.step.update((value) => value - 1)
}
/** Close without completing (React's Skip / chrome close). */
close(event?: unknown): void {
if (event === undefined || event === null) this.onClose?.()
else this.onClose?.(event)
}
/** The heading's class list (React's `cm.cn(cm.textSize('xl'), cm.fontWeight('bold'))`). */
titleClasses(): string {
return this.cm().cn(this.cm().textSize('xl'), this.cm().fontWeight('bold'))
}
/** The body wrapper's class (React's `cm.textSize('sm')`). */
bodyClasses(): string {
return this.cm().textSize('sm')
}
/** The media wrapper's class (React's `cm.flex({ align: 'center', justify: 'center' })`). */
mediaClasses(): string {
return this.cm().flex({ align: 'center', justify: 'center' })
}
/** The footer's class (React's `cm.flex({ align: 'center', justify: 'between', gap: 'sm' })`). */
footerClasses(): string {
return this.cm().flex({ align: 'center', justify: 'between', gap: 'sm' })
}
/** The dots row's class (React's `cm.flex({ align: 'center', gap: 'xs' })`). */
dotsClasses(): string {
return this.cm().flex({ align: 'center', gap: 'xs' })
}
/** The buttons row's class (React's `cm.flex({ align: 'center', gap: 'sm' })`). */
buttonsClasses(): string {
return this.cm().flex({ align: 'center', gap: 'sm' })
}
/** One dot's fill: React sets the active dot to `currentColor`. */
dotBackground(index: number): string {
return index === this.step() ? 'currentColor' : 'rgba(0,0,0,0.2)'
}
/** Whether a node-valued field is plain text (React renders it as a text child). */
isText(value: unknown): value is string {
return typeof value === 'string'
}
/** Narrows a node-valued field to an embedded template. */
templateOf(value: unknown): TemplateRef<unknown> | null {
return value instanceof TemplateRef ? value : null
}
/** The media as a template, when the caller passed one. */
mediaTemplate(): TemplateRef<unknown> | null {
return this.templateOf(this.current()?.media)
}
/** The media as text (React renders a string node as text). */
mediaText(): string {
const media = this.current()?.media
return this.isText(media) ? media : ''
}
/** React's truthiness check on `current.media`: a template or a non-empty text. */
hasMedia(): boolean {
const media = this.current()?.media
return this.templateOf(media) !== null || (this.isText(media) && media !== '')
}
/** The heading as a template, when the caller passed one. */
titleTemplate(): TemplateRef<unknown> | null {
return this.templateOf(this.current()?.title)
}
/** The heading as text. */
titleText(): string {
const title = this.current()?.title
return this.isText(title) ? title : ''
}
/** The body as a template, when the caller passed one. */
bodyTemplate(): TemplateRef<unknown> | null {
return this.templateOf(this.current()?.body)
}
/** The body as text. */
bodyText(): string {
const body = this.current()?.body
return this.isText(body) ? body : ''
}
/** The Skip label (React's `onboarding.skip`). */
skipLabel(): string {
return this.i18n.t('onboarding.skip', {}, { defaultValue: 'Skip' })
}
/** The Back label (React's `onboarding.back`). */
backLabel(): string {
return this.i18n.t('onboarding.back', {}, { defaultValue: 'Back' })
}
/** The primary button's label: Get started on the last step, Next otherwise (React's `onboarding.done` / `onboarding.next`). */
primaryLabel(): string {
return this.isLastStep()
? this.i18n.t('onboarding.done', {}, { defaultValue: 'Get started' })
: this.i18n.t('onboarding.next', {}, { defaultValue: 'Next' })
}
}
(Member comments are shortened to their first sentence, and the longest is left out to fit; the full declaration is in node_modules/@molecule/app-onboarding-modal-angular/dist/onboarding-modal.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
Requires a wired ClassMap bond and an Angular i18n provider — the composed
Modal / Button (from @molecule/app-ui-angular) and useTranslation()
all depend on them. Pair with @molecule/app-locales-onboarding-modal for
the Skip / Back / Next / Get-started strings in 79 languages.
Step position is UNCONTROLLED and persists across close/reopen — a user who
closed on step 3 reopens on step 3. onComplete fires only from the
final-step button; closing via Skip or the chrome close button calls
onClose alone — persist "onboarding seen" in onClose if skipping should
count as done.
Translations
Translation strings are provided by @molecule/app-locales-onboarding-modal.