@molecule/app-drawing-toolbar-solid

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

npm · Source on GitHub

How it works

@molecule/app-drawing-toolbar-solid 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 { createSignal } from 'solid-js'
import { DrawingToolbar } from '@molecule/app-drawing-toolbar-solid'

const [tool, setTool] = createSignal('select')

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

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

Reference

Solid whiteboard / canvas / annotation tool selector.

Exports <DrawingToolbar> (a role="toolbar" row/column of toggle buttons) — the Solid 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 { createSignal } from 'solid-js'
import { DrawingToolbar } from '@molecule/app-drawing-toolbar-solid'

const [tool, setTool] = createSignal('select')

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

Type

feature

Installation

npm install @molecule/app-drawing-toolbar-solid @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js

API

Interfaces

DrawingTool

A single drawing tool entry rendered as a toolbar button.

interface DrawingTool {
  /** Stable tool id — the list 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?: JSX.Element | 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?: JSX.Element
  /** Layout — default `'horizontal'`. Set `'vertical'` for left-rail toolbars. */
  orientation?: 'horizontal' | 'vertical'
  /** Extra classes. */
  className?: string
}

Functions

DrawingToolbar(props)

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.

React keys each tool button by the tool's id, so a re-ordered or re-passed array moves/keeps the rendered buttons per key. Solid's For keys by reference, so the buttons are keyed through stable per-id records: the record for an id is created once and reused (a re-pass or reversal moves/keeps the rendered button, like React), while the button reads the CURRENT tool for its id reactively (a changed label updates in place).

function DrawingToolbar(props: DrawingToolbarProps): JSX.Element
  • props — Component props (see DrawingToolbarProps).

Returns: The rendered toolbar.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-solid ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-solid ^1.1.0
  • solid-js ^1.8.0

Runtime Dependencies

  • @molecule/app-solid

  • @molecule/app-ui

  • @molecule/app-ui-solid

  • solid-js

  • 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-solid; 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.