Tooltip card for a chart data point
import {ChartTooltip} from "@peakui-pro/react" ;
import {ChartTooltip} from "@peakui-pro/react" ;
// The card imports nothing from a chart library, so it ships from the package root.
// `Content` is the adapter a chart passes as its tooltip's `content`; the parts below
// stay usable on their own.
export default () => (
< ChartTooltip >
< ChartTooltip.Header />
< ChartTooltip.Item >
< ChartTooltip.Indicator />
< ChartTooltip.Label />
< ChartTooltip.Value />
</ ChartTooltip.Item >
</ ChartTooltip >
);
indicator is set on the root and reaches every indicator in the card.
--chart-1 to --chart-5 are derived from the theme's accent, darkest to lightest.
ChartTooltip.Content turns a chart's payload into the card.
< ChartTooltip className = "min-w-40" >...</ ChartTooltip >
@layer components {
.chart-tooltip {
--chart-tooltip-gap : calc ( var ( --spacing ) * 2 );
--chart-tooltip-indicator-size : calc ( var ( --spacing ) * 2.5 );
}
}
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
The ChartTooltip component uses these CSS classes (view source styles ):
.chart-tooltip - The card; a column on the surface colour, with the surface shadow
.chart-tooltip__header - The hovered point's own label
.chart-tooltip__item - One series row
.chart-tooltip__label - The series name; takes the slack so every value ends on one edge
.chart-tooltip__value - The series value; tabular numerals
.chart-tooltip__indicator - The colour marker; its colour is written inline from the series
.chart-tooltip__indicator--dot - A round dot
.chart-tooltip__indicator--line - A segment of the series line, stood on end
[data-slot="chart-tooltip"] - The card
[data-slot="chart-tooltip-header"] - The header
[data-slot="chart-tooltip-item"] - A series row
[data-slot="chart-tooltip-indicator"] - The colour marker
[data-slot="chart-tooltip-label"] - The series name
[data-slot="chart-tooltip-value"] - The series value
Variable Purpose --chart-tooltip-gapSpace between the header and the rows, and between rows --chart-tooltip-indicator-sizeThe dot's box; the line is half as wide and half again as tall
Prop Type Default Description activebooleantrueWhether the card is shown. false renders nothing indicator'dot' | 'line''dot'Shape of the colour marker; shared with every part through context childrenReactNode- The parts classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes
Prop Type Default Description activeboolean- The chart passes this: whether the pointer is over a point labelstring | number- The chart passes this: the hovered point's label payloadreadonly ChartTooltipPayloadEntry[]- The chart passes this: one entry per series at the hovered point hideHeaderbooleanfalseLeaves out the label row indicator'dot' | 'line''dot'Shape of the colour marker labelFormatter(label: string | number) => ReactNode- Formats the header's label valueFormatter(value: string | number) => ReactNode- Formats each value; a range series is formatted end by end, then joined
Prop Type Default Description childrenReactNode- The hovered point's label classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes
Prop Type Default Description childrenReactNode- Typically an indicator, a label and a value classNamestring- Additional classes renderDOMRenderFunction<'div', undefined>- Replaces the rendered <div> with your own element ...restComponentProps<'div'>- Native <div> attributes
Prop Type Default Description colorstring- The series' colour, written as the element's inline background. Any CSS colour, including a var() from the chart ramp classNamestring- Additional classes renderDOMRenderFunction<'span', undefined>- Replaces the rendered <span> with your own element ...restComponentProps<'span'>- Native <span> attributes; a style of your own wins over color
Prop Type Default Description childrenReactNode- The series name classNamestring- Additional classes renderDOMRenderFunction<'span', undefined>- Replaces the rendered <span> with your own element ...restComponentProps<'span'>- Native <span> attributes
Prop Type Default Description childrenReactNode- The series value classNamestring- Additional classes renderDOMRenderFunction<'span', undefined>- Replaces the rendered <span> with your own element ...restComponentProps<'span'>- Native <span> attributes
Field Type Description namestring | numberThe series name; the card falls back to dataKey valuestring | number | readonly (string | number)[]The value at the hovered point; an array is a range colorstringThe series colour dataKeystring | numberThe field the series reads payloadunknownThe whole data point the entry came from