@molecule/app-drawing-toolbar-svelte

Feature · drawing-toolbar · App (browser) · v1.1.2 · Apache-2.0

Whiteboard / canvas tool selector (select, rect, ellipse, arrow, text, sticky, pen)

npm install @molecule/app-drawing-toolbar-svelte

npm · Source on GitHub

How it works

@molecule/app-drawing-toolbar-svelte 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.

<script lang="ts">
  import { DrawingToolbar } from '@molecule/app-drawing-toolbar-svelte'

  let tool = $state('select')
</script>

<DrawingToolbar
  tools={[
    { id: 'select', label: 'Select', icon: '↖' },
    { id: 'pen', label: 'Pen', icon: '✎' },
    { id: 'rectangle', label: 'Rectangle', icon: '▭' },
  ]}
  selectedId={tool}
  onSelect={(id) => (tool = id)}
  orientation="horizontal"
/>

Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte

Reference

Svelte whiteboard / canvas / annotation tool selector.

Exports <DrawingToolbar> (a role="toolbar" row/column of toggle buttons) — the Svelte counterpart of @molecule/app-drawing-toolbar-react: same props and the same DOM for the same input. 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.ts JSDoc, not this file.

Quick Start

<script lang="ts">
  import { DrawingToolbar } from '@molecule/app-drawing-toolbar-svelte'

  let tool = $state('select')
</script>

<DrawingToolbar
  tools={[
    { id: 'select', label: 'Select', icon: '↖' },
    { id: 'pen', label: 'Pen', icon: '✎' },
    { id: 'rectangle', label: 'Rectangle', icon: '▭' },
  ]}
  selectedId={tool}
  onSelect={(id) => (tool = id)}
  orientation="horizontal"
/>

Type

feature

Installation

npm install @molecule/app-drawing-toolbar-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

DrawingTool

A single drawing tool entry rendered as a toolbar button.

interface DrawingTool {
  /** Stable tool id — the each-block 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 snippet or a plain string. When absent, the first character of `label` is shown. */
  icon?: Snippet | string
}

DrawingToolbarProps

Props accepted by the DrawingToolbar component (React's names).

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), rendered after the tools. */
  extras?: Snippet | string
  /** Layout — default `'horizontal'`. Set `'vertical'` for left-rail toolbars. */
  orientation?: 'horizontal' | 'vertical'
  /** Extra classes. */
  className?: string
}

Constants

DrawingToolbar

const DrawingToolbar: LegacyComponentType

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-svelte ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-svelte ^1.1.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-svelte

  • @molecule/app-ui

  • @molecule/app-ui-svelte

  • svelte

  • tools defaults to a standard set (select, rectangle, ellipse, arrow, text, sticky, pen, eraser) — always pass your own list, with label already translated via your t() call (labels feed each button's aria-label and title verbatim).

  • 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 of label is shown.

  • extras renders after the tool buttons — drop in color pickers or stroke-width controls.

  • Buttons come from @molecule/app-ui-svelte; 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.