PeakUIPro

ChartTooltip

Tooltip card for a chart data point

Usage

import {ChartTooltip} from "@peakui-pro/react";

Anatomy

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>
);

Examples

Line Indicator

indicator is set on the root and reaches every indicator in the card.

No Header

Chart Colors

--chart-1 to --chart-5 are derived from the theme's accent, darkest to lightest.

Auto Content

ChartTooltip.Content turns a chart's payload into the card.

Custom Formatters

Inactive

Customization

Tailwind CSS

<ChartTooltip className="min-w-40">...</ChartTooltip>

Global CSS

@layer components {
  .chart-tooltip {
    --chart-tooltip-gap: calc(var(--spacing) * 2);
    --chart-tooltip-indicator-size: calc(var(--spacing) * 2.5);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The ChartTooltip component uses these CSS classes (view source styles):

Base Classes

  • .chart-tooltip - The card; a column on the surface colour, with the surface shadow

Element Classes

  • .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

Indicator Classes

  • .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

Slots

  • [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

CSS Variables

VariablePurpose
--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

API Reference

ChartTooltip

PropTypeDefaultDescription
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

ChartTooltip.Content

PropTypeDefaultDescription
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

ChartTooltip.Header

PropTypeDefaultDescription
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

ChartTooltip.Item

PropTypeDefaultDescription
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

ChartTooltip.Indicator

PropTypeDefaultDescription
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

ChartTooltip.Label

PropTypeDefaultDescription
childrenReactNode-The series name
classNamestring-Additional classes
renderDOMRenderFunction<'span', undefined>-Replaces the rendered <span> with your own element
...restComponentProps<'span'>-Native <span> attributes

ChartTooltip.Value

PropTypeDefaultDescription
childrenReactNode-The series value
classNamestring-Additional classes
renderDOMRenderFunction<'span', undefined>-Replaces the rendered <span> with your own element
...restComponentProps<'span'>-Native <span> attributes

ChartTooltipPayloadEntry

FieldTypeDescription
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

On this page