Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(quill): own data-viz palette in tokens + shared chart theme reader (#61829)

Adam Leithdf6f8c291688
diff --git a/packages/quill/apps/storybook/.storybook/preview.tsx b/packages/quill/apps/storybook/.storybook/preview.tsx
index 57b7f210106b..a7b349b79284 100644
--- a/packages/quill/apps/storybook/.storybook/preview.tsx
+++ b/packages/quill/apps/storybook/.storybook/preview.tsx
@@ -1,9 +1,9 @@
import './storybook.css'
-import React, { useEffect, useState } from 'react'
+import { DocsContainer } from '@storybook/addon-docs'
import type { Preview } from '@storybook/react'
import { themes } from '@storybook/theming'
-import { DocsContainer } from '@storybook/addon-docs'
+import React, { useEffect, useState } from 'react'
import { useDarkMode } from 'storybook-dark-mode'
// The Docs container renders outside Storybook's preview-hooks context, so
diff --git a/packages/quill/packages/blocks/package.json b/packages/quill/packages/blocks/package.json
index b29f26688bce..4a7c5fae7ea8 100644
--- a/packages/quill/packages/blocks/package.json
+++ b/packages/quill/packages/blocks/package.json
@@ -1,6 +1,6 @@
{
"name": "@posthog/quill-blocks",
- "version": "0.3.0-beta.13",
+ "version": "0.3.0-beta.14",
"private": true,
"description": "Internal workspace package (private, not published). The highest layer of the quill design system — product-level patterns made of components + primitives (e.g. a PageHeader with title + breadcrumb + action slot, an EmptyState with icon + copy + CTA, a CommandPalette, a user-menu dropdown). Opinionated and shape-stable across products so they feel consistent. Bundled into @posthog/quill at build time; consumers should import from @posthog/quill instead.",
"license": "MIT",
diff --git a/packages/quill/packages/charts/package.json b/packages/quill/packages/charts/package.json
index a1ad9ad21b23..32007f576daa 100644
--- a/packages/quill/packages/charts/package.json
+++ b/packages/quill/packages/charts/package.json
@@ -30,6 +30,7 @@
"simple-statistics": "^7.8.3"
},
"devDependencies": {
+ "@posthog/quill-tokens": "workspace:*",
"@storybook/react": "catalog:",
"@testing-library/react": "^14.3.1",
"@types/d3-array": "^3.2.1",
diff --git a/packages/quill/packages/charts/src/README.md b/packages/quill/packages/charts/src/README.md
index ddb195f54301..6f18cdc14257 100644
--- a/packages/quill/packages/charts/src/README.md
+++ b/packages/quill/packages/charts/src/README.md
@@ -13,6 +13,36 @@ const THEME: ChartTheme = { colors: ['#1f77b4'], backgroundColor: '#ffffff' }
;<LineChart series={SERIES} labels={LABELS} theme={THEME} />
```
+## Theme
+
+Charts are **headless about color** — every chart takes a `ChartTheme` (`colors`
+plus axis/grid/tooltip colors) and owns no palette of its own. Supply it however
+you like, but the intended source is quill's design tokens.
+
+`@posthog/quill-tokens` defines the data-viz palette as CSS vars
+(`--data-color-1..15`, `--color-graph-*`). Read them into a `ChartTheme` with the
+built-in helpers instead of hand-rolling per consumer:
+
+```tsx
+import { useChartTheme, BarChart } from '@posthog/quill-charts'
+
+function MyChart() {
+ const theme = useChartTheme() // re-reads on light/dark toggle
+ return <BarChart series={SERIES} labels={LABELS} theme={theme} />
+}
+```
+
+- `useChartTheme(opts?)` — React hook; re-reads the vars when the `class` / `theme`
+ attribute flips on `<html>` or `<body>`.
+- `themeFromCssVars(opts?)` — one-shot, non-React read.
+- `DEFAULT_CHART_COLORS` — fallback palette used when the token vars aren't loaded
+ (no quill-tokens stylesheet, or SSR). Without tokens loaded you get this palette,
+ not black. Load `@posthog/quill-tokens/color-system.css` to get the real tokens.
+
+Both helpers read from `document.body` by default. If you use the **scoped** token
+build (vars gated behind `[data-quill]`) and quill isn't mounted on `<body>`, pass
+`root` pointing inside the scoped subtree: `useChartTheme({ root: myQuillEl })`.
+
## Series
- `series.overlay` (default `false`): marks an auxiliary series derived from primary data — trend lines and moving averages. Excluded from stack computation and from the y-axis baseline calculation, so a trendline projection won't drag the axis below 0 when the underlying data is non-negative. (CI bands are not overlays — they represent real data uncertainty whose range should still influence the axis.)
diff --git a/packages/quill/packages/charts/src/core/theme.test.ts b/packages/quill/packages/charts/src/core/theme.test.ts
new file mode 100644
index 000000000000..84c245bb679c
--- /dev/null
+++ b/packages/quill/packages/charts/src/core/theme.test.ts
@@ -0,0 +1,74 @@
+import { dataColorPalette } from '@posthog/quill-tokens'
+
+import { DEFAULT_CHART_COLORS, themeFromCssVars } from './theme'
+
+describe('chart theme', () => {
+ afterEach(() => {
+ document.body.replaceChildren()
+ })
+
+ function rootWithVars(vars: Record<string, string>): HTMLElement {
+ const el = document.createElement('div')
+ for (const [name, value] of Object.entries(vars)) {
+ el.style.setProperty(name, value)
+ }
+ document.body.appendChild(el)
+ return el
+ }
+
+ it('fallback palette stays in sync with the quill-tokens palette', () => {
+ // Guards the duplicated literal against drift — tokens (`dataColorPalette`)
+ // is the source of truth; update both together.
+ expect(DEFAULT_CHART_COLORS).toEqual([...dataColorPalette])
+ })
+
+ it('reads --data-color-* and quill chrome vars off the given root', () => {
+ const root = rootWithVars({
+ '--data-color-1': '#111111',
+ '--data-color-2': '#222222',
+ '--color-graph-axis-label': '#aaaaaa',
+ '--color-graph-axis-line': '#bbbbbb',
+ '--background': '#f0f0f0',
+ })
+
+ const theme = themeFromCssVars({ root, colorCount: 2 })
+
+ expect(theme.colors).toEqual(['#111111', '#222222'])
+ expect(theme.axisColor).toBe('#aaaaaa')
+ expect(theme.gridColor).toBe('#bbbbbb')
+ expect(theme.backgroundColor).toBe('#f0f0f0')
+ })
+
+ it.each<{ name: string; vars: Record<string, string>; expected: string }>([
+ {
+ name: 'prefers the quill token over the app compat name',
+ vars: { '--background': '#quill0', '--color-bg-surface-primary': '#app000' },
+ expected: '#quill0',
+ },
+ {
+ name: 'falls back to the app compat name when the quill token is absent',
+ vars: { '--color-bg-surface-primary': '#app000' },
+ expected: '#app000',
+ },
+ ])('backgroundColor $name', ({ vars, expected }) => {
+ const root = rootWithVars(vars)
+
+ expect(themeFromCssVars({ root }).backgroundColor).toBe(expected)
+ })
+
+ it('falls back to DEFAULT_CHART_COLORS for unset color vars', () => {
+ const root = rootWithVars({})
+
+ expect(themeFromCssVars({ root }).colors).toEqual([...DEFAULT_CHART_COLORS])
+ })
+
+ it('wraps the fallback palette when colorCount exceeds the defaults', () => {
+ const root = rootWithVars({})
+ const colorCount = DEFAULT_CHART_COLORS.length + 2
+
+ const { colors } = themeFromCssVars({ root, colorCount })
+
+ expect(colors).toHaveLength(colorCount)
+ expect(colors[DEFAULT_CHART_COLORS.length]).toBe(DEFAULT_CHART_COLORS[0])
+ })
+})
diff --git a/packages/quill/packages/charts/src/core/theme.ts b/packages/quill/packages/charts/src/core/theme.ts
new file mode 100644
index 000000000000..2d8c7f98ac44
--- /dev/null
+++ b/packages/quill/packages/charts/src/core/theme.ts
@@ -0,0 +1,111 @@
+import { useEffect, useState } from 'react'
+
+import type { ChartTheme } from './types'
+
+/**
+ * Fallback categorical palette, used only when the `--data-color-*` CSS vars
+ * aren't loaded (no `@posthog/quill-tokens` stylesheet, or SSR with no DOM).
+ *
+ * Charts are headless — colors normally come from the host's design tokens via
+ * {@link themeFromCssVars}. `@posthog/quill-tokens` is the source of truth for
+ * these values (`dataColorPalette`); this literal copy keeps the package's
+ * runtime dependency-free so a missing stylesheet degrades to a visible palette
+ * instead of black. `theme.test.ts` asserts it stays equal to the token palette,
+ * so the duplication can't silently drift — update both together.
+ */
+export const DEFAULT_CHART_COLORS: readonly string[] = [
+ '#1d4aff',
+ '#621da6',
+ '#42827e',
+ '#ce0e74',
+ '#f14f58',
+ '#7c440e',
+ '#529a0a',
+ '#0476fb',
+ '#fe729e',
+ '#35416b',
+ '#41cbc4',
+ '#b64b02',
+ '#e4a604',
+ '#a56eff',
+ '#30d5c8',
+]
+
+export interface ThemeFromCssOptions {
+ /**
+ * Element whose computed styles are read. Token vars defined on `:root`
+ * inherit down to any element, and dark-mode overrides applied to `<body>`
+ * (the visual test-runner flips `body[theme="dark"]`) are only visible at
+ * or below `<body>` — so the default is `document.body`, not `<html>`.
+ */
+ root?: HTMLElement
+ /** How many `--data-color-N` vars to read (default 15, the token count). */
+ colorCount?: number
+}
+
+function readCssVar(style: CSSStyleDeclaration, name: string): string | undefined {
+ return style.getPropertyValue(name).trim() || undefined
+}
+
+/**
+ * Build a {@link ChartTheme} from the quill data-viz CSS vars
+ * (`--data-color-*`, `--color-graph-*`, surface/text tokens). Reads computed
+ * styles once; pair with {@link useChartTheme} to re-read on theme changes.
+ *
+ * Safe on the server / before mount: returns the fallback palette when there's
+ * no DOM.
+ */
+export function themeFromCssVars(options: ThemeFromCssOptions = {}): ChartTheme {
+ const { colorCount = DEFAULT_CHART_COLORS.length } = options
+
+ if (typeof document === 'undefined' || typeof getComputedStyle !== 'function') {
+ return { colors: [...DEFAULT_CHART_COLORS] }
+ }
+
+ const root = options.root ?? document.body
+ const style = getComputedStyle(root)
+
+ const colors = Array.from(
+ { length: colorCount },
+ (_, i) => readCssVar(style, `--data-color-${i + 1}`) ?? DEFAULT_CHART_COLORS[i % DEFAULT_CHART_COLORS.length]
+ )
+
+ // Prefer quill's own tokens; the app's `--color-*` names are a compat
+ // fallback only, so the design-system package never depends on app naming.
+ return {
+ colors,
+ backgroundColor: readCssVar(style, '--background') ?? readCssVar(style, '--color-bg-surface-primary'),
+ axisColor: readCssVar(style, '--color-graph-axis-label'),
+ gridColor: readCssVar(style, '--color-graph-axis-line'),
+ crosshairColor: readCssVar(style, '--color-graph-crosshair'),
+ tooltipBackground: readCssVar(style, '--card') ?? readCssVar(style, '--color-bg-surface-tooltip'),
+ tooltipColor: readCssVar(style, '--foreground') ?? readCssVar(style, '--color-text-primary-inverse'),
+ }
+}
+
+/**
+ * React hook returning a {@link ChartTheme} read from the quill data-viz CSS
+ * vars, kept in sync as the active theme changes. Watches the `class` / `theme`
+ * attributes on both `<html>` and `<body>` (different toggling conventions set
+ * one or the other) and re-reads the vars whenever they flip.
+ */
+export function useChartTheme(options: ThemeFromCssOptions = {}): ChartTheme {
+ const { root, colorCount } = options
+ const [theme, setTheme] = useState<ChartTheme>(() => themeFromCssVars(options))
+
+ useEffect(() => {
+ if (typeof document === 'undefined' || typeof MutationObserver !== 'function') {
+ return
+ }
+ const reread = (): void => setTheme(themeFromCssVars({ root, colorCount }))
+ reread()
+ const observer = new MutationObserver(reread)
+ const opts: MutationObserverInit = { attributes: true, attributeFilter: ['class', 'theme', 'data-theme'] }
+ observer.observe(document.documentElement, opts)
+ observer.observe(document.body, opts)
+ return () => observer.disconnect()
+ // root/colorCount are the only inputs; options identity is intentionally ignored.
+ }, [root, colorCount])
+
+ return theme
+}
diff --git a/packages/quill/packages/charts/src/index.ts b/packages/quill/packages/charts/src/index.ts
index c531c413f824..94d10f3e78d6 100644
--- a/packages/quill/packages/charts/src/index.ts
+++ b/packages/quill/packages/charts/src/index.ts
@@ -79,6 +79,10 @@ export type {
} from './core/types'
export { DEFAULT_Y_AXIS_ID } from './core/types'
+// Theme: read a ChartTheme from quill data-viz CSS vars (with a built-in fallback palette)
+export { themeFromCssVars, useChartTheme, DEFAULT_CHART_COLORS } from './core/theme'
+export type { ThemeFromCssOptions } from './core/theme'
+
// Built-in tooltip (for reference or extension)
export { DefaultTooltip } from './overlays/DefaultTooltip'
diff --git a/packages/quill/packages/charts/src/story-helpers.tsx b/packages/quill/packages/charts/src/story-helpers.tsx
index 7ced56cf9b3c..1bb95e20b0b6 100644
--- a/packages/quill/packages/charts/src/story-helpers.tsx
+++ b/packages/quill/packages/charts/src/story-helpers.tsx
@@ -1,60 +1,16 @@
import { fireEvent, waitFor } from '@testing-library/dom'
-import { useEffect, useState } from 'react'
+import { useChartTheme } from './core/theme'
import type { ChartTheme } from './core/types'
-const DATA_COLOR_VARS = [
- 'data-color-1',
- 'data-color-2',
- 'data-color-3',
- 'data-color-4',
- 'data-color-5',
- 'data-color-6',
- 'data-color-7',
- 'data-color-8',
- 'data-color-9',
- 'data-color-10',
- 'data-color-11',
- 'data-color-12',
- 'data-color-13',
- 'data-color-14',
- 'data-color-15',
-]
-
-function readCssVar(name: string): string | undefined {
- const value = getComputedStyle(document.body)
- .getPropertyValue('--' + name)
- .trim()
- return value || undefined
-}
-
-function buildTheme(): ChartTheme {
- return {
- colors: DATA_COLOR_VARS.map((v) => readCssVar(v) ?? '#000'),
- backgroundColor: readCssVar('color-bg-surface-primary') ?? '#ffffff',
- axisColor: readCssVar('color-graph-axis-label'),
- gridColor: readCssVar('color-graph-axis-line'),
- crosshairColor: readCssVar('color-graph-crosshair'),
- tooltipBackground: readCssVar('color-bg-surface-tooltip'),
- tooltipColor: readCssVar('color-text-primary-inverse'),
- }
-}
-
/**
- * `buildTheme()` reads CSS variables from `document.body` once. The Storybook
- * test runner takes a second screenshot after flipping `body[theme="dark"]`,
- * but stories that captured the theme at first render keep light-mode colors
- * in the dark snapshot. This hook re-evaluates `buildTheme()` whenever the
- * theme attribute changes so the chart's own colors actually update.
+ * Theme for stories, read from the quill data-viz CSS vars and kept in sync as
+ * the active light/dark mode changes (the visual test runner flips the theme
+ * for its second screenshot). Thin alias over the package's {@link useChartTheme}
+ * so stories and product code resolve colors through the exact same reader.
*/
export function useReactiveTheme(): ChartTheme {
- const [theme, setTheme] = useState<ChartTheme>(() => buildTheme())
- useEffect(() => {
- const observer = new MutationObserver(() => setTheme(buildTheme()))
- observer.observe(document.body, { attributes: true, attributeFilter: ['theme', 'class'] })
- return () => observer.disconnect()
- }, [])
- return theme
+ return useChartTheme()
}
interface StageProps {
diff --git a/packages/quill/packages/components/package.json b/packages/quill/packages/components/package.json
index 6453a4309c42..a61208d004c0 100644
--- a/packages/quill/packages/components/package.json
+++ b/packages/quill/packages/components/package.json
@@ -1,6 +1,6 @@
{
"name": "@posthog/quill-components",
- "version": "0.3.0-beta.13",
+ "version": "0.3.0-beta.14",
"private": true,
"description": "Internal workspace package (private, not published). The middle layer of the quill design system — higher-level compositions of primitives that wire several of them together with sensible defaults (e.g. a FormField that composes Label + Input + validation state, or a ConfirmDialog that composes Dialog + Button + destructive variant). Bundled into @posthog/quill at build time; consumers should import from @posthog/quill instead.",
"license": "MIT",
diff --git a/packages/quill/packages/primitives/package.json b/packages/quill/packages/primitives/package.json
index 5aa9592675e0..f81092b3bf9d 100644
--- a/packages/quill/packages/primitives/package.json
+++ b/packages/quill/packages/primitives/package.json
@@ -1,6 +1,6 @@
{
"name": "@posthog/quill-primitives",
- "version": "0.3.0-beta.13",
+ "version": "0.3.0-beta.14",
"private": true,
"description": "Internal workspace package (private, not published). The lowest layer of the quill design system — unstyled Base UI primitives wrapped with quill's Tailwind classes (Button, Card, Dialog, Input, Popover, Combobox, etc.). Bundled into @posthog/quill at build time; consumers should import from @posthog/quill instead.",
"license": "MIT",
diff --git a/packages/quill/packages/quill/package.json b/packages/quill/packages/quill/package.json
index 6789123015d3..5073a306a394 100644
--- a/packages/quill/packages/quill/package.json
+++ b/packages/quill/packages/quill/package.json
@@ -1,6 +1,6 @@
{
"name": "@posthog/quill",
- "version": "0.3.0-beta.13",
+ "version": "0.3.0-beta.14",
"description": "PostHog's unified design system — primitives, components, and blocks designed to be compiled by the consumer's Tailwind v4.",
"license": "MIT",
"repository": {
diff --git a/packages/quill/packages/tokens/AGENTS.md b/packages/quill/packages/tokens/AGENTS.md
index e69de29bb2d1..95cd0d42d742 100644
--- a/packages/quill/packages/tokens/AGENTS.md
+++ b/packages/quill/packages/tokens/AGENTS.md
@@ -0,0 +1,66 @@
+# Quill Tokens — Agent Guide
+
+`@posthog/quill-tokens` is the source of truth for quill's design tokens. Tokens
+are authored in TypeScript under `src/` and **generated** into CSS in `dist/`.
+Never hand-edit `dist/*.css` — every file is stamped
+`Auto-generated by @posthog/quill-tokens — do not edit manually`.
+
+## Pipeline
+
+```text
+src/*.ts ──(tsx src/build.ts)──▶ dist/*.css
+```
+
+`pnpm --filter @posthog/quill-tokens build` runs `src/build.ts` then `vite build`.
+`build.ts` calls the generators in `colors.ts` and writes:
+
+| File | Contents | Consumed by |
+| ------------------ | ------------------------------------------------------------ | -------------------------------------- |
+| `color-system.css` | `:root` (light) + dark-selector overrides — runtime CSS vars | apps & packages at runtime |
+| `tailwind.css` | `@theme` + `@custom-variant` + base layer | apps |
+| `tailwind-lib.css` | `@theme` + `@custom-variant` only | library packages |
+| `*.scoped.css` | same, gated behind `[data-quill]` | consumers with their own design system |
+
+After changing anything in `src/`, **rerun the build** so `dist/` matches.
+(The quill storybook also watches `src/` via `quillTokensWatcher` in its
+`main.ts`, so it hot-reloads without a manual build.)
+
+## Token groups
+
+- **Semantic colors** (`colors.ts`, `buildSemanticColors`) — `[light, dark, tailwindClass]`
+ tuples. Surface/neutral colors are theme-hue-derived (`surface()`); status and
+ brand colors are static `oklch()`. Theme-derived tokens must be listed in
+ `THEME_DERIVED_TOKENS` (a load-time guard enforces this) so they emit on `*`
+ and re-evaluate under local `[--theme-hue:X]` overrides.
+- **Data-visualization** (`data-viz.ts`) — see below.
+- **Spacing / typography / shadow / border-radius** — own modules, own generators.
+
+## Data-visualization tokens (`data-viz.ts`)
+
+Consumed by `@posthog/quill-charts`, which ships **no CSS** and reads these vars
+into a `ChartTheme` at runtime (via its `themeFromCssVars` / `useChartTheme`).
+
+- `--data-color-1..15` — an **ordered categorical palette** for series colors.
+ Order is meaningful and hues must stay mutually distinguishable. Values are
+ static brand hexes (not theme-hue-derived); only the entries needing extra
+ dark-mode contrast carry an override. Edit the `dataColors` array — the no-CSS
+ fallback copy `DEFAULT_CHART_COLORS` in quill-charts (`core/theme.ts`) must
+ match; its `theme.test.ts` asserts equality with `dataColorPalette`, so drift
+ fails CI rather than slipping through.
+- `--color-graph-axis-label`, `--color-graph-axis-line`, `--color-graph-crosshair`
+ — graph chrome, aliased onto semantic tokens (`--muted-foreground`, `--border`)
+ so they flip with light/dark automatically (no dark block needed).
+
+These names match the PostHog app's historical `--data-color-*` / `--color-graph-*`,
+so the app can drop its local definitions and inherit quill's instead.
+
+JS exports for non-CSS consumers: `dataColors`, `dataColorPalette`, `dataColorVarName`.
+
+## Adding or changing a token
+
+1. Edit the relevant `src/*.ts` module (e.g. add a `dataColors` entry, or a
+ `semanticColors` tuple).
+2. If a semantic token references a theme var directly, add it to
+ `THEME_DERIVED_TOKENS`.
+3. Rerun `pnpm --filter @posthog/quill-tokens build`.
+4. Verify the var appears in `dist/color-system.css` (and `.scoped.css`).
diff --git a/packages/quill/packages/tokens/package.json b/packages/quill/packages/tokens/package.json
index 6aa55106928c..856dea6a1f88 100644
--- a/packages/quill/packages/tokens/package.json
+++ b/packages/quill/packages/tokens/package.json
@@ -1,6 +1,6 @@
{
"name": "@posthog/quill-tokens",
- "version": "0.3.0-beta.13",
+ "version": "0.3.0-beta.14",
"license": "MIT",
"repository": {
"type": "git",
diff --git a/packages/quill/packages/tokens/src/colors.ts b/packages/quill/packages/tokens/src/colors.ts
index 5885a7ad34b4..9a2ade42695c 100644
--- a/packages/quill/packages/tokens/src/colors.ts
+++ b/packages/quill/packages/tokens/src/colors.ts
@@ -11,6 +11,7 @@
*/
import { cssVarsFlat } from './css'
+import { generateDataVizVars } from './data-viz'
import { generateShadowCSS, shadow } from './shadow'
import { generateSpacingCSS } from './spacing'
import { generateFontSizeCSS, generateFontFamilyCSS } from './typography'
@@ -61,11 +62,7 @@ export type ColorTuple = readonly [light: string, dark: string, tailwindClass: s
function surface(lightness: number, chromaScale: number, mode: 'light' | 'dark', alpha?: number): string {
const hueVar = mode === 'light' ? 'var(--theme-hue)' : 'var(--theme-dark-hue)'
const chromaExpr =
- chromaScale === 1
- ? 'var(--theme-tint)'
- : chromaScale === 0
- ? '0'
- : `calc(var(--theme-tint) * ${chromaScale})`
+ chromaScale === 1 ? 'var(--theme-tint)' : chromaScale === 0 ? '0' : `calc(var(--theme-tint) * ${chromaScale})`
const alphaSuffix = alpha !== undefined ? ` / ${alpha * 100}%` : ''
return `oklch(${lightness} ${chromaExpr} ${hueVar}${alphaSuffix})`
}
@@ -125,11 +122,7 @@ export function buildSemanticColors(): Record<string, ColorTuple> {
],
success: [oklch(0.94, 0.06, 154.03), oklch(0.27, 0.04, 157.6), 'bg-success'],
- 'success-foreground': [
- oklch(0.448, 0.119, 151.328),
- oklch(0.925, 0.084, 155.995),
- 'text-success-foreground',
- ],
+ 'success-foreground': [oklch(0.448, 0.119, 151.328), oklch(0.925, 0.084, 155.995), 'text-success-foreground'],
warning: [oklch(0.93, 0.04, 74.41), oklch(0.29, 0.03, 75), 'bg-warning'],
'warning-foreground': [oklch(0.476, 0.114, 61.907), oklch(0.77, 0.14, 99.29), 'text-warning-foreground'],
@@ -138,8 +131,8 @@ export function buildSemanticColors(): Record<string, ColorTuple> {
'info-foreground': [oklch(0.49, 0.02, 254), oklch(0.882, 0.059, 254.128), 'text-info-foreground'],
// ── Borders & rings (theme-derived) ───────────
- border: [surface(0.90, 0.8, 'light'), surface(0.27, 1.2, 'dark'), 'border-border'],
- input: [surface(0.81, 0.5, 'light'), surface(0.30, 1.5, 'dark'), 'border-input'],
+ border: [surface(0.9, 0.8, 'light'), surface(0.27, 1.2, 'dark'), 'border-border'],
+ input: [surface(0.81, 0.5, 'light'), surface(0.3, 1.5, 'dark'), 'border-input'],
ring: [oklch(0.446, 0.03, 257), oklch(0.709, 0, 0), 'border-ring'],
// ── Interactive fills for default button / interactive elements ───────────
@@ -304,6 +297,10 @@ export function generateColorSystemCSS(
const light = partition(0)
const dark = partition(1)
+ // Data-viz tokens (categorical palette + graph chrome) are static like the
+ // semantic static vars — they live with them on :root / the scope selector.
+ const dataViz = generateDataVizVars()
+
// ── Scoped mode ─────────────────────────────────────
// All vars gated behind the scope selector to avoid clashing
// with the consumer's existing CSS custom properties.
@@ -339,6 +336,9 @@ ${themeKnobs()}
${cssVarsFlat(light.staticVars)}
${cssVarsFlat(light.dynamicVars)}
+ /* Data-visualization palette + graph chrome (see data-viz.ts) */
+${dataViz.light}
+
/* Override Tailwind --color-* theme tokens within scope so utilities
* like bg-card, text-foreground, border-border resolve to quill's
* values instead of the consumer's global theme. */
@@ -348,6 +348,7 @@ ${generateColorMappingsCSS()}
${darkScopeSel} {
${cssVarsFlat(dark.staticVars)}
${cssVarsFlat(dark.dynamicVars)}
+${dataViz.dark}
}
`
}
@@ -371,10 +372,14 @@ ${themeKnobs()}
/* Static colors (no theme-var references, safe on :root) */
:root {
${cssVarsFlat(light.staticVars)}
+
+ /* Data-visualization palette + graph chrome (see data-viz.ts) */
+${dataViz.light}
}
${darkSelector} {
${cssVarsFlat(dark.staticVars)}
+${dataViz.dark}
}
/*
diff --git a/packages/quill/packages/tokens/src/data-viz.ts b/packages/quill/packages/tokens/src/data-viz.ts
new file mode 100644
index 000000000000..a6fb73c0f249
--- /dev/null
+++ b/packages/quill/packages/tokens/src/data-viz.ts
@@ -0,0 +1,79 @@
+/**
+ * PostHog Design System — Data-visualization tokens
+ *
+ * Two kinds of token live here, both consumed by `@posthog/quill-charts`
+ * (charts ship no CSS — they read these vars into a `ChartTheme` at runtime):
+ *
+ * 1. A **categorical palette** (`--data-color-1..N`) — an ordered, qualitative
+ * scale charts index into for series colors. Distinct from the semantic
+ * color map in `colors.ts`: order is meaningful, hues must stay mutually
+ * distinguishable, and the values are static brand hexes (NOT derived from
+ * `--theme-hue`). Only the shades that need extra contrast carry a dark
+ * override; the rest reuse the light value.
+ *
+ * 2. **Graph chrome** vars (axis labels, grid lines, crosshair) — aliased onto
+ * existing semantic tokens so they flip with light/dark automatically and
+ * need no separate dark block.
+ *
+ * Var names match the PostHog app's historical `--data-color-*` /
+ * `--color-graph-*` so the app can drop its local definitions and inherit
+ * these instead.
+ */
+
+/** `[light, dark?]` — omit `dark` to reuse the light value in both modes. */
+export type DataColorTuple = readonly [light: string, dark?: string]
+
+/** Ordered categorical series palette. Index 0 → `--data-color-1`. */
+export const dataColors: readonly DataColorTuple[] = [
+ ['#1d4aff'],
+ ['#621da6', '#7f26d9'],
+ ['#42827e', '#3e7a76'],
+ ['#ce0e74', '#bf0d6c'],
+ ['#f14f58', '#f0474f'],
+ ['#7c440e', '#b36114'],
+ ['#529a0a'],
+ ['#0476fb'],
+ ['#fe729e'],
+ ['#35416b', '#6576b3'],
+ ['#41cbc4'],
+ ['#b64b02'],
+ ['#e4a604'],
+ ['#a56eff'],
+ ['#30d5c8'],
+] as const
+
+/** Light-mode palette as a plain array — for JS consumers and as a sensible
+ * fallback when the CSS vars aren't loaded (see quill-charts `DEFAULT_CHART_COLORS`). */
+export const dataColorPalette: readonly string[] = dataColors.map(([light]) => light)
+
+/** CSS custom property name for the categorical color at `index` (0-based). */
+export function dataColorVarName(index: number): string {
+ return `--data-color-${index + 1}`
+}
+
+/** Graph chrome tokens, aliased onto semantic vars so they track theme mode. */
+const graphChrome: Record<string, string> = {
+ '--color-graph-axis-label': 'var(--muted-foreground)',
+ '--color-graph-axis-line': 'var(--border)',
+ '--color-graph-crosshair': 'var(--muted-foreground)',
+}
+
+/**
+ * CSS var lines for the data-viz tokens, split by mode. Injected into
+ * `color-system.css` alongside the static semantic colors (these are not
+ * theme-hue-derived, so `:root` / the scope selector is the right home).
+ *
+ * - `light`: full palette + graph chrome.
+ * - `dark`: only the palette entries that define an override.
+ */
+export function generateDataVizVars(indent = ' '): { light: string; dark: string } {
+ const lightLines = [
+ ...dataColors.map(([light], i) => `${indent}${dataColorVarName(i)}: ${light};`),
+ ...Object.entries(graphChrome).map(([name, value]) => `${indent}${name}: ${value};`),
+ ]
+ const darkLines = dataColors
+ .map(([, dark], i) => (dark ? `${indent}${dataColorVarName(i)}: ${dark};` : null))
+ .filter((line): line is string => line !== null)
+
+ return { light: lightLines.join('\n'), dark: darkLines.join('\n') }
+}
diff --git a/packages/quill/packages/tokens/src/index.ts b/packages/quill/packages/tokens/src/index.ts
index d52ee1bff254..89b6ffd47698 100644
--- a/packages/quill/packages/tokens/src/index.ts
+++ b/packages/quill/packages/tokens/src/index.ts
@@ -9,6 +9,10 @@ export {
} from './colors'
export type { SemanticColorKey, ColorTuple, StylesConfig, ThemeConfig } from './colors'
+// Data-visualization tokens (categorical palette + graph chrome)
+export { dataColors, dataColorPalette, dataColorVarName, generateDataVizVars } from './data-viz'
+export type { DataColorTuple } from './data-viz'
+
// Spacing
export { spacing, spacingPx, SPACING_BASE, SPACING_BASE_REM } from './spacing'
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 98b702f55e53..23a9f9030f26 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1927,6 +1927,9 @@ importers:
specifier: ^7.8.3
version: 7.8.8
devDependencies:
+ '@posthog/quill-tokens':
+ specifier: workspace:*
+ version: link:../tokens
'@storybook/react':
specifier: 'catalog:'