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.

chore(quill): show a threshold-colored headline on the composable metric (#127416)

Sam Pennington8f3789a17815
diff --git a/packages/quill/packages/components/AGENTS.md b/packages/quill/packages/components/AGENTS.md
index f094aa8de291..7e6ebeb19dd6 100644
--- a/packages/quill/packages/components/AGENTS.md
+++ b/packages/quill/packages/components/AGENTS.md
@@ -140,6 +140,7 @@ Rules:
- The root owns the data/hover behavior and feeds the parts via context — a part used outside `<Metric>` throws. Pass `value` for a number-only tile; pass `data`+`labels`+`theme` for a sparkline.
- `labels` doubles as the sparkline's x-scale keys, so entries must be **unique** — a duplicate collapses two points onto one position and draws the series backwards (see the charts guide's `labels` rule). Pass raw keys (ISO dates) and render them for display with `formatLabel`, instead of pre-formatting text like `'June 16'`, which repeats once a range spans a year. `formatLabel` covers the subtitle; a `sparklineTooltip` formats the same keys through the charts' own `labelFormatter`.
- `MetricDelta` renders a `Badge`; `goodDirection` (default `up`) decides success vs destructive. It carries its own `TooltipProvider`, so `changeTooltip` needs no app-root setup. resize via `className` (the metric insight passes its own larger-pill classes and puts it inline next to the headline via `MetricHeader`; there is no `changeInline` or size prop, compose and style at the call site).
+- Color the headline at the call site: `<MetricValue style={{ color }} />` for a dynamic color (a threshold status), or a `text-*` class for a token. The root `color` tints only the sparkline.
- Reproduces `MetricCard`'s behavior (`restingSubtitle`, `hoverChangeFromPreviousPoint`, `changeTooltip`, `positiveColor`/`negativeColor` for user-configured pill colors); omit the color props to keep the semantic `Badge` variants.
- `series` draws a multi-series sparkline (one line per series, the charts' `Series[]` shape) instead of the single `data` line. It's purely visual — the headline, hover and change pill still read `data`, so pass the numbers the tile should read (e.g. the per-index totals) as `data` alongside it; the types reject `series` without `data`. The single-line conveniences (`color`, `sparklineDashedFromIndex`) don't apply — set them per series.
- `sparklineTooltip` is a render prop passed straight to the sparkline (off by default, since hover already scrubs the headline) — supply `(ctx) => <DefaultTooltip {...ctx} />` to also show a hover tooltip, e.g. the per-series breakdown behind a multi-series total.
diff --git a/packages/quill/packages/components/src/metric.stories.tsx b/packages/quill/packages/components/src/metric.stories.tsx
index 98babc420c88..5779b0745121 100644
--- a/packages/quill/packages/components/src/metric.stories.tsx
+++ b/packages/quill/packages/components/src/metric.stories.tsx
@@ -172,6 +172,35 @@ export const RestingSummary: Story = {
},
}
+// A status tile: `MetricValue` takes `style` (or a `text-*` color class), so a threshold color tints the
+// headline without a root prop. `color` tints only the sparkline.
+export const ValueColor: Story = {
+ render: () => {
+ const theme = useChartTheme()
+ return (
+ <Card flush className="h-[320px] w-[360px]">
+ <Metric
+ data={[0.8, 1.1, 0.9, 1.6, 2.4, 3.1, 4.2]}
+ labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']}
+ theme={theme}
+ color="#f04438"
+ goodDirection="down"
+ sparklineFill
+ formatValue={(v) => `${v.toFixed(1)}%`}
+ >
+ <MetricHeader>
+ <MetricTitle>Error rate</MetricTitle>
+ <MetricDelta />
+ </MetricHeader>
+ <MetricValue className="mt-2" style={{ color: '#f04438' }} />
+ <MetricSubtitle className="mt-1" />
+ <MetricSparkline />
+ </Metric>
+ </Card>
+ )
+ },
+}
+
// `changeTooltip` spells out the comparison on hover (needs a `TooltipProvider` at the app root —
// supplied here by the story decorator).
export const WithTooltip: Story = {