Repository navigation
feat(mosaic): add the styled Chart with a categorical palette - #10960
Draft
austincalvelage wants to merge 54 commits into
Draft
austincalvelage wants to merge 54 commits into
austincalvelage wants to merge 54 commits into
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: a20724f The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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
|
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.
@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: |
… 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.
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
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
Chartto Mosaic at@clerk/mosaic/components/chart. It has the same parts as the headlessChartprimitive, with Mosaic's styles applied, plus a categorical color palette. Styled parts render sensible defaults when given no children, the way the styledSelectpopup renders its options.Several series stack, with negative values below the zero line. Add
Chart.Legendonce a chart has two series or a projection.useBarChart,Root,Legend,Grid,YLine,YAxis,YTick,XAxis,XTick,Bars,Bar,ProjectionOutline,Selection,Cursor,TooltipandTooltipContent..cl-chart-<slot>theme slot and takesxstyle.show*props.Chart.Tooltipis the.cl-chart-tooltipsurface on the primitive's single tooltip element. It 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, and returning null from its children hides it.--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.--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. It shows 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.Chart.Selectionrings the whole chart while it has keyboard focus. A keyboard selection shows the same band and tooltip as a hover.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.For review
Chart.LegendinsideRootportals into a slot thatRootrenders above the plot, because the plot layers cover the whole measured box.Root,Chart.Legend items={…}renders in place.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.cssbundlewatch budget rises from 18KB to 20KB.mainwas already 52 B over the old limit undergzip -9.components/chartis a separate entry, not imported byindex.How to test
pnpm --filter @clerk/mosaic testandtest:browser. The browser tests cover: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.Verification
On
a20724fb4f:lint,format:check,test(3,601 passed, 2 todo),test:browser(182) andbuildpass, includingtypecheck, the client-boundary check and the docs-export check.styles.cssis 18.95KB of the 20KB budget, the eager entry 26.88KB of 28KB and the total 307.95KB of 310KB.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.On an earlier commit of this PR, and not rerun since:
transparentfailed the opaque-dim test.test:visualpassed the 4 primitive screenshots and the 2 styled ones.Not verified
mosaic-chart-component.md.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
🤖 Generated with Claude Code