: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
refactor(quill): shared inline-styled chart tooltip surface (#61847)
Adam Leith3eadccb9e56d
diff --git a/.github/workflows/publish-quill-npm.yml b/.github/workflows/publish-quill-npm.ymlindex aa86bd74d7c1..45f18bbd4be5 100644--- a/.github/workflows/publish-quill-npm.yml+++ b/.github/workflows/publish-quill-npm.yml@@ -59,6 +59,10 @@ jobs:npm version "$BUMP_TYPE" --no-git-tag-versionQUILL_V=$(node -p "require('./package.json').version")echo "Bumped @posthog/quill to $QUILL_V ($BUMP_TYPE)"+ cd ../charts+ npm version "$BUMP_TYPE" --no-git-tag-version+ CHARTS_V=$(node -p "require('./package.json').version")+ echo "Bumped @posthog/quill-charts to $CHARTS_V ($BUMP_TYPE)"- name: Install dependenciesrun: pnpm install --frozen-lockfile --filter "@posthog/quill..." --filter "@posthog/quill-tokens" --filter "@posthog/quill-charts..."@@ -141,10 +145,11 @@ jobs:- name: Commit version bumprun: |- git add packages/quill/packages/tokens/package.json packages/quill/packages/quill/package.json+ git add packages/quill/packages/tokens/package.json packages/quill/packages/quill/package.json packages/quill/packages/charts/package.jsonTOKENS_V=$(node -p "require('./packages/quill/packages/tokens/package.json').version")QUILL_V=$(node -p "require('./packages/quill/packages/quill/package.json').version")- git commit -m "chore(quill): bump quill-tokens to $TOKENS_V, quill to $QUILL_V [skip ci]"+ CHARTS_V=$(node -p "require('./packages/quill/packages/charts/package.json').version")+ git commit -m "chore(quill): bump quill-tokens to $TOKENS_V, quill to $QUILL_V, quill-charts to $CHARTS_V [skip ci]"if ! git push; thenecho "::warning::git push failed (likely branch protection). Versions were published successfully but package.json not updated in repo. A manual bump or PR may be needed."fidiff --git a/packages/quill/apps/storybook/.storybook/storybook.css b/packages/quill/apps/storybook/.storybook/storybook.cssindex ea07e5ee0c96..029e28bf3a98 100644--- a/packages/quill/apps/storybook/.storybook/storybook.css+++ b/packages/quill/apps/storybook/.storybook/storybook.css@@ -65,6 +65,7 @@@source "../../../packages/primitives/src/**/*.{ts,tsx}";@source "../../../packages/components/src/**/*.{ts,tsx}";@source "../../../packages/blocks/src/**/*.{ts,tsx}";+@source "../../../packages/charts/src/**/*.{ts,tsx}";@layer base {* {diff --git a/packages/quill/packages/charts/src/README.md b/packages/quill/packages/charts/src/README.mdindex 6f18cdc14257..a90fd49490fd 100644--- a/packages/quill/packages/charts/src/README.md+++ b/packages/quill/packages/charts/src/README.md@@ -13,6 +13,17 @@ const THEME: ChartTheme = { colors: ['#1f77b4'], backgroundColor: '#ffffff' };<LineChart series={SERIES} labels={LABELS} theme={THEME} />```+## Setup++**Tokens (optional but recommended)** — load `@posthog/quill-tokens/color-system.css`+so `useChartTheme()` resolves the real quill palette and chrome. Without it you get+a sensible built-in fallback palette (see below), not the brand colors.++The built-in tooltip styles itself inline, so it renders correctly with no extra+setup. The rest of the library's chrome uses Tailwind utility classes — if you want+those generated for a non-PostHog host, add this package to your Tailwind+`@source`/content globs.+## ThemeCharts are **headless about color** — every chart takes a `ChartTheme` (`colors`diff --git a/packages/quill/packages/charts/src/charts/BoxPlot/BoxPlotTooltip.tsx b/packages/quill/packages/charts/src/charts/BoxPlot/BoxPlotTooltip.tsxindex a46a9422d1c4..21549865bd43 100644--- a/packages/quill/packages/charts/src/charts/BoxPlot/BoxPlotTooltip.tsx+++ b/packages/quill/packages/charts/src/charts/BoxPlot/BoxPlotTooltip.tsx@@ -1,13 +1,10 @@import React from 'react'-import { useChartLayout } from '../../core/chart-context'import type { TooltipContext } from '../../core/types'+import { TooltipSurface, TooltipSwatch } from '../../overlays/TooltipSurface'import type { BoxPlotAdaptedMeta } from './BoxPlot'import type { BoxPlotDatum } from './computeBoxLayout'-const DEFAULT_TOOLTIP_BG = '#1d2330'-const DEFAULT_TOOLTIP_COLOR = '#ffffff'-/** Rows shown per box, in the same order the legacy BoxPlotChart used. */const ROWS: { label: string; key: keyof BoxPlotDatum }[] = [{ label: 'Max', key: 'max' },@@ -38,8 +35,6 @@ export function BoxPlotTooltip<Meta = unknown>({userTooltip,grouped,}: BoxPlotTooltipProps<Meta>): React.ReactElement | null {- const { theme } = useChartLayout()-if (userTooltip) {return <>{userTooltip(ctx)}</>}@@ -65,25 +60,13 @@ export function BoxPlotTooltip<Meta = unknown>({}return (- <div- className="px-3 py-2 rounded-lg shadow-lg text-[13px]"- // eslint-disable-next-line react/forbid-dom-props- style={{- backgroundColor: theme.tooltipBackground ?? DEFAULT_TOOLTIP_BG,- color: theme.tooltipColor ?? DEFAULT_TOOLTIP_COLOR,- }}- data-attr="hog-chart-boxplot-tooltip"- >+ <TooltipSurface data-attr="hog-chart-boxplot-tooltip"><div className="font-semibold mb-1">{ctx.label}</div>{entries.map((entry, i) => (<div key={entry.key} className={i > 0 ? 'mt-2' : undefined}>{grouped && (<div className="flex items-center gap-2 mb-1">- <span- className="inline-block size-2 rounded-full"- // eslint-disable-next-line react/forbid-dom-props- style={{ backgroundColor: entry.color }}- />+ <TooltipSwatch color={entry.color} /><span className="font-semibold">{entry.label}</span></div>)}@@ -101,6 +84,6 @@ export function BoxPlotTooltip<Meta = unknown>({</table></div>))}- </div>+ </TooltipSurface>)}diff --git a/packages/quill/packages/charts/src/charts/PieChart/PieTooltip.tsx b/packages/quill/packages/charts/src/charts/PieChart/PieTooltip.tsxindex 055e7d97d326..54bfb731ee15 100644--- a/packages/quill/packages/charts/src/charts/PieChart/PieTooltip.tsx+++ b/packages/quill/packages/charts/src/charts/PieChart/PieTooltip.tsx@@ -1,7 +1,7 @@import React from 'react'-import { useChartLayout } from '../../core/chart-context'import type { TooltipContext } from '../../core/types'+import { TooltipSurface, TooltipSwatch } from '../../overlays/TooltipSurface'export interface PieTooltipProps<Meta> {ctx: TooltipContext<Meta>@@ -9,9 +9,6 @@ export interface PieTooltipProps<Meta> {isPercent?: boolean}-const DEFAULT_TOOLTIP_BG = '#1d2330'-const DEFAULT_TOOLTIP_COLOR = '#ffffff'-function defaultFormatter(v: number): string {return v.toLocaleString()}@@ -25,7 +22,6 @@ export function PieTooltip<Meta>({valueFormatter = defaultFormatter,isPercent = false,}: PieTooltipProps<Meta>): React.ReactElement | null {- const { theme } = useChartLayout()const entry = ctx.seriesData[0]if (!entry) {return null@@ -33,26 +29,15 @@ export function PieTooltip<Meta>({const share = entry.fraction ?? 0return (- <div- className="px-3 py-2 rounded-lg shadow-lg text-[13px]"- // eslint-disable-next-line react/forbid-dom-props- style={{- backgroundColor: theme.tooltipBackground ?? DEFAULT_TOOLTIP_BG,- color: theme.tooltipColor ?? DEFAULT_TOOLTIP_COLOR,- }}- >+ <TooltipSurface><div className="flex items-center gap-2 mb-1">- <span- className="inline-block size-2 rounded-full"- // eslint-disable-next-line react/forbid-dom-props- style={{ backgroundColor: entry.color }}- />+ <TooltipSwatch color={entry.color} /><span className="font-semibold">{entry.series.label}</span></div><div className="flex items-center gap-2"><strong>{isPercent ? formatPercent(share) : valueFormatter(entry.value)}</strong>{!isPercent && share > 0 ? <span className="opacity-70">({formatPercent(share)})</span> : null}</div>- </div>+ </TooltipSurface>)}diff --git a/packages/quill/packages/charts/src/core/theme.test.ts b/packages/quill/packages/charts/src/core/theme.test.tsindex 84c245bb679c..7a77bd58ae7b 100644--- a/packages/quill/packages/charts/src/core/theme.test.ts+++ b/packages/quill/packages/charts/src/core/theme.test.ts@@ -56,6 +56,15 @@ describe('chart theme', () => {expect(themeFromCssVars({ root }).backgroundColor).toBe(expected)})+ it('maps the tooltip to quill inverse surface tokens', () => {+ const root = rootWithVars({ '--foreground': '#0b0b0b', '--background': '#fafafa' })++ const theme = themeFromCssVars({ root })++ expect(theme.tooltipBackground).toBe('#0b0b0b')+ expect(theme.tooltipColor).toBe('#fafafa')+ })+it('falls back to DEFAULT_CHART_COLORS for unset color vars', () => {const root = rootWithVars({})diff --git a/packages/quill/packages/charts/src/core/theme.ts b/packages/quill/packages/charts/src/core/theme.tsindex 2d8c7f98ac44..8bb6adff397d 100644--- a/packages/quill/packages/charts/src/core/theme.ts+++ b/packages/quill/packages/charts/src/core/theme.ts@@ -78,8 +78,10 @@ export function themeFromCssVars(options: ThemeFromCssOptions = {}): ChartThemeaxisColor: 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'),+ // quill's tooltip is an inverse panel (`.quill-tooltip__content`):+ // foreground-colored surface, background-colored text.+ tooltipBackground: readCssVar(style, '--foreground') ?? readCssVar(style, '--color-bg-surface-tooltip'),+ tooltipColor: readCssVar(style, '--background') ?? readCssVar(style, '--color-text-primary-inverse'),}}diff --git a/packages/quill/packages/charts/src/index.ts b/packages/quill/packages/charts/src/index.tsindex b4a81ec16644..d6209cb9de64 100644--- a/packages/quill/packages/charts/src/index.ts+++ b/packages/quill/packages/charts/src/index.ts@@ -87,6 +87,8 @@ export type { ThemeFromCssOptions } from './core/theme'// Built-in tooltip (for reference or extension)export { DefaultTooltip } from './overlays/DefaultTooltip'+// Shared tooltip surface — reuse to build custom tooltips with the quill look+export { TooltipSurface, TooltipSwatch, TOOLTIP_FALLBACK_BG, TOOLTIP_FALLBACK_COLOR } from './overlays/TooltipSurface'// Optional overlaysexport { ReferenceLine, ReferenceLines } from './overlays/ReferenceLine'diff --git a/packages/quill/packages/charts/src/overlays/DefaultTooltip.tsx b/packages/quill/packages/charts/src/overlays/DefaultTooltip.tsxindex 59ad3b18d242..28a136b3f6aa 100644--- a/packages/quill/packages/charts/src/overlays/DefaultTooltip.tsx+++ b/packages/quill/packages/charts/src/overlays/DefaultTooltip.tsx@@ -1,32 +1,17 @@-import { useChartLayout } from '../core/chart-context'import type { TooltipContext } from '../core/types'--const DEFAULT_TOOLTIP_BG = '#1d2330'-const DEFAULT_TOOLTIP_COLOR = '#ffffff'+import { TooltipSurface, TooltipSwatch } from './TooltipSurface'export function DefaultTooltip({ label, seriesData }: TooltipContext): React.ReactElement {- const { theme } = useChartLayout()return (- <div- className="px-3 py-2 rounded-lg shadow-lg text-[13px]"- // eslint-disable-next-line react/forbid-dom-props- style={{- backgroundColor: theme.tooltipBackground ?? DEFAULT_TOOLTIP_BG,- color: theme.tooltipColor ?? DEFAULT_TOOLTIP_COLOR,- }}- >+ <TooltipSurface><div className="font-semibold mb-1">{label}</div>{seriesData.map((s) => (<div key={s.series.key} className="flex items-center gap-2">- <span- className="inline-block size-2 rounded-full"- // eslint-disable-next-line react/forbid-dom-props- style={{ backgroundColor: s.color }}- />+ <TooltipSwatch color={s.color} /><span>{s.series.label}:</span><strong>{s.value.toLocaleString()}</strong></div>))}- </div>+ </TooltipSurface>)}diff --git a/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx b/packages/quill/packages/charts/src/overlays/ReferenceLine.tsxindex 0cf70ab48b70..a2e746cac467 100644--- a/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx+++ b/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx@@ -2,6 +2,7 @@import React, { useMemo } from 'react'import { useChartLayout } from '../core/chart-context'+import { TOOLTIP_FALLBACK_BG, TOOLTIP_FALLBACK_COLOR } from './TooltipSurface'export type ReferenceLineOrientation = 'horizontal' | 'vertical'export type ReferenceLineVariant = 'goal' | 'alert' | 'marker'@@ -65,11 +66,6 @@ const LABEL_HEIGHT = 20/** Padding between the label and the plot edge. */const LABEL_PADDING = 4-// Match the chart tooltip look (see DefaultTooltip) so the label bubble reads as part of the-// chart's own theming rather than depending on the host app's CSS variables.-const DEFAULT_TOOLTIP_BG = '#1d2330'-const DEFAULT_TOOLTIP_COLOR = '#ffffff'-function resolveStyle(variant: ReferenceLineVariant, style: ReferenceLineStyle | undefined): ResolvedStyle {const defaults = VARIANT_DEFAULTS[variant]return {@@ -309,8 +305,8 @@ function ReferenceLineView({const { theme } = useChartLayout()const resolvedLabelStyle: React.CSSProperties = {...labelStyle,- backgroundColor: theme.tooltipBackground ?? DEFAULT_TOOLTIP_BG,- color: theme.tooltipColor ?? DEFAULT_TOOLTIP_COLOR,+ backgroundColor: theme.tooltipBackground ?? TOOLTIP_FALLBACK_BG,+ color: theme.tooltipColor ?? TOOLTIP_FALLBACK_COLOR,}return (<>diff --git a/packages/quill/packages/charts/src/overlays/TooltipSurface.tsx b/packages/quill/packages/charts/src/overlays/TooltipSurface.tsxnew file mode 100644index 000000000000..f7ec378bcef3--- /dev/null+++ b/packages/quill/packages/charts/src/overlays/TooltipSurface.tsx@@ -0,0 +1,74 @@+import React from 'react'++import { useChartLayout } from '../core/chart-context'++/**+ * Fallback tooltip colors for hosts that don't supply them on `ChartTheme`.+ * An inverse panel (dark surface, light text), matching quill's tooltip — when+ * the quill theme reader is used these come from `--foreground` / `--background`.+ */+export const TOOLTIP_FALLBACK_BG = '#1d2330'+export const TOOLTIP_FALLBACK_COLOR = '#ffffff'++interface TooltipSurfaceProps {+ children: React.ReactNode+ className?: string+ /** Forwarded onto the panel — used for test/automation selectors. */+ 'data-attr'?: string+}++/**+ * Shared surface for the built-in chart tooltips. Geometry mirrors quill's+ * tooltip (`.quill-tooltip__content`: inverse panel, `radius-sm`, compact+ * padding, `text-xs`) but is applied inline — no shipped stylesheet, no Tailwind+ * scan needed, so the floating panel renders correctly regardless of the+ * consumer's setup. Dimensions reference quill token vars with literal+ * fallbacks; colors stay theme-driven so non-quill hosts can restyle.+ */+export function TooltipSurface({+ children,+ className,+ 'data-attr': dataAttr,+}: TooltipSurfaceProps): React.ReactElement {+ const { theme } = useChartLayout()+ return (+ <div+ className={className}+ data-attr={dataAttr}+ // eslint-disable-next-line react/forbid-dom-props+ style={{+ width: 'fit-content',+ maxWidth: '20rem',+ paddingBlock: '0.375rem',+ paddingInline: '0.75rem',+ fontSize: 'var(--text-xs, 0.75rem)',+ lineHeight: 1.4,+ borderRadius: 'var(--radius-sm, 0.375rem)',+ // Soft float shadow for separation over dense chart data — the+ // one intentional addition over quill's flat in-page tooltip.+ boxShadow: '0 2px 8px rgb(0 0 0 / 18%)',+ backgroundColor: theme.tooltipBackground ?? TOOLTIP_FALLBACK_BG,+ color: theme.tooltipColor ?? TOOLTIP_FALLBACK_COLOR,+ }}+ >+ {children}+ </div>+ )+}++/** Round series-color swatch used in tooltip rows. */+export function TooltipSwatch({ color }: { color: string }): React.ReactElement {+ return (+ <span+ // eslint-disable-next-line react/forbid-dom-props+ style={{+ display: 'inline-block',+ flex: 'none',+ width: '0.5rem',+ height: '0.5rem',+ borderRadius: '9999px',+ backgroundColor: color,+ }}+ />+ )+}diff --git a/packages/quill/packages/tokens/package.json b/packages/quill/packages/tokens/package.jsonindex e245f4d6ce4b..a0d08e761d91 100644--- a/packages/quill/packages/tokens/package.json+++ b/packages/quill/packages/tokens/package.json@@ -14,10 +14,10 @@"type": "module","main": "./dist/index.cjs","module": "./dist/index.js",- "types": "./dist/index.d.ts",+ "types": "./dist/src/index.d.ts","exports": {".": {- "types": "./dist/index.d.ts",+ "types": "./dist/src/index.d.ts","import": "./dist/index.js","require": "./dist/index.cjs","default": "./dist/index.js"