Skip to content

Chart frame

Pro

The card a chart sits in: its title names the chart, a switch shows the same numbers as a table, and it has empty, loading, pending and error states. Not an M3 component (@windmorph/react-pro).

import { ChartFrame } from '@windmorph/react-pro/charts';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Props

By name or description, across the 23 props below

ChartFrame 23 props

  • titletype ReactNodeRequired

    The chart's title, a heading that names the chart inside. Untrusted text, rendered as text.

  • headingLeveltype 2 | 3 | 4 | 5 | 6default 3

    The title's heading level.

  • descriptiontype ReactNode

    Under the title: what the chart shows.

  • actionstype ReactNode

    The app's own controls, before the table switch.

  • childrentype ReactNode

    The chart. A chart inside gives the frame its numbers for the table view.

  • varianttype "filled" | "elevated" | "outlined"default "filled"

    The core Card's variant.

  • showTabletype boolean

    Whether the table view shows (controlled).

  • defaultShowTabletype booleandefault false

    Whether it shows at first. The charts give the frame their numbers once they're in the page, so the server's HTML shows the chart and the table follows; pass table for a table in the server's HTML.

  • tabletype false | ChartTable

    Rows for the table view in place of the chart's own; false for no table view.

  • emptytype ReactNode

    Shown in place of the chart (words, or an EmptyState) when there's nothing to draw: the app says so (empty={rows.length ? undefined : 'No orders yet'}), since lists and meters have no table for the frame to look at. error and loading come first, so that pattern never hides a load or a failure. The title stays and the switch goes. Its words are announced as they replace the chart: text, and the words of elements (blocks apart, a picture's alt), but not an app's own component's, whose words can't be read without drawing it (it stays where screen readers reach it); an EmptyState announces itself with its own announce.

  • loadingtype booleandefault false

    No picture yet: a placeholder in place of the chart, before empty, at the frame's least height, or the last chart's height once one has shown.

  • pendingtype booleandefault false

    New numbers loading: the last picture stays, dimmed (busy for assistive technology); with error, Try again shows it's working, and the error is said again if the retry fails.

  • errortype ReactNode

    A message in place of the chart, first of the states; announced as it replaces the chart, read as empty is: words are read once by screen readers, and an error holding a link (or an app's own component) stays where they reach it.

  • minHeighttype numberdefault 240

    The least height of the chart area, px at the default text size (growing with larger text): the placeholder's, a state's and the table view's until something has shown, and a line or bar chart's. Such a chart with no minHeight of its own fills it, its legend included (its plot takes the rest, half of it at least), so a load never moves the page; a chart's own minHeight is its plot's. A list or a meter (SegmentedList, RankedBars, Meter …) takes its own height instead; around one, pass about its height, which the first load's placeholder holds, or 0. After that, a reload holds the height last shown.

  • iconstype Partial<ChartFrameIcons>

    Replaces the table switch's and the error's icons.

  • reftype Ref<HTMLDivElement>

    Ref to the outermost element.

  • idtype string

    The outermost element's id.

Events

  • onShowTableChangetype ((show: boolean) => void)

    Called when the switch is pressed.

  • onRetrytype (() => void)

    Adds a Try again button to the error, which takes focus back if a retry fails.

Text

  • labelstype Partial<ChartFrameLabels>

    Words it shows and says. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • A title that names the chart, a description and the table switch

    Built

    Configuration · Table

  • The table view as a list of figures in a narrow column

    Built

    Configuration · Narrow

  • Empty, loading, error and pending states

    Built

    Configuration · States

  • Actions of your own in the header (actions)

    Built

    Use case · States

  • The core Card, with a table view

    Extension

    M3 has no chart container. This is the core Card with a heading that names the chart and a switch to a plain DataTable of the same numbers, loaded only when first asked for.

Theming & tokens

Set the tokens below on the frame or any ancestor. The card is the core's, so its --md-comp-card-* tokens paint the container, and the charts inside draw their point rings and the gaps between their marks in the card's colour. icons replaces the switch's and the error's icons. className goes on the card. Style each part with classNames: header, heading, title, description, actions, toggle, content, view, table, empty, error, retry, loading.

ChartFrame tokens
VariableDefaultPaints
--wm-chart-frame-padding16pxThe space inside the card.
--wm-chart-frame-gap12pxThe space between the header and the chart.
--wm-chart-frame-header-gap12pxThe space between the title and the actions.
--wm-chart-frame-header-min-height40pxThe header’s least height: the actions’ 40px buttons, with or without them.
--wm-chart-frame-actions-gapmax(8px, calc(8px - var(--md-sys-density, 0) * 4px))The space between the actions: 8px beside 40px icon buttons, and 4px more each density step down as they narrow, so their 48px targets never overlap.
--wm-chart-frame-view-durationvar(--md-sys-motion-spring-effects-default-duration)How long the chart or the table takes to fade in as the switch, or a state that ends, turns to it.
--wm-chart-frame-view-easingvar(--md-sys-motion-spring-effects-default-easing)The easing of that fade.
--wm-chart-frame-title-colorvar(--md-sys-color-on-surface)The title.
--wm-chart-frame-description-colorvar(--md-sys-color-on-surface-variant)The description under the title.
--wm-chart-frame-empty-colorvar(--md-sys-color-on-surface-variant)The words shown when there is nothing to draw.
--wm-chart-frame-pending-opacity0.5The last picture’s marks while new numbers load (a chart’s `marks`, a meter’s or a ranked or funnel list’s tracks, a segmented part’s colour): held, dimmed, never a skeleton; its words keep their contrast. A pending frame prints dimmed.
--wm-chart-frame-pending-durationvar(--md-sys-motion-spring-effects-default-duration)How long the marks take to dim and come back.
--wm-chart-frame-pending-easingvar(--md-sys-motion-spring-effects-default-easing)The easing of that change.