Chartsv26.10.18
Pro edition

Widgets

A compact Pro markets card with SVG sparklines, signed changes and host-owned paging.

This page covers MarketsWidget, the first component of the Pro widgets catalogue: a compact card of market rows with an SVG sparkline, a signed change and host-owned pagination.

The widget ships from @unifin/chart-react/widgets and carries no chart, canvas or data feed. Rows arrive from the host; the component never fetches, subscribes or stores them.

Widget catalogue

WidgetImportStatusSurface
MarketsWidget@unifin/chart-react/widgetsBetaFive market rows, one SVG sparkline per row, a signed change, optional page dots, a footer link and an optional menu trigger

Try it live

Markets

  • Moscow Exchange IndexIMOEX+1.39%3,215.91
  • USD/RUBUSD/RUB-0.96%83.0705
  • EUR/RUBEUR/RUB-0.78%93.3629
  • RTS IndexIRTS+0.42%1,137.45
  • Moscow Exchange Government Bond IndexRGBI+0.14%107.69

The card opens on the light palette. The dots switch five prepared lists and the menu trigger opens a panel drawn by the host.

Props

PropTypeDefaultDescription
titlestringrequiredCard title, for example Markets
itemsreadonly MarketsWidgetItem[]requiredRows of the current page; the component neither slices nor sorts them
localeLocaleCoderuNumber formats and accessible texts; uz and kz use the English accessible texts
themeChartThemeneutral CSS valuesColors and radius; every missing token falls back on its own
paginationMarketsWidgetPaginationnoneControlled page dots; without the prop there are no dots
footerLinkMarketsWidgetFooterLinknoneFooter link; a missing or unsafe href removes the link
onMenu() => voidnoneMenu trigger; without the prop the ellipsis button is not rendered
asOfnumbernoneSnapshot time in epoch milliseconds, read only through aria-description
labelsPartial<MarketsWidgetLabels>RU/EN catalogueAccessible text overrides; an empty string falls back to the default
formatValue(item, locale) => stringbuilt-in formatHost value formatter; an exception or an empty string falls back to the default
formatChange(item, locale) => stringbuilt-in formatHost change formatter; an exception or an empty string falls back to the default
classNamestringnoneHost class for the outer layout; colors and radius stay in the theme
ariaLabelstringtitleAccessible name of the card section

Item fields

FieldTypeDefaultDescription
idstringrequiredUnique key of the row within the page
symbolstringrequiredTicker or short instrument code, for example IMOEX
namestringsymbolDisplay name; a long name is truncated with the full value in title
valuenumbernoneNumeric value formatted through formatNumber
formattedValuestringnoneReady value from the host; wins over value and formatValue
valueDigitsnumber2Fraction digits of the default value format, clamped to 0..8
changenumbernoneChange in percentage points: 1.39 means +1.39%
formattedChangestringnoneReady change from the host; wins over change and formatChange
trendreadonly number[]noneSparkline series; non-finite points are skipped

Import and render

import { useState } from 'react';
import { MarketsWidget, type MarketsWidgetItem } from '@unifin/chart-react/widgets';

const PAGES: readonly (readonly MarketsWidgetItem[])[] = [
  [
    { id: 'imoex', symbol: 'IMOEX', name: 'Moscow Exchange Index', value: 3215.91, change: 1.39, trend: [3118, 3141, 3168, 3215.91] },
    { id: 'usdrub', symbol: 'USD/RUB', value: 83.0705, valueDigits: 4, change: -0.96, trend: [84.31, 83.97, 83.48, 83.0705] },
  ],
  [{ id: 'brent', symbol: 'BRENT', value: 74.18, change: 0.63, trend: [72.85, 73.26, 73.72, 74.18] }],
];

export function MarketsCard() {
  const [page, setPage] = useState(0);
  return (
    <MarketsWidget
      title="Markets"
      items={PAGES[page] ?? []}
      locale="en"
      pagination={{ pages: PAGES.length, current: page, onChange: setPage }}
      footerLink={{ label: 'View the market', href: '/docs/kits' }}
    />
  );
}

The host keeps the page index and passes the rows of that page. pages counts pages, current is a 0-based index, and the active dot never calls onChange.

Formatting and locales

Value priority is formattedValue, then formatValue, then value with valueDigits. Change priority is formattedChange, then formatChange, then change with a sign and a percent suffix.

  • NaN and Infinity render as -.
  • en groups thousands with a comma and separates decimals with a dot: 3,215.91.
  • ru groups thousands with a space and separates decimals with a comma: 3 215,91.
  • An exception in a host formatter does not escape: the built-in format takes over.

Note The locale prop defaults to ru. Pass en for an English card, as the live demo does.

Themes

The card paints only from the ChartTheme you pass: panel, grid, text, muted text, accent, up, down and radius. Missing tokens resolve one by one, so a partial theme stays renderable.

Without a theme, the card uses neutral CSS values: a transparent surface, the surrounding text color and the inherited font. Pass a palette object for a colored card.

import { LIGHT_THEME } from '@unifin/chart-core';
import { MarketsWidget, type MarketsWidgetItem } from '@unifin/chart-react/widgets';

const rows: readonly MarketsWidgetItem[] = [
  { id: 'rgbi', symbol: 'RGBI', name: 'Moscow Exchange Government Bond Index', value: 107.69, change: 0.14 },
];

<MarketsWidget title="Markets" items={rows} locale="en" theme={LIGHT_THEME} />;

No stylesheet is required. className adds outer layout only; colors and radius remain in the theme, so a white-label host repaints the card through its own palette.

Accessibility

  • The card is a section named by ariaLabel, or by title when the prop is absent.
  • Rows form a semantic list; every row carries an aria-label with the name, ticker, change and value.
  • The sparkline is aria-hidden: it repeats the numbers of its row.
  • Page dots are <button type="button"> with a 1-based label and aria-current="page" on the active dot.
  • The footer link is keyboard focusable; external http(s) links receive rel="noopener noreferrer".
  • asOf is exposed only as an aria-description, so the visual layout stays unchanged.

Server rendering

The component has no effects, no useId and no access to window, document or ResizeObserver. renderToString returns the same markup on the server and in a second render; React 18 and React 19 are supported.

Caution pagination.onChange and onMenu are callbacks. Pass them from a client component; a server component can render the card itself but cannot hand it functions.

Budget and stability

The @unifin/chart-react/widgets subpath is budgeted at 6 KB gzip and the built entry measures 5.30 KB gzip. A host that does not import the subpath pays nothing extra.

Every export of the subpath is in beta. New optional props are additive; a breaking prop change follows the major version.

See also

On this page