Skip to content

feat(mosaic): add the styled Chart with a categorical palette - #10960

Draft
austincalvelage wants to merge 54 commits into
austin/mosaic-bar-chartfrom
austin/mosaic-bar-chart-component
Draft

austincalvelage wants to merge 54 commits into
austin/mosaic-bar-chartfrom
austin/mosaic-bar-chart-component

Conversation

@austincalvelage

@austincalvelage austincalvelage commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Description

Stacked on #10953. Review that PR first; this diff contains only the styled layer.

Adds a styled Chart to Mosaic at @clerk/mosaic/components/chart. It has the same parts as the headless Chart primitive, with Mosaic's styles applied, plus a categorical color palette. Styled parts render sensible defaults when given no children, the way the styled Select popup renders its options.

import { Chart, type ChartSeries } from '@clerk/mosaic/components/chart';

const series: ChartSeries<Day>[] = [{ key: 'agents', label: 'Active agents', color: 1, value: day => day.agents }];

const chart = Chart.useBarChart({ data: days, index: day => day.date, series });

<Chart.Root chart={chart} aria-label='Active agents by day'>
  <Chart.Grid />
  <Chart.Bars />
  <Chart.YAxis />
  <Chart.XAxis ticks='calendar' />
  <Chart.Selection />
</Chart.Root>;

Several series stack, with negative values below the zero line. Add Chart.Legend once a chart has two series or a projection.

  • Parts. useBarChart, Root, Legend, Grid, YLine, YAxis, YTick, XAxis, XTick, Bars, Bar, ProjectionOutline, Selection, Cursor, Tooltip and TooltipContent.
    • Each part has a .cl-chart-<slot> theme slot and takes xstyle.
    • Leave a part out to hide it; there are no show* props.
  • Tooltip. Chart.Tooltip is the .cl-chart-tooltip surface on the primitive's single tooltip element. It fades in on first open, then slides between bars once the selection moves, while it carries data-moving. Under reduced motion it only fades. It hides while the selected bar is scrolled out of view, carrying data-anchor-hidden. It takes the primitive's side, sideOffset, collisionPadding, collisionBoundary and pinned, and returning null from its children hides it.
  • From feat(mosaic): slide the chart tooltip between bars #11006 (Alex). The slide, the off-screen hiding, and a selection update that skips re-rendering while the pointer stays on one bar. In Alex's Swingset measurement, React commits over three sweeps fell from 321 to 71.
  • Palette. Six new public tokens, --cl-color-chart-1 through --cl-color-chart-6, keep the original hue order: violet, sky, orange, cyan, yellow and slate.
    • Light and dark values are tuned separately so every color passes the dataviz contrast and color-vision checks against the surface. Yellow becomes a gold and slate a steel blue.
    • chart-palette.test.ts reruns those checks against the token values.
    • Pairs to keep apart in one stack: 2 with 4, 2 with 6, and 3 with 5.
    • These are the only new tokens. The grid, labels and tooltip read --cl-color-border, --cl-color-foreground-secondary and --cl-color-surface.
  • Series colors. color is required on every series, as a slot 1 to 6 or any CSS color, so filtering a series never recolors the others.
    • Series reach the Canvas through 8 static [data-series] rules, which caps a chart at 8 series.
  • Highlight. highlight dims the other bars with an opaque color-mix(in oklab, <series> 40%, var(--cl-color-surface)), so grid lines don't show through.
    • Plain hover and keyboard selection don't dim anything.
    • The hover band sits behind the bars, so bar colors stay exact.
  • States. Root sets data-state to ready, empty or error. It shows an empty state, and when Canvas fails it shows a negative Banner (role='alert') with a retry. Loading belongs to the owner, who renders a skeleton.
  • Focus ring. Chart.Selection rings the whole chart while it has keyboard focus. A keyboard selection shows the same band and tooltip as a hover.
  • Screen reader text. Each series' label reaches the primitive's announcement, and values use the tooltip's number format, so screen readers hear Nov 24, 2026, Active agents 53. The series bridge keys series by position for the Canvas, so it passes the label through.
  • Localization. Empty and error copy and the screen reader text, including the new projected message, come from the chart messages, passed to the primitive's messages option.
  • Swingset. The page leads with a single series: daily active agents, a few monthly bars, and a projection. The six-series growth chart is the Stacked example. Highlight pins on click, as Dashboard's overview chart does: clicking a section, or pressing Enter on it, keeps it at full strength until it is clicked again.

