@exodus/datapoints-react
v3.4.0
Published
Headless React components for provenance-backed datapoint reports: unstyled, data-attribute driven, built on the @exodus/datapoints contract
Maintainers
Keywords
Readme
@exodus/datapoints-react
Headless React components for provenance-backed datapoint reports. Renders the
@exodus/datapoints report payload — a title, prose with value pills and a verify list
with per-datapoint audit panels — with zero styles.
Every visual state is exposed as a data-* attribute, so any design system
styles it with plain CSS.
Install
npm install @exodus/datapoints-reactReact 19 is a peer dependency. @exodus/datapoints (the payload contract)
comes along as a regular dependency.
Rendering a report
import { DataReport } from '@exodus/datapoints-react';
function Report({ payload, sourceText }: { payload: unknown; sourceText?: string }) {
return (
<DataReport.Root payload={payload} text={sourceText}>
<DataReport.Title />
<DataReport.Summary />
<DataReport.Prose />
<DataReport.VerifySummary />
<DataReport.Table />
</DataReport.Root>
);
}payload is validated with the contract's reportPayloadSchema; an invalid
payload renders nothing and calls onInvalid. text is the placeholder
source ({{dp:id}} / {{lit:text}}) — when provided, DataReport.Prose
renders it with clickable value pills (onPillClick on the root receives the
datapoint id). When the prop is absent, the root falls back to the payload's
own optional text field, so a persisted payload that carries its source
renders prose and charts without the caller threading the text through.
DataReport.Title renders the payload's title as <h2 data-report-title> and
DataReport.Summary its summary as <p data-report-summary>. Both hold the
same placeholders as text, so they render value pills (and **bold** /
*italic*), and each renders nothing when its field is absent.
DataReport.VerifySummary renders <span data-verify-summary> with one
[data-verify-count] per count. human-reviewed ("3 human-reviewed") counts
curated datapoints and is always shown, even at zero. human-approved
("1 human-approved") counts custom datapoints approved in a report review,
ai-reviewed ("1 AI-reviewed") the rest of the custom ones, and stale
("1 stale") the expired ones; these three show only when non-zero. The counts
cover every datapoint in the payload, inputs included, using each datapoint's
own tier, and the stale count follows the clock.
DataReport.Prose renders a markdown subset so a report can be structured:
paragraphs (blank-line separated, soft breaks kept), bullet lists (- / * ),
GFM tables (header, |---| separator, rows), **bold** and *italic*. A value pill works
anywhere text does, including inside a table cell. Out of scope on purpose:
column alignment colons are accepted but not carried through, pipes cannot be
escaped, and anything else renders as plain text. The root is a
<div data-report-prose> (previously a <p>; a breaking change for consumers selecting on the tag); paragraphs are
<p data-prose-paragraph>, lists <ul data-prose-list>, tables
<table data-prose-table>.
Refresh now and freshness
DataReport.Source takes an optional automation slug. With it, DataReport.RefreshButton
renders a <button data-report-refresh> (aria-busy and disabled while running) that posts to
../bridge/api/automations/<slug>/run, waits for the run, then re-fetches src. A failure renders
<span data-report-refresh-error role="alert"> and keeps the current report. Without the slug the
button renders nothing. With the slug, a src that returns 404 (no run has written it yet)
starts the automation once on load. onRefreshError receives a failed run, including that first
one, since nothing renders until a report exists. The route is Bridge's, reached through the workspace's shared URL, so it
only works for the workspace owner. DataReport.Freshness renders
<p data-report-freshness> ("As of Nov 18, 2026 · fetched Nov 19, 9:05 AM") from the payload.
useDataReportSource also returns refetch(), a ResultAsync that re-fetches on demand.
Charts
A report puts series datapoints (value is an ordered list of { label, value }
points) on a chart with a fenced block the gateway has already validated:
```chart
kind: line
title: Monthly MTU
series:
- {{dp:custom_mtu_monthly_1a2b3c4d}}
```DataReport.Prose lifts the block out of the prose and renders it with Chart
(or StatTiles for kind: stat), looking each id up in the payload. Points
align by index and the first series supplies the category labels. A block that
fails to parse renders as plain prose rather than disappearing. A series id the
payload lacks, or that resolves to a scalar datapoint, is not drawn: the
<figure> carries data-missing with the space-separated ids and the legend
keeps an entry per missing id marked data-missing (no swatch, no
data-series-index), the same hook [data-value-pill][data-missing] offers.
Outside a chart, a series placeholder renders its formatted summary as an
ordinary pill; the audit panel for a series row draws its points in the Points
tab.
Kinds and options
| Block | Rendering |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| kind: line | one [data-series-line] path and [data-point] markers per series, overlaid |
| kind: bar | one rect[data-point] per point per series, grouped per category from a zero baseline, with text[data-bar-value] labels (see below) |
| kind: area | line plus a path[data-area] polygon closed along the baseline |
| kind: stat | StatTiles: a [data-stat-grid] of [data-stat-tile] KPI tiles instead of an svg |
| stacked: true | bars share one slot and areas nest; each series is offset by the cumulative total of the series listed before it, and the domain covers the stacked totals |
| orientation: horizontal | bars grow rightward from the zero baseline, categories run down the y axis, value ticks along the x axis |
| layout: multiples | one [data-chart-panel] per series in a [data-chart-panels] wrapper, each with its own svg, domain and unit; a [data-panel-title] replaces the legend |
| target: {{dp:id}} | a [data-target] reference line at the scalar value (it extends the domain), with the formatted value as an end label and a [data-legend-target] entry |
Bar charts label their values with <text data-bar-value> (the value
formatted with the series unit) when they draw 12 or fewer visible bars
(categories × side-by-side series; a stack counts as one); above that no label
renders and hover shows the values. A vertical bar's label sits above it (below
for negatives), a horizontal bar's past its end. A stacked segment's label sits
inside the segment and is dropped when the segment is too small for it, and each
stack gets its net total past its end as <g data-bar-totals> >
<text data-bar-value data-bar-total data-label>. Labeled charts pad the value
domain so labels stay inside the plot; the axis ticks keep the unpadded domain.
Figure attributes mirror the spec: data-chart-kind, data-chart-layout,
data-chart-stacked and data-chart-orientation are present when set.
Chart and StatTiles are also exported on their own:
import { Chart, StatTiles } from '@exodus/datapoints-react';
<Chart
spec={{ kind: 'bar', title: 'Revenue', stacked: true, series: [revenue.id, cost.id] }}
series={[
{ id: revenue.id, unit: revenue.unit, points: revenue.value },
{ id: cost.id, unit: cost.unit, points: cost.value },
]}
target={{ id: goal.id, value: goal.value, formatted: goal.formatted }}
onLegendClick={(id) => openAudit(id)}
/>;
<StatTiles
title="Headline"
entries={[{ id: mtu.id, datapoint: mtu }]}
onTileClick={(id) => openAudit(id)}
/>;The SVG is hand-drawn with no dependencies and no colors or sizes of its own:
it carries a viewBox (640×240) and scales to whatever width the consumer
gives it. Inside a [data-chart-fit] ancestor whose size the consumer sets,
the plot widens its viewBox to the container's aspect (never below 640) so
it fills both dimensions without stretching. The [data-chart-fit] opt-in is
resolved when the plot mounts; adding or removing the attribute later has no
effect until the chart remounts. Each series' stroke/fill is
var(--chart-series-N, currentColor) (N from 1), so a consumer sets up to
eight series colors once:
[data-chart] {
--chart-series-1: var(--accent);
--chart-series-2: teal;
}
[data-chart] svg {
width: 100%;
height: auto;
}
[data-chart-kind='line'] [data-series-line],
[data-chart-kind='area'] [data-series-line] {
stroke-width: 2;
}
[data-chart-kind='area'] [data-area] {
fill-opacity: 0.18;
}
[data-target] line {
stroke: gray;
stroke-dasharray: 4 3;
}
[data-chart-panels] {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
[data-stat-grid] {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
}
[data-sparkline] {
width: 6rem;
height: 2rem;
color: var(--chart-series-1);
}
[data-axis] text {
font-size: 10px;
fill: gray;
}Vocabulary: <figure data-chart data-chart-kind> wraps <figcaption data-chart-title>,
a <div data-plot> holding the <svg role="img"> (labelled by the title or the
series ids) and, while a point is hovered, the tooltip, and <ul data-chart-legend>. Inside the svg: <g data-axis="y"> and <g data-axis="x">
hold [data-tick] entries; value ticks carry data-value, a [data-gridline] and
the value formatted with the series unit, category labels carry data-label and
are thinned to at most twelve on the x axis. Which axis carries values follows
the orientation. Each series is <g data-series data-series-index data-datapoint-id>
with a [data-series-line] path on line and area charts, a [data-area] polygon on
area charts, and one [data-point data-label data-value] marker or bar per point,
each with a <title> ("label · formatted value"; a stacked shape reports its own
value, not the running total). <g data-target data-value data-datapoint-id> holds
the reference line and its <text> label. Legend entries are
<button data-legend-item data-datapoint-id data-series-index> with a
[data-legend-swatch] and the datapoint id without its hash (data-missing in
place of the index and swatch, or data-legend-target for the target); clicking
one calls the root's onPillClick, so the same audit flow opens for a chart as
for a pill.
Interaction
Charts answer the cursor and the keyboard without a dependency, and expose every state as data attributes so the consumer decides what it looks like:
- A transparent
<rect data-hover-overlay>covers the plot. Moving or pressing a pointer over it snaps to the nearest point (line and area by point spacing, bars by slot; horizontal bars read the row from y). The<svg>and, for a single plot, the figure carrydata-hover-index; each[data-chart-panel]of a multiples chart hovers on its own. - While hovered the svg draws
<line data-crosshair>through the point (vertical, or horizontal for horizontal bars) and every marker or bar at that index getsdata-hovered. - A
<div data-tooltip role="status" aria-live="polite">follows the svg inside[data-plot], referenced by the svg'saria-describedby. It holds[data-tooltip-label](the point label) and one<div data-tooltip-row data-series-index data-datapoint-id>per series with a[data-legend-swatch],[data-tooltip-name](the id without its hash) and[data-tooltip-value](the point formatted with the series unit); a target adds a row withdata-tooltip-target. The tooltip's only inline style is two custom properties,--tooltip-xand--tooltip-y, the anchor as fractions of the svg box (the point x and the plot top; the plot middle and the row y for horizontal bars), so CSS positions it relative to[data-plot]. - The svg is focusable (
tabindex="0"): ArrowLeft/ArrowRight step the index, Home/End jump, Escape clears, and losing focus clears. Pointer leave clears. - Hovering or focusing a legend entry sets
data-highlight-serieson the figure anddata-dimmedon every other[data-series]; leaving or blurring clears it. Clicking still callsonPillClick.
Stat tiles have no hover state; the sparkline is decoration for the value.
[data-plot] {
position: relative;
}
[data-hover-overlay] {
cursor: crosshair;
}
[data-crosshair] {
stroke: gray;
stroke-dasharray: 2 2;
}
circle[data-point][data-hovered] {
r: 5;
}
[data-series][data-dimmed] {
opacity: 0.3;
transition: opacity 150ms;
}
[data-tooltip] {
position: absolute;
top: calc(var(--tooltip-y) * 100%);
left: clamp(6rem, var(--tooltip-x) * 100%, calc(100% - 6rem));
transform: translateX(-50%);
pointer-events: none;
}Stat tiles: <div data-chart data-chart-kind="stat" data-stat-grid> holds an
optional [data-chart-title] and one <article data-stat-tile data-datapoint-id>
per entry wrapping a <button data-stat-open> with [data-stat-label] (the
datapoint description, else its id without the hash) and [data-stat-value]
(a scalar's formatted, or a series' last value formatted with its unit). A
series tile adds <svg data-sparkline> (a [data-series-line] path and a
[data-sparkline-last] marker, no axes) and [data-stat-span] with the first
and last labels. A missing id renders the tile with data-missing and no value.
Tiles never derive numbers the payload does not carry.
Verify list
DataReport.Table renders <ul data-report-list>. Datapoints referenced by a
placeholder in the title, summary or text come first, in order of first
reference; the rest are formula inputs, in payload order, each marked
data-role="input". A report with no source text at all keeps payload order and
marks nothing as an input.
Before the first input sits one <li data-inputs-heading> holding the label
"Formula inputs" and a button[data-help] whose accessible name and data-tip
carry INPUTS_HELP, a short explanation of why those rows appear. It is absent
when every row is referenced. Select rows with li[data-datapoint-id] to skip it.
Each datapoint is an <li data-datapoint-id data-tier data-kind> (plus
data-custom, data-stale, data-expanded and data-role when they apply)
holding a <button aria-expanded aria-controls> toggle and, after it, the
detail region. The toggle starts with a [data-row-caret] glyph (›
collapsed, ⌄ expanded), then one <span data-column> per column. The
datapoint cell has a ReviewMark (an inline SVG, shield for human-reviewed,
warning triangle for ai-reviewed, with the explanation in its title, styled
through [data-review-mark][data-tier]) followed by
<span data-datapoint-name>. The value cell shows formatted, or a sparkline
and the latest value for a series. The source cell is
<span data-datapoint-source data-source-kind>: query with the source id,
formula with Formula, or constant with Constant. The retrieved cell is
<span data-retrieved> with the relative time, Stale · <relative> once the
freshness window has passed, or Never expires for constants; its title
holds the absolute time.
The detail region is a <div data-audit-row data-datapoint-id> whose id is
unique per rendered row and matches the toggle's aria-controls. It holds
DataReport.AuditPanel, a <div data-audit-content> with these parts in order:
<p data-about>: the custom question, else the description.<div data-chips>: a[data-chip="freshness"]withdata-statefresh("Fresh · 4:02 PM, valid 5m" plus a<span data-meter>whose--usedcustom property is the used share of the window, 0–1),expired("Expired 1 minute ago · 4:02 PM, valid 5m"),constant("Constant value, never expires") orunbounded("Retrieved 4:02 PM"); a[data-chip="period"]for a custom period; and one[data-chip="as-of"][data-query-id]per dated provenance entry ("Data as of Sep 1, 2026").<div data-ai-notice role="note">forai-revieweddatapoints.<code data-formula>for derived values: each input is a<button data-formula-input data-datapoint-id>that calls the root'sonPillClick, and every operator, parenthesis or number is a[data-formula-op].<div data-audit-tabs>when there is a query or a series value: arole="tablist"ofbutton[role="tab"][data-tab](Querywith the source id andPointswith the point count, each in a[data-tab-count]), a<button data-copy>and arole="tabpanel"[data-tab-panel]. Copy writes the query text, orlabel,valueCSV on Points (labels starting with=,+,-,@or a tab get a leading'), to the clipboard and then setsdata-copiedfor 1.6 seconds, so a CSS animation on[data-copy][data-copied]shows the flash.- The Query pane is
<pre data-query data-language>with one[data-line="<n>"]per line and one[data-token="<prism types>"]per token (tokenized byprism-react-renderer, no theme). Before highlighting, a per-language formatter lays the query out for reading (SQL viasql-formatter, with the Spark dialect fordatabricksand ClickHouse forclickhouse; word case is never changed). Text the formatter cannot parse, and languages with no formatter, render as stored. Copy always copies the stored text. Queries over 7 lines are clamped (data-clamped) behind a<button data-clamp-toggle aria-expanded>("Show all N lines" / "Show less"). - The Points pane is
<div data-points>with a[data-zero-line](--y), a<div role="group" aria-label="Series points" data-point-bars>holding one<button data-point data-label data-value>bar per point (--x,--width,--top,--height, all 0–1 fractions of the pane, anddata-markwithhigh,lowandlast), at most six[data-point-labels] [data-point-label](--x;YYYY-MMlabels as short month names) and a[data-readout]with[data-readout-label],[data-readout-value],[data-readout-change]("▲ 5.0%") and the[data-readout-high]/[data-readout-low]points. Hovering or focusing a bar shows it in the readout and marks itdata-active; otherwise the last point is shown.
- The Query pane is
Collapsed regions stay mounted so they can animate. That means the audit
content (query, formula) is always present in the rendered HTML; hidden
and inert are presentation, not access control, so do not rely on the collapsed
state to keep audit detail out of the DOM. Detail regions carry
[data-collapsible], get hidden + inert while collapsed and
data-expanded while open, and aria-controls always resolves.
The collapsible's only child is an unstyled <div> wrapping the audit content,
so a consumer can clip it without fighting the content's padding or border.
Unstyled, hidden keeps them out of the way; to animate, override [hidden]
and transition the wrapper:
[data-audit-row][hidden] {
display: block;
}
[data-collapsible] {
display: grid;
grid-template-rows: 0fr;
transition: grid-template-rows 200ms;
}
[data-collapsible] > * {
overflow: hidden;
min-height: 0;
}
[data-collapsible][data-expanded] {
grid-template-rows: 1fr;
}onExpandedChange(expandedIds, changed) receives { datapointId, expanded }
for the row that toggled, so a consumer can scroll the right region into view.
Styling
Everything is addressable through data attributes:
[data-report-list] li[data-tier='ai-reviewed'] {
/* caution tint */
}
[data-report-list] li[data-stale] [data-retrieved] {
color: orange;
}
[data-value-pill] {
font-variant-numeric: tabular-nums;
}
li[data-expanded] {
background: color-mix(in srgb, currentColor 6%, transparent);
}These attributes are the stable styling surface, so consumers such as
@ai/ui's chat.css can lay out a report without reaching into its markup:
| Attribute | Element |
| ---------------------- | ------------------------------ |
| data-report-prose | the prose container |
| data-prose-paragraph | each prose paragraph |
| data-chart | each chart figure |
| data-chart-title | the chart caption, when titled |
| data-plot | the box around a chart's SVG |
Staleness is computed client-side on a live interval from each datapoint's
retrievedAt and freshness; a value past its freshness window gets
data-stale.
Columns
<DataReport.Table
columns={[
{ key: 'datapoint' },
{ key: 'value', render: (datapoint) => <strong>{datapoint.formatted}</strong> },
{ key: 'custom', id: 'unit', render: (datapoint) => datapoint.unit },
]}
/>Built-in columns: datapoint, value, source, retrieved (that order is
the default). A built-in column's render overrides its default cell; custom
columns add new ones. The list has no header row, so columns carry no header.
Cells render inside the row's toggle <button>, so a renderer must return
non-interactive phrasing content (no links, buttons or inputs); the button's
accessible name is its cells' text.
Reference
| Export | Purpose |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| DataReport.Root | Validation, context, expansion state (expandedIds/onExpandedChange for controlled mode) |
| DataReport.Title / .Summary | The payload's title and summary with value pills |
| DataReport.Prose | Placeholder text with value pills |
| DataReport.VerifySummary | Human-reviewed, AI-reviewed and stale counts |
| DataReport.Table / .Row / .AuditPanel | The verify list and its audit detail |
| Chart | Headless SVG line/bar/area chart over series datapoints (ChartProps, ChartSeries, ChartTarget) |
| StatTiles | Headless KPI tiles for scalar and series datapoints (StatTilesProps, StatEntry) |
| ReviewMark, REVIEW_MARK_TITLES | Tier icon with tooltip text, for custom cells |
| QueryPane | Highlighted, numbered, clamped query; isVerbatim skips formatting |
| useRelativeTime | Live relative/absolute time + staleness for custom cells |
| DEFAULT_COLUMNS, ColumnConfig | Column configuration |
