@molecule/app-editor-toolbar-angular
Feature · editor-toolbar · App (browser) · v1.1.2 · Apache-2.0
Top editor toolbar with title + version badge + primary/secondary action buttons
npm install @molecule/app-editor-toolbar-angularHow it works
@molecule/app-editor-toolbar-angular is a ready-made editor-toolbar 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 { EditorToolbar } from '@molecule/app-editor-toolbar-angular'
@Component({
selector: 'app-editor',
standalone: true,
imports: [EditorToolbar],
template: `
<div
mol-editor-toolbar
[primaryActions]="[
{ id: 'save', label: 'Save', onClick: save, variant: 'outline' },
{ id: 'publish', label: 'Publish', onClick: publish, color: 'primary' },
]"
>
<span slot="title">My Blog Post</span>
<span slot="badge">Draft</span>
</div>
`,
})
export class EditorPage {
readonly save = (): void => {
console.log('save draft')
}
readonly publish = (): void => {
console.log('publish post')
}
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular editor-top toolbar — the counterpart of
@molecule/app-editor-toolbar-react: the same props (React names) and the
same DOM for the same input.
Exports <EditorToolbar> — title + badge + primary/secondary action groups —
and the ToolbarAction shape. Pair it with the editor layout's topBar
slot.
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 { EditorToolbar } from '@molecule/app-editor-toolbar-angular'
@Component({
selector: 'app-editor',
standalone: true,
imports: [EditorToolbar],
template: `
<div
mol-editor-toolbar
[primaryActions]="[
{ id: 'save', label: 'Save', onClick: save, variant: 'outline' },
{ id: 'publish', label: 'Publish', onClick: publish, color: 'primary' },
]"
>
<span slot="title">My Blog Post</span>
<span slot="badge">Draft</span>
</div>
`,
})
export class EditorPage {
readonly save = (): void => {
console.log('save draft')
}
readonly publish = (): void => {
console.log('publish post')
}
}
Type
feature
Installation
npm install @molecule/app-editor-toolbar-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
ToolbarAction
A single action item rendered as a button (or linked button) in the toolbar.
Node-valued fields (label, icon) are templated content in Angular (an
input cannot carry a node), so they are typed unknown: pass plain strings
or <ng-template> refs.
interface ToolbarAction {
/** Stable id — the `@for` track key of the action's button. */
id: string
/** Button label — text or a template ref. */
label: unknown
/** Optional leading icon inside the button — text or a template ref. */
icon?: unknown
/**
* Called when the action's button is clicked. React's DOM click handler
* receives the click event, so the callback may take it.
*/
onClick?: (event?: MouseEvent) => void
/** Renders the button inside a plain anchor with this href. */
href?: string
/** Disables the button. */
disabled?: boolean
/** Visual variant — defaults to `'ghost'`. */
variant?: 'solid' | 'outline' | 'ghost' | 'link'
/** Optional color variant for emphasis. */
color?: 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info'
}
EditorToolbarProps
Props accepted by EditorToolbar — the same props
@molecule/app-editor-toolbar-react accepts. Node props (title, badge,
leading) are projected content in Angular (an input cannot carry a node),
so they are typed unknown: pass them in the host template, not as values.
interface EditorToolbarProps {
/** Document title, projected as `[slot=title]` content. */
title: unknown
/** Optional version / status badge, projected as `[slot=badge]` content. */
badge?: unknown
/** Primary actions (e.g. Save, Publish) rendered on the right. */
primaryActions?: ToolbarAction[]
/** Secondary icon-only actions (theme, settings, help). */
secondaryActions?: ToolbarAction[]
/** Optional leading slot (back button, breadcrumb), projected as `[slot=leading]`. */
leading?: unknown
/** Sticky top — defaults to true. */
sticky?: boolean
/** Extra classes. */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
}
Classes
EditorToolbar
EditorToolbar component.
Editor-page top toolbar — title + optional version/status badge + primary
actions (Save, Publish, Test) + secondary icon actions. The host IS the
root <div> (div[mol-editor-toolbar]), matching React's root exactly.
The title row and actions row use React's ClassMap tokens, the 1px divider
renders between non-empty primary and secondary groups, and the sticky
inline style applies by default (sticky defaults to true). Action
labels render verbatim — the component has no t() calls of its own.
Node props (title, badge, leading) are projected content
([slot=title], [slot=badge], [slot=leading]) — an input cannot carry
a node. An action's node fields (label, icon) are template refs from a
data prop, rendered through ngTemplateOutlet. Angular's @for tracks the
action's id, the way React keys its button lists.
@Component({
selector: 'div[mol-editor-toolbar]',
standalone: true,
imports: [Button, NgTemplateOutlet],
inputs: ['primaryActions', 'secondaryActions', 'sticky', 'className', 'dataMolId'],
host: {
'[class]': 'classes()',
'[attr.data-mol-id]': 'dataMolId ?? null',
'[style]': 'stickyStyle()',
},
template: `<div [class]="titleRowClasses()">
<ng-content select="[slot=leading]"></ng-content>
<h1 [class]="headingClasses()"><ng-content select="[slot=title]"></ng-content></h1>
<ng-content select="[slot=badge]"></ng-content>
</div>
<div [class]="actionsRowClasses()">
@for (action of primaryList(); track action.id) {
@if (action.href) {
<a [attr.href]="action.href">
<ng-container
[ngTemplateOutlet]="actionButton"
[ngTemplateOutletContext]="context(action)"
/>
</a>
} @else {
<ng-container
[ngTemplateOutlet]="actionButton"
[ngTemplateOutletContext]="context(action)"
/>
}
}
@if (showDivider()) {
<span aria-hidden="true" [style]="dividerStyle"></span>
}
@for (action of secondaryList(); track action.id) {
@if (action.href) {
<a [attr.href]="action.href">
<ng-container
[ngTemplateOutlet]="actionButton"
[ngTemplateOutletContext]="context(action)"
/>
</a>
} @else {
<ng-container
[ngTemplateOutlet]="actionButton"
[ngTemplateOutletContext]="context(action)"
/>
}
}
</div>
<ng-template #actionButton let-action>
<button
mol-button
[variant]="action.variant ?? 'ghost'"
[color]="action.color ?? 'primary'"
[disabled]="action.disabled ?? false"
(click)="runAction(action, $event)"
>
@if (isTemplate(action.icon)) {
<ng-container [ngTemplateOutlet]="action.icon" />
} @else if (action.icon) {
{{ action.icon }}
}
@if (action.label) {
<span>
@if (isTemplate(action.label)) {
<ng-container [ngTemplateOutlet]="action.label" />
} @else {
{{ action.label }}
}
</span>
}
</button>
</ng-template>`,
})
export class EditorToolbar {
/** Primary actions (e.g. Save, Publish) rendered on the right. */
primaryActions?: ToolbarAction[]
/** Secondary icon-only actions (theme, settings, help). */
secondaryActions?: ToolbarAction[]
/** Sticky top (defaults to true at read time). */
sticky?: boolean
/** Extra classes on the outer wrapper. */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
/** React's divider inline style text. */
readonly dividerStyle = DIVIDER_STYLE
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* Computes the wrapper class list (React's
* `cm.cn(cm.flex({ align, justify, gap, wrap }), cm.sp('px', 4), cm.sp('py', 2), className)`).
* @returns The class string.
*/
classes(): string {
return this.cm().cn(
this.cm().flex({ align: 'center', justify: 'between', gap: 'md', wrap: 'wrap' }),
this.cm().sp('px', 4),
this.cm().sp('py', 2),
this.className,
)
}
/**
* The title row's class (`cm.flex({ align: 'center', gap: 'sm' })`).
* @returns The class string.
*/
titleRowClasses(): string {
return this.cm().flex({ align: 'center', gap: 'sm' })
}
/**
* The heading's class (`cm.cn(cm.textSize('base'), cm.fontWeight('semibold'))`).
* @returns The class string.
*/
headingClasses(): string {
return this.cm().cn(this.cm().textSize('base'), this.cm().fontWeight('semibold'))
}
/**
* The actions row's class (`cm.flex({ align: 'center', gap: 'sm' })`).
* @returns The class string.
*/
actionsRowClasses(): string {
return this.cm().flex({ align: 'center', gap: 'sm' })
}
/**
* The primary actions to render (React's `primaryActions = []` default: a
* later-bound write of `undefined` must not erase it).
* @returns The action list.
*/
primaryList(): ToolbarAction[] {
return this.primaryActions ?? []
}
/**
* The secondary actions to render (React's `secondaryActions = []` default).
* @returns The action list.
*/
secondaryList(): ToolbarAction[] {
return this.secondaryActions ?? []
}
/**
* Whether React renders the divider — only when both groups are non-empty.
* @returns True when the divider renders.
*/
showDivider(): boolean {
return this.secondaryList().length > 0 && this.primaryList().length > 0
}
/**
* The toolbar's inline style text (React's
* `style={sticky ? { position: 'sticky', top: 0, zIndex: 10 } : undefined}`);
* null when not sticky, so no `style` attribute renders.
* @returns The style text or null.
*/
stickyStyle(): string | null {
return (this.sticky ?? true) ? STICKY_STYLE : null
}
/**
* The `ngTemplateOutlet` context for one action.
* @param action - The action to expose to the button template.
* @returns The context object.
*/
context(action: ToolbarAction): { $implicit: ToolbarAction } {
return { $implicit: action }
}
/**
* Runs one action's callback (React passes the click event through).
* @param action - The action whose button was clicked.
* @param event - The native click event.
*/
runAction(action: ToolbarAction, event: MouseEvent): void {
action.onClick?.(event)
}
/**
* Whether the value is a node template (a node-valued prop's Angular
* representation). Checked structurally — `TemplateRef` is a type-only
* import here, and the check must survive any bundler.
* @param value - The prop value.
* @returns True for a template ref.
*/
isTemplate(value: unknown): value is TemplateRef<unknown> {
return (
typeof value === 'object' &&
value !== null &&
typeof (value as TemplateRef<unknown>).createEmbeddedView === 'function'
)
}
}
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 -
stickydefaults to TRUE and appliesposition: sticky; top: 0with a TRANSPARENT background — pass a surface class viaclassNameor page content will scroll visibly through the toolbar. -
Action
labels render verbatim (into the button and nothing else) — pass already-translated strings; the component has not()calls or locale bond of its own. -
Prefer
onClickoverhref: anhrefaction wraps the button in a plain anchor (full page navigation, and invalid button-in-anchor nesting for assistive tech). -
A 1px divider renders between the primary and secondary groups only when both are non-empty.
-
Node props are projected content:
title,badgeandleadingare selected by[slot=title],[slot=badge]and[slot=leading]. -
Buttons come from
@molecule/app-ui-angular; requires a wired ClassMap bond (standard molecule app setup).