For review

  • Legend placement. Chart.Legend inside Root portals into a slot that Root renders above the plot, because the plot layers cover the whole measured box.
    • It is absent from the server render and appears on the first client render.
    • It is hidden in the error state.
    • Outside a Root, Chart.Legend items={…} renders in place.
  • Default date formatting. The default formatCategory formats UTC date keys (YYYY-MM-DD, or ISO ending in Z) as dates, for example "Jan 5, 2026" in tooltips and announcements, and "Jan 5" on ticks. Pass formatCategory for anything else, such as a month.
  • CSS budget. The styles.css bundlewatch budget rises from 18KB to 20KB.
    • main was already 52 B over the old limit under gzip -9.
    • This PR adds 954 B, going from 18,484 B to 19,438 B.
  • Bundle. The JS budgets do not change.

How to test

  • pnpm --filter @clerk/mosaic test and test:browser. The browser tests cover:
    • palette pixels
    • the opaque dim over a grid line
    • the band behind the bars
    • the tooltip and a custom tooltip render function
    • the announcement with each series label and value
    • color-scheme and series-color repaint
    • error and retry
    • empty states and the legend
  • pnpm --filter @clerk/mosaic test:visual runs the light and dark styled screenshots.
  • pnpm dev:swingset, then open /components/chart. Hover the Few bars example, then move above the short September bar: the tooltip closes. Tab into a chart: the ring sits on the selected bar's band as you use the arrow keys, and moves to the whole chart after Escape. Read the status region as you move.

Verification

On a20724fb4f:

  • lint, format:check, test (3,601 passed, 2 todo), test:browser (182) and build pass, including typecheck, the client-boundary check and the docs-export check.
  • Bundlewatch passes: styles.css is 18.95KB of the 20KB budget, the eager entry 26.88KB of 28KB and the total 307.95KB of 310KB.
  • The announcement test fails when the series bridge drops the label: it reads A, 0 10, 1 10, 2 10.
  • On the real Swingset page:
    • The styled tooltip is one .cl-chart-tooltip element that opens beside the bar on the side that fits, with position: fixed, z-index: 10 and pointer-events: none.
    • The slide matches feat(mosaic): slide the chart tooltip between bars #11006's original commit in an identical keyboard run: opacity, top, left at 0.1s, 0.25s and 0.25s on the enter curve, the same first position, and the same path between bars.
    • Hovering the empty top of the short September column opens its tooltip.
    • Highlight pins on click: clicking a section keeps it at full strength and dims the rest, the dimming stays after the pointer leaves, clicking it again clears it, and Enter pins the same way. Hovering alone dims nothing.
    • The few-bars labels sit centered under their bars, and the daily chart keeps its first and last dates at the plot edges.

On an earlier commit of this PR, and not rerun since:

  • Two mutations each failed exactly one test: a bar z-index of 0 failed the band test, and a dim mixed with transparent failed the opaque-dim test.
  • test:visual passed the 4 primitive screenshots and the 2 styled ones.

Not verified

  • The styled screenshots have not run since the slide and the focus ring. Docker was not available.
  • feat(mosaic): slide the chart tooltip between bars #11006's changeset stays separate from the chart's. The chart is unreleased, so it could fold into mosaic-chart-component.md.
  • The styled screenshots have not run on React 19.
  • The legend's first-render flash has not been measured in a real app.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

🤖 Generated with Claude Code

Add --cl-color-chart-1 to -6 to colorVars. Each light-dark() value is
tuned per mode so the palette passes the data-viz lightness, chroma,
adjacent CVD, normal-vision and 3:1 contrast checks on the surface, and
a unit test reruns those checks on the token text.
… frame

