Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
435adee
feat(mosaic): add the categorical chart palette tokens
austincalvelage Nov 23, 2026
00f62c0
feat(mosaic): add the shared styled Chart legend, tooltip content and…
austincalvelage Nov 23, 2026
bdb9a6d
feat(mosaic): add the styled BarChart component
austincalvelage Nov 23, 2026
5b2d1aa
feat(mosaic): publish the styled Chart and BarChart components
austincalvelage Nov 23, 2026
995d22f
fix(mosaic): fill the container and hide empty value labels in BarChart
austincalvelage Nov 23, 2026
3207bf8
docs(swingset): add the styled BarChart page
austincalvelage Nov 23, 2026
a40be31
test(mosaic): add light and dark screenshots of the styled BarChart
austincalvelage Nov 23, 2026
b30bb02
refactor(mosaic): replace the styled BarChart with styled Chart parts
austincalvelage Nov 23, 2026
cfb67e9
docs(changeset): describe the styled Chart parts
austincalvelage Nov 23, 2026
98a790e
test(mosaic): move the styled chart screenshots to the parts API
austincalvelage Nov 23, 2026
c9a228e
docs(swingset): style the chart for the clerk theme
austincalvelage Nov 23, 2026
af88950
feat(mosaic): add chart grid, label, tooltip and inactive-mix tokens
austincalvelage Nov 23, 2026
a95a949
fix(mosaic): style the Canvas-painted projection outline in the chart…
austincalvelage Nov 23, 2026
da409f4
docs(swingset): base the chart example on Dashboard's weekly active u…
austincalvelage Nov 23, 2026
885234c
docs(swingset): leave churn out of the week in progress, as Dashboard…
austincalvelage Nov 23, 2026
ab2f373
refactor(mosaic): rename the styled Chart.StackedBars to Chart.Bars
austincalvelage Nov 24, 2026
c54fe10
test(mosaic): update the styled chart screenshots for the Canvas proj…
austincalvelage Nov 24, 2026
7247d4a
fix(mosaic): show the chart render error in a negative Banner
austincalvelage Nov 24, 2026
ea6d4b1
fix(mosaic): fade the chart tooltip in and out on the enter and exit …
austincalvelage Nov 24, 2026
8bd5377
fix(mosaic): take the chart bar gap, width and top radius from tokens
austincalvelage Nov 24, 2026
a46582d
fix(mosaic): declare the chart messages as const
austincalvelage Nov 24, 2026
50071cf
fix(mosaic): floor the chart legend tooltip trigger at the coarse-poi…
austincalvelage Nov 24, 2026
ef696b8
refactor(mosaic): drop the chart role tokens and inactive mix for the…
austincalvelage Nov 24, 2026
9c5bf93
docs(swingset): style the chart from the general tokens and part classes
austincalvelage Nov 24, 2026
a822ea7
docs(swingset): fold the chart examples into Usage and shorten the intro
austincalvelage Nov 24, 2026
2e0fbe0
docs(mosaic): drop the placeholder-chart use from the chart doc
austincalvelage Nov 24, 2026
fa71eeb
test(mosaic): assert chart series positions through painted bars, not…
austincalvelage Nov 24, 2026
0d28d02
fix(mosaic): localize the styled chart's screen reader text
austincalvelage Nov 24, 2026
0e7b5f8
fix(mosaic): announce series labels in the styled chart and lead the …
austincalvelage Nov 25, 2026
3882835
feat(mosaic): render the styled chart tooltip through the Tooltip parts
austincalvelage Nov 25, 2026
021fc86
feat(mosaic): ring the keyboard-selected bar instead of the whole chart
austincalvelage Nov 25, 2026
68eb30b
refactor(mosaic): style the chart tooltip as one element again
austincalvelage Nov 25, 2026
31836fb
feat(mosaic): slide the chart tooltip between bars (#11006)
alexcarpenter Nov 25, 2026
d2544ad
docs(swingset): describe the chart's column hit area
austincalvelage Nov 25, 2026
768cc8c
feat(mosaic): ring the keyboard-selected bars in the styled chart
austincalvelage Nov 26, 2026
15e38dd
revert(mosaic): drop the styled chart's keyboard focus ring changes
austincalvelage Nov 26, 2026
54effe4
docs(swingset): pin the chart highlight on click
austincalvelage Nov 26, 2026
0c89b8a
feat(mosaic): list the chart legend top to bottom as the bars draw
austincalvelage Dec 3, 2026
fae11ce
feat(mosaic): list zero values in the chart tooltip
austincalvelage Dec 3, 2026
a85955f
feat(mosaic): wrap the chart tooltip footer to the rows' width
austincalvelage Dec 3, 2026
67880f3
refactor(mosaic): move the chart palette beside the chart
austincalvelage Dec 3, 2026
2ca7be1
feat(mosaic): ship the chart styles as @clerk/mosaic/chart.css
austincalvelage Dec 3, 2026
e5977cc
feat(mosaic): render the styled chart through BarChart.Root
austincalvelage Dec 3, 2026
97e81c7
fix(mosaic): satisfy the Mosaic lint rules in the styled chart
austincalvelage Dec 3, 2026
259f069
chore(repo): dedupe the lockfile after the rebase
austincalvelage Dec 3, 2026
2a390ed
chore(swingset): Sort the chart story imports
austincalvelage Dec 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .changeset/mosaic-chart-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
'@clerk/mosaic': minor
---

Add a styled `Chart` at `@clerk/mosaic/components/chart`. `BarChart.Root` takes rows, a category key and series that each name a color. With no children it draws the legend, a dotted grid, the bars, both axes and a tooltip with one row per series. It handles values above and below zero, a projected total, dimming through `highlight`, an empty state and a retry when the Canvas fails to paint.

```tsx
import { BarChart, type ChartSeries } from '@clerk/mosaic/components/chart';

const series: ChartSeries<Row>[] = [
{ key: 'signups', label: 'Sign-ups', color: 1, value: row => row.signups },
{ key: 'churned', label: 'Churned', color: 3, value: row => row.churned, negative: true },
];

<BarChart.Root
aria-label='Weekly growth'
data={rows}
index={row => row.week}
series={series}
/>;
```

Each series names its color: a palette slot from `1` to `6` or a CSS color. `negative: true` marks a series drawn below zero. The legend lists the series top to bottom as the bars draw, and the tooltip lists a zero value with the section its series is drawn in. The `tooltip` prop renders a custom tooltip body, typed from `data`.

Children set the layout. `BarChart.Legend` goes anywhere, such as in a row beside an action, and `BarChart.Plot` holds the layers drawn on the plot. Each axis reserves its own room beside the plot, so leaving one out needs no `margin`. Leaving out `BarChart.Tooltip` gives a chart that takes no focus.

```tsx
<BarChart.Root aria-label='Weekly growth' data={rows} index={getWeek} series={series} onActivate={openPeriod}>
<header>
<BarChart.Legend />
<ExportButton />
</header>
<BarChart.Plot>
<BarChart.Grid />
<BarChart.Bars />
<BarChart.XAxis ticks='calendar' />
<BarChart.Tooltip />
</BarChart.Plot>
</BarChart.Root>
```

The chart's styles ship in their own sheet, `@clerk/mosaic/chart.css`, so `styles.css` does not grow for apps that render no chart. Import it into the same cascade layer as `styles.css`:

```css
@import '@clerk/mosaic/styles.css' layer(components);
@import '@clerk/mosaic/chart.css' layer(components);
```

The palette ships in `chart.css` as six new tokens, `--cl-color-chart-1` to `--cl-color-chart-6`, with separate light and dark values that meet the data-viz contrast and color-blind separation checks.
7 changes: 7 additions & 0 deletions .changeset/mosaic-chart-fluid-tooltip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/mosaic': minor
---

The chart tooltip now slides between bars instead of jumping, and stays put when it first opens. With reduced motion it only fades. While the selected bar is scrolled out of view the tooltip hides, and it comes back when the bar does. Moving the pointer within one bar no longer rerenders the chart.

`Chart.Tooltip` carries two new attributes for styling: `data-moving`, from the first change of bar until it closes, and `data-anchor-hidden`, while the selected bar is out of view.
2 changes: 2 additions & 0 deletions packages/mosaic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ If you want to use custom CSS to theme the components, instead import the styles

This ensures your unlayered custom CSS takes priority. Expect more documentation on custom theming soon.

If you render `BarChart` from `@clerk/mosaic/components/chart`, also import `@clerk/mosaic/chart.css` after `styles.css`, into the same layer. `styles.css` does not include the chart's styles.

### Set a color scheme

Mosaic's colors use [`light-dark()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark), which resolves against the `color-scheme` in scope. Mosaic does not set one, so your app must:
Expand Down
3 changes: 2 additions & 1 deletion packages/mosaic/bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files": [
{ "path": "./dist/.bundlewatch/eager/ui.js", "maxSize": "54KB" },
{ "path": "./dist/.bundlewatch/total/ui.js", "maxSize": "347KB" },
{ "path": "./dist/styles.css", "maxSize": "20KB" }
{ "path": "./dist/styles.css", "maxSize": "20KB" },
{ "path": "./dist/chart.css", "maxSize": "2KB" }
]
}
1 change: 1 addition & 0 deletions packages/mosaic/chart.css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
15 changes: 13 additions & 2 deletions packages/mosaic/docs/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ A theme's CSS wins without any prop because the consumer imports the sheet into

