: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
feat(quill-charts): render the tooltip surface outside a chart (#120698)
Sam Penningtone139c85e7883
diff --git a/packages/quill/packages/charts/src/docs/tooltips.md b/packages/quill/packages/charts/src/docs/tooltips.mdindex 6b6c8952429a..a01c0ca1dbb3 100644--- a/packages/quill/packages/charts/src/docs/tooltips.md+++ b/packages/quill/packages/charts/src/docs/tooltips.md@@ -44,6 +44,9 @@ A render prop that is not a list of series rows composes the exported pieces so- `TooltipSwatch` is the series-color dot.- `TooltipFooter` is the divider plus muted row, the same slot `DefaultTooltip.footer` renders into.+These pieces also render outside a chart, so a custom d3 or SVG chart can show the same tooltip.+Outside a chart, `TooltipSurface` takes its colors from the `--card` and `--foreground` tokens, the same ones `useChartTheme()` reads.+## Reading `TooltipContext`- `seriesData` holds one entry per visible series at `dataIndex`, in declaration order. Series with `visibility.tooltip: false` are absent. Look rows up by `entry.series.key`, not by position.diff --git a/packages/quill/packages/charts/src/overlays/DefaultTooltip.test.tsx b/packages/quill/packages/charts/src/overlays/DefaultTooltip.test.tsxindex c7c6345ad07b..cc3c03a31a08 100644--- a/packages/quill/packages/charts/src/overlays/DefaultTooltip.test.tsx+++ b/packages/quill/packages/charts/src/overlays/DefaultTooltip.test.tsx@@ -1,8 +1,9 @@-import { cleanup, fireEvent, screen } from '@testing-library/react'+import { cleanup, fireEvent, render, screen } from '@testing-library/react'import type { TooltipContext } from '../core/types'import { createDefaultTooltipAccessor, makeOverlayContext, renderOverlayInChart } from '../testing'import { DefaultTooltip } from './DefaultTooltip'+import { TooltipSurface } from './TooltipSurface'const SCALES = { x: () => 0, y: (v: number) => v, yTicks: () => [] }@@ -49,6 +50,11 @@ describe('DefaultTooltip', () => {screen.getByText((19402).toLocaleString())})+ it('renders TooltipSurface outside a chart', () => {+ render(<TooltipSurface>Outside a chart</TooltipSurface>)+ screen.getByText('Outside a chart')+ })+it('formats values with custom valueFormatter', () => {renderTooltip({ valueFormatter: (v: number) => `${v}ms` })screen.getByText('19402ms')diff --git a/packages/quill/packages/charts/src/overlays/TooltipSurface.tsx b/packages/quill/packages/charts/src/overlays/TooltipSurface.tsxindex 1aa9ec187842..f2235e1c7905 100644--- a/packages/quill/packages/charts/src/overlays/TooltipSurface.tsx+++ b/packages/quill/packages/charts/src/overlays/TooltipSurface.tsx@@ -1,11 +1,15 @@-import React from 'react'+import React, { useContext } from 'react'-import { useChartLayout } from '../core/chart-context'+import { ChartLayoutContext } from '../core/chart-context'// Fallback colors for non-quill hosts; quill hosts get --card / --foreground from the theme reader.export const TOOLTIP_FALLBACK_BG = '#1d2330'export const TOOLTIP_FALLBACK_COLOR = '#ffffff'+// Outside a chart there is no theme, so read the same tokens the theme reader does.+const STANDALONE_BG = `var(--card, var(--color-bg-surface-popover, ${TOOLTIP_FALLBACK_BG}))`+const STANDALONE_COLOR = `var(--foreground, var(--color-text-primary, ${TOOLTIP_FALLBACK_COLOR}))`+interface TooltipSurfaceProps {children: React.ReactNodeclassName?: string@@ -19,7 +23,7 @@ export function TooltipSurface({className,'data-attr': dataAttr,}: TooltipSurfaceProps): React.ReactElement {- const { theme } = useChartLayout()+ const theme = useContext(ChartLayoutContext)?.themereturn (<divclassName={className}@@ -37,8 +41,8 @@ export function TooltipSurface({// one intentional addition over quill's flat in-page tooltip.border: '1px solid rgba(255, 255, 255, 0.1)',boxShadow: '0 4px 16px rgb(0 0 0 / 40%)',- backgroundColor: theme.tooltipBackground ?? TOOLTIP_FALLBACK_BG,- color: theme.tooltipColor ?? TOOLTIP_FALLBACK_COLOR,+ backgroundColor: theme ? (theme.tooltipBackground ?? TOOLTIP_FALLBACK_BG) : STANDALONE_BG,+ color: theme ? (theme.tooltipColor ?? TOOLTIP_FALLBACK_COLOR) : STANDALONE_COLOR,}}>{children}