Chart.Legend and Chart.TooltipContent take plain data and read no
context, so they render beside any chart, a skeleton or a card header.
components/chart/internal holds the frame every styled chart type renders
through: the series bridge that keys series by position for the headless
hook, the static per-slot color rules, locale formatting, grid, axes,
selection layer and overlays. The chart internal lint fence now lets only
components/*-chart/ import it.
BarChart renders a stacked bar chart from data, an index and a series
list with required colors: the legend, dotted grid, bars, axes, hover
band and a default tooltip. highlight dims every other bar with an
opaque mix toward the surface, so grid lines never show through, and the
hover band sits behind the bars. The root reflects data-state ready,
empty or error, with a built-in empty state and a retry after a Canvas
failure. interactive={false} removes the selection props at the type
level.
Add the @clerk/mosaic/components/chart and
@clerk/mosaic/components/bar-chart exports, their tsdown entries and
agent docs, and a changeset. The chart CSS and palette tokens take
styles.css from 17.97KB to 18.9KB gzip, so its budget rises to 20KB.
The chart root now takes the full width of its container, so a chart in a
centered flex parent no longer shrinks to its labels. Without rows the
Y axis showed placeholder ticks from 0 to 1 behind the empty state; it is
now left out.
Add bar-chart.component.stories.tsx and .mdx under Components, with a
knob playground and examples for the palette, a dimmed highlight, a
projection, the empty and render error states, and dark mode.
The styled layer is now the headless Chart parts with Mosaic styles:
Chart.useBarChart tags the primitive chart with the series colors,
legend, formatter and tooltip rows, and each part renders a default
when it has no children. Chart.Root owns the series color variables,
data-state, the empty state and the Canvas error boundary. The
components/bar-chart entry and the BarChart component are removed.
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clerk-js-sandbox Ready Ready Preview Nov 26, 2026 12:55am UTC
mosaic-docs Ready Ready Preview Nov 26, 2026 12:55am UTC
swingset Ready Ready Preview Nov 26, 2026 12:55am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a20724f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/mosaic Minor
@clerk/mosaic-docs Patch
@clerk/swingset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

The chart's grid lines, tick labels and tooltip read --cl-color-chart-grid,
--cl-color-chart-label and --cl-color-chart-tooltip, which default to the
general tokens they used before. Dimmed bars keep --cl-chart-inactive-mix
(40%) of their color. A theme can now restyle these without selectors; the
Clerk theme in Swingset uses them and matches Dashboard's 50% dimming.
@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@10960

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@10960

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@10960

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@10960

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@10960

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@10960

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@10960

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@10960

@clerk/expo-biometrics

npm i https://pkg.pr.new/@clerk/expo-biometrics@10960

@clerk/expo-google-signin

npm i https://pkg.pr.new/@clerk/expo-google-signin@10960

@clerk/expo-native-components

npm i https://pkg.pr.new/@clerk/expo-native-components@10960

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@10960

@clerk/express

npm i https://pkg.pr.new/@clerk/express@10960

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@10960

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@10960

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@10960

@clerk/mosaic

npm i https://pkg.pr.new/@clerk/mosaic@10960

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@10960

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@10960

@clerk/react

npm i https://pkg.pr.new/@clerk/react@10960

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@10960

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@10960

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@10960

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@10960

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@10960

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@10960

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@10960

commit: 38c3ee2

… component

Chart.ProjectionOutline is now a hidden g whose stroke the Canvas reads, so the
styled part forwards a g ref and drops the SVG-only fill.
…sers

The example now stacks retained, reactivated and new users above zero and
their churn below, with the week in progress projected. Related series share
a hue, gains as tints of the first palette color and churn as steps of the
text colors. The Clerk theme sets Dashboard's exact purples and grays.
The styled `Chart.Tooltip` composes the primitive's portal, positioner and
popup: the popup keeps the `cl-chart-tooltip` surface and fade, and a new
`cl-chart-tooltip-positioner` holds the z-index on the fixed element. It
passes `side`, `sideOffset`, `collisionPadding`, `collisionBoundary` and
`pinned` through.

The primitive Swingset examples and docs return the tooltip parts from
`Chart.Tooltip`, since content returned on its own renders unpositioned.
The chart is one tab stop with arrow keys inside. While the keyboard has a
bar selected, the focus ring sits on its band, and the chart-wide ring shows
only while keyboard focus has no band, as after Escape. A mouse hover still
shows the band without a ring.
Follows the primitive back to a single tooltip element. The styled
`Chart.Tooltip` again takes the element's props and `ref`, styles it as
`.cl-chart-tooltip` with the z-index, and hides when its children return
null. The `.cl-chart-tooltip-positioner` class is gone, and the Swingset
examples and docs return content from `Chart.Tooltip` directly.
Hovering anywhere in a column selects it again, so the examples no longer
say that moving off the bars closes the tooltip.
The styled `Chart.FocusOutline` draws Mosaic's focus ring, in the ring color
and width, 2px clear of the selected section's bars, with corners concentric
with theirs. `Chart.Bars` renders it by default after the zero line. The
cursor no longer draws a ring and shows no band under the keyboard, so the
ring around the bars is the only focus mark.
Reverts 188db2b (the styled `Chart.FocusOutline`) and 38c3ee2 (the
ring on the keyboard-selected band). `Chart.Selection` rings the whole chart
while it has keyboard focus again, and the cursor shows the same band for
the keyboard as for a pointer.
The Highlight example dimmed on hover, so the highlight and the hover band
said the same thing and the dimming left with the pointer. It now follows
Dashboard's overview chart: `onActivate` pins the clicked section, or the one
Enter is pressed on, the dimming stays after the pointer leaves, and
clicking the same section again clears it.

This branch was successfully deployed

2 active deployments
Preview – swingset — a20724fb Deployed Nov 26, 2026 by vercel[bot]
Preview – clerk-js-sandbox — a20724fb Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants