@molecule/app-drawing-toolbar-vue

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-vue

npm · Source on GitHub

How it works

@molecule/app-drawing-toolbar-vue 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 { createApp, defineComponent, h, ref } from 'vue'
import { DrawingToolbar } from '@molecule/app-drawing-toolbar-vue'

const App = defineComponent({
  setup() {
    const tool = ref('select')
    return () =>
      h(DrawingToolbar, {
        tools: [
          { id: 'select', label: 'Select', icon: '↖' },
          { id: 'pen', label: 'Pen', icon: '✎' },
          { id: 'rectangle', label: 'Rectangle', icon: '▭' },
        ],
        selectedId: tool.value,
        onSelect: (id: string) => (tool.value = id),
        orientation: 'horizontal',
      })
  },
})

createApp(App).mount('#app')

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

Reference

Vue whiteboard / canvas / annotation tool selector.

Exports <DrawingToolbar> (a role="toolbar" row/column of toggle buttons) — the Vue 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

import { createApp, defineComponent, h, ref } from 'vue'
import { DrawingToolbar } from '@molecule/app-drawing-toolbar-vue'

const App = defineComponent({
  setup() {
    const tool = ref('select')
    return () =>
      h(DrawingToolbar, {
        tools: [
          { id: 'select', label: 'Select', icon: '↖' },
          { id: 'pen', label: 'Pen', icon: '✎' },
          { id: 'rectangle', label: 'Rectangle', icon: '▭' },
        ],
        selectedId: tool.value,
        onSelect: (id: string) => (tool.value = id),
        orientation: 'horizontal',
      })
  },
})

createApp(App).mount('#app')

Type

feature

Installation

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

API

Interfaces

DrawingTool

A single drawing tool entry rendered as a toolbar button.

interface DrawingTool {
  /** Stable tool id — the button's key and the `onSelect` payload. */
  id: string
  /** Accessible label (`aria-label` + `title`); also the iconless fallback's first character. */
  label: string
  /** Optional icon content. When absent, the first character of `label` is shown. */
  icon?: VNodeChild
}

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?: VNodeChild
  /** Layout — default `'horizontal'`. Set `'vertical'` for left-rail toolbars. */
  orientation?: 'horizontal' | 'vertical'
  /** Extra classes. */
  className?: string
}

Constants

DrawingToolbar

Whiteboard / canvas / annotation tool selector. Defaults to a standard set of tools (select, rectangle, ellipse, arrow, text, sticky, pen, eraser) but apps can pass any list. 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. Buttons are keyed by the tool's id, so a re-passed equal array keeps the rendered buttons the way React keys its list.

const DrawingToolbar: DefineComponent<
  ExtractPropTypes<{
    tools: { type: PropType<DrawingTool[]>; default: () => DrawingTool[] }
    selectedId: StringConstructor
    onSelect: PropType<(id: string) => void>
    extras: null
    orientation: { type: PropType<'horizontal' | 'vertical'>; default: string }
    className: StringConstructor
  }>,
  () => VNode,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      tools: { type: PropType<DrawingTool[]>; default: () => DrawingTool[] }
      selectedId: StringConstructor
      onSelect: PropType<(id: string) => void>
      extras: null
      orientation: { type: PropType<'horizontal' | 'vertical'>; default: string }
      className: StringConstructor
    }>
  > &
    Readonly<{}>,
  { tools: DrawingTool[]; orientation: 'horizontal' | 'vertical' },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — Component props (see DrawingToolbarProps in ./types.js).

Returns: The toolbar component.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.5.0 || ^4.0.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui

  • @molecule/app-ui-vue

  • @molecule/app-vue

  • vue

  • 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 (prop or same-named slot) renders after the tool buttons — drop in color pickers or stroke-width controls.

  • Buttons come from @molecule/app-ui-vue; requires a wired ClassMap bond and the app i18n plugin (standard molecule app setup).

Translations

Translation strings are provided by @molecule/app-locales-drawing-toolbar.