## Tokens

Tokens are `stylex.defineVars` groups in `src/tokens.stylex.ts`, one exported `*Vars` const per group; the file is the list, and its comments explain each group. Keys that start with `--cl-` are emitted verbatim, so they are stable handles. `space` keys are not `--cl-*` names, so its steps are hashed and internal. The derived name unions (`ColorVarName`, …) live in `src/styles/index.ts`, because a `.stylex.ts` file may export only define-primitives.
Tokens are `stylex.defineVars` groups in `src/tokens.stylex.ts`, one exported `*Vars` const per group; the file is the list, and its comments explain each group. A component with its own sheet keeps its tokens beside it ([CSS build](#css-build)). Keys that start with `--cl-` are emitted verbatim, so they are stable handles. `space` keys are not `--cl-*` names, so its steps are hashed and internal. The derived name unions (`ColorVarName`, …) live in `src/styles/index.ts`, because a `.stylex.ts` file may export only define-primitives.

The color model, which decides which token a new style uses:

Expand Down Expand Up @@ -75,7 +75,18 @@ Components render and style without a provider. `MosaicProvider` (`src/mosaic-pr

## CSS build

`src/styles/index.ts` is a StyleX-only barrel of every component, token group and styling helper. The build walks it with the StyleX rollup plugin and extracts one `dist/styles.css`, exported as `@clerk/mosaic/styles.css`. Run it with `pnpm build` in `packages/mosaic`.
`src/styles/index.ts` is a StyleX-only barrel of every component, token group and styling helper. The build walks it with the StyleX rollup plugin and extracts `dist/styles.css`, exported as `@clerk/mosaic/styles.css`. Run it with `pnpm build` in `packages/mosaic`.

A component that Clerk's own components do not render ships its own sheet, so `styles.css` does not carry it. The chart components are the ones today. `src/styles/chart.ts` is its barrel, and the build emits `dist/chart.css`, exported as `@clerk/mosaic/chart.css`. A sheet holds only the rules its barrel reaches that an earlier sheet in `tsdown.css.config.mts` does not hold, so the atoms the chart shares with `Tooltip` or `Button` stay in `styles.css`. A consumer imports both sheets into the same layer:

```css
@import '@clerk/mosaic/styles.css' layer(components);
@import '@clerk/mosaic/chart.css' layer(components);
```

StyleX names a layer `priorityN` by its position among the priority levels in the sheet, so the build gives each sheet every level. `priority3` means the same priority in both files, and each file names all the levels in order, so the sublayer order holds whichever sheet loads first. Within each layer the chart's rules now follow the core rules. A conditional atom outranks a plain one by specificity, not by order, so the move is safe until a chart part carries a chart-only atom and a core atom for the same property at equal specificity. Give such a state its own selector rather than relying on the order.

A component's sheet carries its own tokens. The chart palette, `--cl-color-chart-1` to `-6`, lives in `src/components/chart/chart.vars.stylex.ts`, not `src/tokens.stylex.ts`.

Swingset consumes Mosaic from source instead. `@stylexjs/unplugin/webpack` in its `next.config` compiles the StyleX calls, and `@stylexjs/postcss-plugin` extracts the CSS by replacing `@stylex;` in `globals.css`. Both contexts must use the same StyleX babel version and options, or the atom hashes will not line up.

Expand Down
17 changes: 15 additions & 2 deletions packages/mosaic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"license": "MIT",
"author": "Clerk",
"sideEffects": [
"./dist/styles.css"
"./dist/styles.css",
"./dist/chart.css"
],
"type": "module",
"exports": {
Expand Down Expand Up @@ -71,6 +72,11 @@
"import": "./dist/components/card.js",
"default": "./dist/components/card.js"
},
"./components/chart": {
"types": "./dist/components/chart.d.ts",
"import": "./dist/components/chart.js",
"default": "./dist/components/chart.js"
},
"./components/checkbox": {
"types": "./dist/components/checkbox.d.ts",
"import": "./dist/components/checkbox.js",
Expand Down Expand Up @@ -505,6 +511,10 @@
"types": "./styles.css.d.ts",
"default": "./dist/styles.css"
},
"./chart.css": {
"types": "./chart.css.d.ts",
"default": "./dist/chart.css"
},
"./package.json": "./package.json"
},
"types": "dist/index.d.ts",
Expand All @@ -514,6 +524,7 @@
"!dist/**/*.d.mts.map",
"!dist/.bundlewatch",
"styles.css.d.ts",
"chart.css.d.ts",
"CHANGELOG.md"
],
"scripts": {
Expand All @@ -529,7 +540,7 @@
"format": "node ../../scripts/format-package.mjs",
"format:check": "node ../../scripts/format-package.mjs --check",
"lint": "oxlint -c oxlint.config.mjs src",
"lint:attw": "attw --pack . --exclude-entrypoints styles.css --profile esm-only",
"lint:attw": "attw --pack . --exclude-entrypoints styles.css chart.css --profile esm-only",
"lint:publint": "publint",
"test": "vitest run --project primitives --project lint-rules --project mosaic",
"test:browser": "vitest run --project browser",
Expand All @@ -548,6 +559,7 @@
},
"devDependencies": {
"@clerk/clerk-js": "workspace:^",
"@stylexjs/babel-plugin": "0.19.2",
"@stylexjs/eslint-plugin": "0.19.2",
"@stylexjs/rollup-plugin": "0.19.2",
"@stylexjs/stylex": "0.19.2",
Expand All @@ -566,6 +578,7 @@
"eslint-plugin-boundaries": "7.3.0",
"eslint-plugin-react-you-might-not-need-an-effect": "1.0.2",
"happy-dom": "^20.8.9",
"lightningcss": "1.33.0",
"msw": "2.15.0",
"playwright": "1.62.1",
"qrcode.react": "4.2.0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';

import { describe, expect, it } from 'vitest';

import { assertChartPalette, oklchToSrgb8, type PaletteMode, type Srgb8 } from './palette-checks';

const tokens = readFileSync(resolve(import.meta.dirname, '../chart.vars.stylex.ts'), 'utf8');

const OKLCH = String.raw`oklch\(([\d.]+) ([\d.]+) ([\d.]+)\)`;
const TOKEN = new RegExp(String.raw`'--cl-color-chart-(\d+)': 'light-dark\(${OKLCH}, ${OKLCH}\)'`, 'g');

function palette(mode: PaletteMode): Srgb8[] {
const slots = [...tokens.matchAll(TOKEN)];
return slots.map(([, , ...values]) => {
const [l, c, h] = (mode === 'light' ? values.slice(0, 3) : values.slice(3)).map(Number);
return oklchToSrgb8(l, c, h);
});
}

const white = oklchToSrgb8(1, 0, 0);
// `--cl-color-surface` in dark mode: 5% of the white neutral mixed in OKLab into the 0.16 page.
const darkSurface = oklchToSrgb8(0.95 * 0.16 + 0.05, 0, 0);
const darkPage = oklchToSrgb8(0.16, 0, 0);

describe('chart palette tokens', () => {
it('defines six slots, in order, each as one light-dark value', () => {
expect([...tokens.matchAll(TOKEN)].map(([, slot]) => slot)).toEqual(['1', '2', '3', '4', '5', '6']);
});

it('passes the data-viz checks in light mode on the surface', () => {
expect(() => assertChartPalette(palette('light'), 'light', white)).not.toThrow();
});

it('passes the data-viz checks in dark mode on the surface and on the page', () => {
expect(() => assertChartPalette(palette('dark'), 'dark', darkSurface)).not.toThrow();
expect(() => assertChartPalette(palette('dark'), 'dark', darkPage)).not.toThrow();
});

it('rejects the original story hues, which fail the band and chroma checks', () => {
const channel = (value: string, at: number) => parseInt(value.slice(at, at + 2), 16) / 255;
const hex = (value: string): Srgb8 => [channel(value, 0), channel(value, 2), channel(value, 4)];
const original = ['7c3aed', '0ea5e9', 'f97316', '06b6d4', 'eab308', '64748b'].map(hex);

expect(() => assertChartPalette(original, 'light', white)).toThrow(/slot 5: lightness .*\n.*slot 6: chroma/s);
});
});
Loading
Loading