Repository navigation
feat(mosaic): add the styled BarChart with a categorical palette - #10960
Draft
austincalvelage wants to merge 46 commits into
Draft
austincalvelage wants to merge 46 commits into
austincalvelage wants to merge 46 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
🦋 Changeset detectedLatest commit: 2a390ed The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
3 of 9 tasks
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-biometrics
@clerk/expo-google-signin
@clerk/expo-native-components
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/mosaic
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
1 of 9 tasks
Pass the keyboard instructions and announcements to the primitive's new `messages` option from the `chart` messages, so a localization override reaches them. The styled hook takes no `messages` of its own: the localization is their one owner. Find the interaction surface in tests by its role now that the primitive drops `data-chart-interaction`.
…examples with one series The styled chart keys series by position for the Canvas, so it now passes each series' label and the full value format to the primitive, and screen readers hear `Nov 24, 2026, Active agents 53` rather than position keys. A new `projected` chart message names an unlabelled projection. The examples now start from a single series, the common case: daily active agents, a few monthly bars, and a projection. The six-series growth chart moves to Stacked. Highlight sets a fixed highlight instead of a selection that ignored clears, which left its tooltip open after the pointer left. The primitive page gets the same single-series Default.
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.
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.
The styled bar chart listed its legend in stack order, bottom first, while
its tooltip listed a period's rows from the top. A chart with churn below
zero had to pass its own legend items to read in drawing order.
A series now takes `negative: true` when it is drawn below zero. The legend
lists the stack above zero from its top, then the negative series from the
zero line down, then a labelled projection, matching the tooltip.
`Chart.useBarChart` returns these entries as `chart.legend`, so a legend
placed outside `Chart.Root`, such as beside an Export button, reads
`<Chart.Legend items={chart.legend} />` instead of repeating the order.
The default bar tooltip dropped a series whose value was zero, so a period where nothing churned or nobody returned showed fewer rows than the chart tracks, and Dashboard rebuilt the rows to keep them. A zero now lists with the section its series is drawn in: above zero by default, below zero for a `negative` series. A missing or non-finite value still lists nothing, and a period with nothing to show still hides the tooltip.
A tooltip sizes to its content, so a `Banner` in `Chart.TooltipContent`'s footer stretched the tooltip to the length of its sentence. The footer now sits in a `cl-chart-tooltip-footer` box that takes the width the heading and rows set, so its text wraps there instead.
The six `--cl-color-chart-*` tokens move from `tokens.stylex.ts` to `components/chart/chart.vars.stylex.ts`, so a separate chart stylesheet can carry them. Only the chart reads them. `resolveChartColor` now reads a slot from `chartColorVars` instead of building the `var()` string. The output is the same string, and the runtime import keeps the palette in the module graph, so a StyleX build that follows imports, such as the Vitest browser project, still emits it.
Clerk's components do not render a chart, so `styles.css` should not carry its rules or palette. The CSS build now has two entries: `styles/index.ts` for `styles.css` and `styles/chart.ts` for `chart.css`. A sheet holds the StyleX rules its entry reaches that an earlier sheet does not, so the atoms the chart shares with Tooltip or Button stay in `styles.css`. StyleX names a layer `priorityN` by its position among the levels a sheet contains, so two sheets built apart would give one name two priorities. The build gives each sheet every level: both files name all ten layers in order, and the sublayer order holds whichever sheet loads first. Every declaration of the old `styles.css` is in exactly one of the two sheets, in the same layer and selector. `styles.css` drops to 19.69KB gzip, so its budget returns to 20KB; `chart.css` is 1.3KB under a 2KB budget. Apps that render the chart import both sheets into the same layer: @import '@clerk/mosaic/styles.css' layer(components); @import '@clerk/mosaic/chart.css' layer(components);
`<BarChart.Root aria-label data index series />` now draws the whole chart. Children replace the layout: `BarChart.Legend` renders in place, anywhere in the column, and `BarChart.Plot` holds the drawn layers. Each chart type gets its own namespace and root, and shares the legend, grid, axes and tooltip parts. - Each axis reserves its gutter while mounted; `margin` only overrides. - The `tooltip` prop is typed from `data`, so no type argument is needed. - `BarChart.Tooltip` mounts the selection surface and the hover band. Leaving it out gives a chart that takes no focus. - A projection names its row by category key, and the legend lists it only when it draws. - The default layout shows the legend from two entries. The styled `Chart` namespace, with `Chart.useBarChart`, `Chart.Root`, `Chart.Selection` and `Chart.Cursor`, is gone. The headless primitive is unchanged.
austincalvelage
force-pushed
the
austin/mosaic-bar-chart-component
branch
from
December 3, 2026 21:01
3116cbc to
e5977cc
Compare
ChartFrame takes the computed chart style as `chartStyle`, since a `style` prop reads as an inline style to the xstyle rule. The custom tooltip test renders through a module-level function.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Stacked on #10953. Review that PR first; this diff contains only the styled layer.
Adds a styled bar chart to Mosaic at
@clerk/mosaic/components/chart, built on the headlessChartprimitive, with a categorical color palette.BarChart.Roottakes the data and, with no children, draws the whole chart: the legend, a grid, the bars, both axes and a tooltip.Children replace the layout.
BarChart.Legendrenders wherever it is placed, andBarChart.Plotholds the layers drawn on the plot, in paint order:The chart's styles and palette ship in their own sheet, since Clerk's components do not render a chart. Import it after
styles.css, into the same layer:Root,Plot,Legend,Grid,YLine,YAxis,YTick,XAxis,XTick,Bars,Bar,ProjectionOutline,TooltipandTooltipContent..cl-chart-<slot>theme slot and takesxstyle.show*props.Rootrenders the legend from two entries, thenPlot.Plotrenders the grid, bars, both axes and the tooltip.BarChart.Roottakesdata,index,series,highlight,projection,tooltip,formatValue,formatCategory,categoryGap,margin,selection,onSelectionChange,onActivate,height,renderEmptyStateandonRenderError. It is generic over the row type, sotooltipandonActivatereceive a typedActiveBar<Row>with no type argument.BarChart.YAxisfrees its gutter without amargin.marginremains as an override.BarChart.Tooltipmounts the pointer and keyboard selection surface, the hover band (cursor={false}drops it) and the.cl-chart-tooltipsurface, which shows what the root'stooltipprop renders. Leaving it out gives a chart that takes no focus, such as a preview. The surface fades in on first open, then slides between bars once the selection moves, while it carriesdata-moving. Under reduced motion it only fades. It hides while the selected bar is scrolled out of view, carryingdata-anchor-hidden. It takes the primitive'sside,sideOffset,collisionPadding,collisionBoundaryandpinned.projectionis{ category, value, label?, description? }, naming its row by category key, ashighlightdoes. Alabeladds it to the legend, the tooltip and the announcement. A category that is not in the data draws nothing and leaves the legend alone.--cl-color-chart-1through--cl-color-chart-6, keep the original hue order: violet, sky, orange, cyan, yellow and slate.chart-palette.test.tsreruns those checks against the token values.chart.vars.stylex.tsand ships inchart.css. The grid, labels and tooltip read--cl-color-border,--cl-color-foreground-secondaryand--cl-color-surface.coloris required on every series, as a slot1to6or any CSS color, so filtering a series never recolors the others.[data-series]rules, which caps a chart at 8 series.highlightdims the other bars with an opaquecolor-mix(in oklab, <series> 40%, var(--cl-color-surface)), so grid lines don't show through.Rootsetsdata-statetoready,emptyorerror.Plotshows an empty state, and when Canvas fails it shows a negativeBanner(role='alert') with a retry. Loading belongs to the owner, who renders a skeleton.labelreaches the primitive's announcement, and values use the tooltip's number format, so screen readers hearNov 24, 2026, Active agents 53. The series bridge keys series by position for the Canvas, so it passes the label through.projectedmessage, come from thechartmessages, passed to the primitive'smessagesoption.<BarChart.Root />. The six-series growth chart is the Stacked example. Highlight pins on click, as Dashboard's overview chart does. Custom layout puts the legend beside an Export button, leaves out the Y axis and adds a total to the tooltip.For review
BarChart.Root, notChart.Rootwith a chart type. A laterLineChart.RootorDonutChart.Roottakes its own options and infers its own tooltip type, and its namespace carries only the parts that apply, so a donut has noXAxisto misuse. The legend, grid, axes and tooltip are shared components re-exported onto each namespace. This shape assumes no combined charts (bars and a line on one plot); those would want a mark-based root.useBarChart. Placing the legend elsewhere is a child ofRoot, reading the hover from outside isselectionandonSelectionChange, and drawing a custom chart is the headlessChart.useBarChartin@clerk/mosaic/primitives/chart. A styled hook can be added later without a breaking change.Barsrenders the bars, the projection outline and the zero line), and it keeps the common case to one line.chart.cssholds the rules the chart reaches thatstyles.cssdoes not already hold, so the atoms the chart shares withTooltipandButtonstay instyles.css. The build emits an empty rule at every StyleX priority level in both sheets, sopriorityNnames the same priority in each file and the sublayer order holds whichever sheet loads first. Within a layer, chart rules now follow core rules. That only matters for two atoms on one chart part that set the same property at equal specificity, which none do today.docs/theming.mddocuments the rule.BarChart.Legendrenders in place, so it is in the server render and stays visible in the error state. Outside a chart,items={…}renders a legend beside a skeleton.negativeseries from the zero line down, then a labelled projection. The tooltip already listed a period's rows this way. A stack with nothing below zero lists top first, so the palette story reads Slot 6 to Slot 1.test:visual:updatealso rewrote the switcher, organization switcher, user profile and headless chart baselines, which this change does not touch. I left those out, so they may still differ in the advisory visual job.negativeseries. A missing value still lists nothing, and a period with nothing to show still hides the tooltip.cl-chart-tooltip-footerbox that takes the width the heading and rows set, so aBannerthere wraps instead of widening the tooltip.formatCategoryformats UTC date keys (YYYY-MM-DD, or ISO ending inZ) as dates, for example "Jan 5, 2026" in tooltips and announcements, and "Jan 5" on ticks. PassformatCategoryfor anything else, such as a month.styles.csskeepsmain's 20KB budget, since the chart's rules moved tochart.css, which gets its own 2KB budget.components/chartis a separate entry, not imported byindex.How to test
pnpm --filter @clerk/mosaic testandtest:browser. The styled browser tests cover:tooltippropBarChart.Tooltiptaking no focuschart.test-d.tsxchecks thattooltipandonActivateinfer the row type and that series must read the chart's rows.pnpm --filter @clerk/mosaic test:visualruns 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 thestatusregion as you move. Custom layout shows the legend beside the button and no Y axis gutter.Verification
On
259f06982a, rebased onmainat49334306d2:test(4,213 passed, 24 skipped, 2 todo) andbuildpass, includingtypecheck, the client-boundary check and the docs-export check. Mosaic'slint(oxlint -c oxlint.config.mjs) andpnpm dedupe --checkpass. The styled chart's 25 browser tests pass on this commit.test:browserrun onb5a1463e08) and passed 3 of 3 runs on its own. It also failed once in this PR's CI one5977cc944, so it is intermittent in CI too and belongs to feat(mosaic): add the headless Chart primitive with stacked bars #10953.uientry is 50.94KB of 54KB, the total 342.45KB of 347KB,styles.css19.69KB of 20KB andchart.css1.3KB of 2KB.b5a1463e08'sChart.Rootcomposition match theBarChart.Rootcomposition on macOS.Before the rebase, on the commit that split out
chart.css:styles.csstochart.css.chart-series.tsreads the slot fromchartColorVars, which keeps the palette in the extracted sheet.On
a20724fb4f, and not rerun since:A, 0 10, 1 10, 2 10..cl-chart-tooltipelement that opens beside the bar on the side that fits, withposition: fixed,z-index: 10andpointer-events: none.opacity, top, leftat 0.1s, 0.25s and 0.25s on the enter curve, the same first position, and the same path between bars.transparentfailed the opaque-dim test.Not verified
BarChart.Root.BarChart.Rooton the snapshot@clerk/mosaic@0.15.0-snapshot.v20261203204906, built before the rebase with the same chart API.selection(selection,onSelectionChange), as in the primitive. Renaming itactive, soselectioncan mean a committed choice, is a separate change.mosaic-chart-component.md.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
🤖 Generated with Claude Code