@molecule/app-chart-wrapper-solid

Feature · chart-wrapper · App (browser) · v1.1.2 · Apache-2.0

Solid ChartCard and ChartLegend wrappers around @molecule/app-charts

npm install @molecule/app-chart-wrapper-solid

npm · Source on GitHub

How it works

@molecule/app-chart-wrapper-solid is a ready-made chart-wrapper feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { onCleanup, onMount } from 'solid-js'

import { ChartCard, ChartLegend } from '@molecule/app-chart-wrapper-solid'
import { createBarChart } from '@molecule/app-charts'

export function RevenueChart() {
  let canvas: HTMLCanvasElement | undefined
  onMount(() => {
    if (!canvas) return
    const chart = createBarChart(canvas, {
      labels: ['Jan', 'Feb', 'Mar'],
      datasets: [{ label: 'Revenue', data: [4200, 5800, 5100] }],
    })
    onCleanup(() => chart.destroy())
  })
  return <canvas ref={canvas} height={240} />
}

export function Chart() {
  return (
    <ChartCard
      title="Monthly Revenue"
      description="Last 12 months"
      footer={
        <ChartLegend
          items={[
            { id: 'revenue', label: 'Revenue', color: '#4f46e5' },
            { id: 'expenses', label: 'Expenses', color: '#e11d48' },
          ]}
        />
      }
    >
      <RevenueChart />
    </ChartCard>
  )
}

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

Reference

Solid ChartCard + ChartLegend wrappers around @molecule/app-charts.

Exports:

  • ChartCard — uniform chrome (title / description / actions / summary / body / footer) around a chart rendering. minChartHeight (default 240) stops responsive charts collapsing; dataMolId sets data-mol-id.
  • ChartLegend — swatch + label (+ value) legend. Items become toggle buttons when onToggle is provided.
  • ChartLegendItem type.

These wrappers provide ONLY the surrounding chrome. The chart itself is whatever you render as children — typically a canvas driven by createLineChart/createBarChart from @molecule/app-charts (via a real bonded ChartProvider) or your own chart component. There is no <BarChart> component in @molecule/app-charts.

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 { onCleanup, onMount } from 'solid-js'

import { ChartCard, ChartLegend } from '@molecule/app-chart-wrapper-solid'
import { createBarChart } from '@molecule/app-charts'

export function RevenueChart() {
  let canvas: HTMLCanvasElement | undefined
  onMount(() => {
    if (!canvas) return
    const chart = createBarChart(canvas, {
      labels: ['Jan', 'Feb', 'Mar'],
      datasets: [{ label: 'Revenue', data: [4200, 5800, 5100] }],
    })
    onCleanup(() => chart.destroy())
  })
  return <canvas ref={canvas} height={240} />
}

export function Chart() {
  return (
    <ChartCard
      title="Monthly Revenue"
      description="Last 12 months"
      footer={
        <ChartLegend
          items={[
            { id: 'revenue', label: 'Revenue', color: '#4f46e5' },
            { id: 'expenses', label: 'Expenses', color: '#e11d48' },
          ]}
        />
      }
    >
      <RevenueChart />
    </ChartCard>
  )
}

Type

feature

Installation

npm install @molecule/app-chart-wrapper-solid @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js

API

Interfaces

ChartCardProps

Props accepted by the ChartCard component.

interface ChartCardProps {
  /** Card heading. */
  title: JSX.Element
  /** Optional supporting description. */
  description?: JSX.Element
  /** Optional right-aligned actions (range selector, export menu, filter). */
  actions?: JSX.Element
  /** Optional KPI summary row shown between header and chart (e.g. "Total: 12,345 +12%"). */
  summary?: JSX.Element
  /** Chart content — any rendering driven by `@molecule/app-charts`. */
  children: JSX.Element
  /** Optional footer below the chart (legend, source attribution). */
  footer?: JSX.Element
  /** Set a minimum chart height so responsive charts don't collapse. Defaults to `240`. */
  minChartHeight?: number
  /** Extra classes on the Card. */
  className?: string
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
}

ChartLegendItem

Describes a single series entry rendered in the chart legend.

interface ChartLegendItem {
  /** Series id — the value `onToggle` receives. */
  id: string
  /** Series label. */
  label: JSX.Element
  /** Swatch color (any valid CSS color or ClassMap token string). */
  color: string
  /** Optional value / count display next to the label. */
  value?: JSX.Element
  /** Whether the series is hidden (greyed out). */
  hidden?: boolean
}

ChartLegendProps

Props accepted by the ChartLegend component.

interface ChartLegendProps {
  /** The legend's series. */
  items: ChartLegendItem[]
  /** Called when an item is toggled. */
  onToggle?: (id: string) => void
  /** Layout direction. Defaults to `'horizontal'`. */
  layout?: 'horizontal' | 'vertical'
  /** Extra classes. */
  className?: string
}

Functions

ChartCard(props)

Uniform chrome around a chart rendering — header + actions + optional summary strip + chart body + optional footer.

The chart library itself comes from the @molecule/app-charts bond; this package only provides the surrounding container.

This is the Solid counterpart of @molecule/app-chart-wrapper-react: the same props (React names), the same ClassMap tokens, and the same DOM for the same input.

function ChartCard(props: ChartCardProps): JSX.Element
  • props — Component props (see ChartCardProps).

Returns: The rendered chart card.

ChartLegend(props)

Chart legend — swatch + label (+ optional value) per series. When onToggle is provided, items become buttons that toggle series visibility.

This is the Solid counterpart of @molecule/app-chart-wrapper-react: the same props (React names), the same ClassMap tokens, and the same DOM for the same input.

function ChartLegend(props: ChartLegendProps): JSX.Element
  • props — Component props (see ChartLegendProps).

Returns: The rendered chart legend.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-solid ^3.14.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

@molecule/app-charts' built-in provider renders a non-functional placeholder notice (and logs a one-time console warning), not a real chart. Bond the Chart.js provider once at startup — import { provider } from '@molecule/app-charts-chartjs'; setProvider(provider) — so createChart / createBarChart draw real charts (or render your own chart component as children). Legend items labels/values are consumer-provided nodes; pass translated strings via t().