@molecule/app-drawing-toolbar-angular
Feature · drawing-toolbar · App (browser) · v1.1.1 · Apache-2.0
Whiteboard / canvas tool selector (select, rect, ellipse, arrow, text, sticky, pen)
npm install @molecule/app-drawing-toolbar-angularHow it works
@molecule/app-drawing-toolbar-angular is a ready-made drawing-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, signal } from '@angular/core'
import { DrawingToolbar } from '@molecule/app-drawing-toolbar-angular'
@Component({
selector: 'app-whiteboard',
standalone: true,
imports: [DrawingToolbar],
template: `
<div
mol-drawing-toolbar
[tools]="[
{ id: 'select', label: 'Select', icon: '↖' },
{ id: 'pen', label: 'Pen', icon: '✎' },
{ id: 'rectangle', label: 'Rectangle', icon: '▭' },
]"
[selectedId]="tool()"
[onSelect]="setTool"
orientation="horizontal"
>
<app-stroke-width slot="extras" />
</div>
`,
})
export class Whiteboard {
readonly tool = signal('select')
readonly setTool = (id: string): void => this.tool.set(id)
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular whiteboard / canvas / annotation tool selector — the counterpart of
@molecule/app-drawing-toolbar-react: the same props and the same DOM for
the same input.
Exports <DrawingToolbar> (a role="toolbar" row/column of toggle
buttons) and the DrawingTool type. Selection is controlled: pass
selectedId + onSelect.
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 { DrawingToolbar } from '@molecule/app-drawing-toolbar-angular'
@Component({
selector: 'app-whiteboard',
standalone: true,
imports: [DrawingToolbar],
template: `
<div
mol-drawing-toolbar
[tools]="[
{ id: 'select', label: 'Select', icon: '↖' },
{ id: 'pen', label: 'Pen', icon: '✎' },
{ id: 'rectangle', label: 'Rectangle', icon: '▭' },
]"
[selectedId]="tool()"
[onSelect]="setTool"
orientation="horizontal"
>
<app-stroke-width slot="extras" />
</div>
`,
})
export class Whiteboard {
readonly tool = signal('select')
readonly setTool = (id: string): void => this.tool.set(id)
}
Type
feature
Installation
npm install @molecule/app-drawing-toolbar-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
DrawingTool
A single drawing tool entry rendered as a toolbar button. Node values
(icon) are templated content in Angular (an input cannot carry a node),
so it is typed unknown: pass a plain string or an <ng-template> ref.
interface DrawingTool {
/** Stable tool id — the `@for` track key and the `onSelect` payload. */
id: string
/** Accessible label (`aria-label` + `title`); also the iconless fallback's first character. */
label: string
/** Optional icon content: a string or a template ref. When absent, the first character of `label` is shown. */
icon?: unknown
}
DrawingToolbarProps
Props accepted by the DrawingToolbar component (React's names).
Node props (extras) are projected content in Angular (an input cannot
carry a node), so they are typed unknown: pass them in the host template
as [slot=extras] content.
interface DrawingToolbarProps {
/** Tools to render. Defaults to the standard set (select → eraser). */
tools?: DrawingTool[]
/** Currently selected tool id. */
selectedId?: string
/** Called when the user picks a tool, with the tool's id. */
onSelect?: (id: string) => void
/** Optional extra controls (color picker, stroke width), projected as `[slot=extras]` content. */
extras?: unknown
/** Layout — default `'horizontal'`. Set `'vertical'` for left-rail toolbars. */
orientation?: 'horizontal' | 'vertical'
/** Extra classes. */
className?: string
}
Classes
DrawingToolbar
DrawingToolbar component.
Whiteboard / canvas / annotation tool selector. The host IS the root
<div> (div[mol-drawing-toolbar]), matching React's root exactly. Each
tool renders as a size="sm" button — solid/primary while selected (with
aria-pressed), ghost otherwise — labelled aria-label/title from the
tool's label. The toolbar's own aria-label resolves through
t('drawingToolbar.label') with an English fallback. Angular's @for
tracks the tool's id, the way React keys its button list.
extras is projected content ([slot=extras]) rendered after the tool
buttons — an input cannot carry a node. A tool's icon may be a plain
string or an <ng-template> ref.
@Component({
selector: 'div[mol-drawing-toolbar]',
standalone: true,
imports: [Button, NgTemplateOutlet],
inputs: ['tools', 'selectedId', 'onSelect', 'orientation', 'className'],
host: {
role: 'toolbar',
'[class]': 'classes()',
'[attr.aria-label]': 'label()',
},
template: `@for (tl of toolList(); track tl.id) {
<button
mol-button
[variant]="tl.id === selectedId ? 'solid' : 'ghost'"
[size]="'sm'"
[attr.aria-pressed]="tl.id === selectedId"
[attr.aria-label]="tl.label"
[attr.title]="tl.label"
(click)="select(tl)"
>
@if (isTemplate(tl.icon)) {
<ng-container [ngTemplateOutlet]="tl.icon" />
} @else if (tl.icon != null) {
{{ tl.icon }}
} @else {
{{ firstChar(tl.label) }}
}
</button>
}
<ng-content select="[slot=extras]"></ng-content>`,
})
export class DrawingToolbar {
/** Tools to render (the standard set until an input says otherwise). */
tools?: DrawingTool[]
/** Currently selected tool id. */
selectedId?: string
/** Called when the user picks a tool, with the tool's id. */
onSelect?: (id: string) => void
/** Layout (`'horizontal'` until an input says otherwise). */
orientation?: 'horizontal' | 'vertical'
/** Extra classes. */
className?: string
/** The translation function, captured in the injection context. */
private readonly i18n = useTranslation()
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* The tools to render (React's default parameter: a later-bound write of
* `undefined` must not erase the default list).
* @returns The tool list.
*/
toolList(): DrawingTool[] {
return this.tools ?? DEFAULT_TOOLS
}
/**
* Computes the toolbar class list (React's
* `cm.cn(orientation === 'vertical' ? cm.stack(1) : cm.flex({ align: 'center', gap: 'xs' }), className)`).
* @returns The class string.
*/
classes(): string {
const cm = this.cm()
return cm.cn(
(this.orientation ?? 'horizontal') === 'vertical'
? cm.stack(1)
: cm.flex({ align: 'center', gap: 'xs' }),
this.className,
)
}
/**
* The translated toolbar label (React's `t('drawingToolbar.label', {}, …)`).
* @returns The label text.
*/
label(): string {
return this.i18n.t('drawingToolbar.label', {}, { defaultValue: 'Drawing tools' })
}
/**
* The first character of a tool's label — React's iconless fallback.
* @param label - The tool's label.
* @returns The first character, or `undefined` for an empty label.
*/
firstChar(label: string): string | undefined {
return label[0]
}
/**
* Calls `onSelect` with the clicked tool's id (React's `onClick`).
* @param tool - The tool whose button was clicked.
*/
select(tool: DrawingTool): void {
this.onSelect?.(tool.id)
}
/**
* 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 -
toolsdefaults to a standard set (select, rectangle, ellipse, arrow, text, sticky, pen, eraser) — always pass your own list, withlabelalready translated via yourt()call (labels feed each button'saria-labelandtitleverbatim). -
The toolbar's own aria-label resolves through
t('drawingToolbar.label')with an English fallback; companion locale bond:@molecule/app-locales-drawing-toolbar. -
When a tool has no
icon, the first character oflabelis shown. -
extrasis projected content ([slot=extras]), rendered after the tool buttons — drop in color pickers or stroke-width controls. -
Buttons come from
@molecule/app-ui-angular; requires a wired ClassMap bond and the app i18n provider (standard molecule app setup).
Translations
Translation strings are provided by @molecule/app-locales-drawing-toolbar.