@molecule/app-sparkline-vue

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

Tiny inline trend chart (line, bar, dot variants) with no library dep

npm install @molecule/app-sparkline-vue

npm · Source on GitHub

How it works

@molecule/app-sparkline-vue is a ready-made sparkline 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 } from 'vue'
import { Sparkline } from '@molecule/app-sparkline-vue'

const App = defineComponent({
  setup() {
    return () =>
      h(Sparkline, {
        values: [12, 18, 15, 22, 30, 27, 35],
        variant: 'line',
        width: 80,
        height: 24,
        ariaLabel: 'Weekly revenue trend',
      })
  },
})

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

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

Reference

Vue tiny inline trend chart — line/bar/dot variants, SVG only.

Exports <Sparkline> — the Vue counterpart of @molecule/app-sparkline-react, with the same props (React names) and the same DOM for the same input, so an app switches framework by changing only the package name in its imports.

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 } from 'vue'
import { Sparkline } from '@molecule/app-sparkline-vue'

const App = defineComponent({
  setup() {
    return () =>
      h(Sparkline, {
        values: [12, 18, 15, 22, 30, 27, 35],
        variant: 'line',
        width: 80,
        height: 24,
        ariaLabel: 'Weekly revenue trend',
      })
  },
})

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

Type

feature

Installation

npm install @molecule/app-sparkline-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

API

Interfaces

SparklineProps

Props accepted by the Sparkline component.

interface SparklineProps {
  /** Numeric series — length determines the segment count. */
  values: number[]
  /** Visual variant. */
  variant?: 'line' | 'bar' | 'dot'
  /** SVG width in px. Defaults to 80. */
  width?: number
  /** SVG height in px. Defaults to 24. */
  height?: number
  /** Stroke / fill color. Defaults to currentColor. */
  color?: string
  /**
   * Optional accessible label. Overrides the translated / `defaultValue`
   * `'Trend sparkline'` (prop > `t()` > default).
   */
  ariaLabel?: string
  /** Extra classes. */
  className?: string
}

Constants

Sparkline

Tiny inline trend chart — line, bar, or dot variants. Uses SVG with no external library so it works inside cards, table cells, KPI tiles, etc. without a chart bond. Same props, same DOM as @molecule/app-sparkline-react's Sparkline.

const Sparkline: DefineComponent<
  ExtractPropTypes<{
    values: { type: PropType<number[]>; required: true }
    variant: { type: PropType<'line' | 'bar' | 'dot'>; default: undefined }
    width: { type: PropType<number>; default: undefined }
    height: { type: PropType<number>; default: undefined }
    color: { type: PropType<string>; default: undefined }
    ariaLabel: { type: PropType<string>; default: undefined }
    className: { type: PropType<string | undefined>; default: undefined }
  }>,
  () => VNode | null,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      values: { type: PropType<number[]>; required: true }
      variant: { type: PropType<'line' | 'bar' | 'dot'>; default: undefined }
      width: { type: PropType<number>; default: undefined }
      height: { type: PropType<number>; default: undefined }
      color: { type: PropType<string>; default: undefined }
      ariaLabel: { type: PropType<string>; default: undefined }
      className: { type: PropType<string | undefined>; default: undefined }
    }>
  > &
    Readonly<{}>,
  {
    variant: 'line' | 'bar' | 'dot'
    width: number
    height: number
    color: string
    ariaLabel: string
    className: string | undefined
  },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — Component props (see SparklineProps).

Returns: The sparkline 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

  • Requires a wired ClassMap bond (getClassMap() throws before bonding). The default aria-label reads through useTranslation(), so it follows the active locale.

  • The SVG is fixed-pixel (width/height props, defaults 80×24) — it does not stretch to its container. Compute px from layout if you need responsiveness.

  • color accepts any CSS color and defaults to currentColor, so the sparkline inherits the surrounding text color — set a text color on a parent (e.g. success/error) to theme it.

  • Values are min-max normalized per series; a constant series renders as a line along the bottom edge, and values: [] renders nothing.

  • Pass ariaLabel with your own translated string to override the built-in one (t('sparkline.aria.trendSparkline', …, { defaultValue: 'Trend sparkline' })).

Translations

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