Components
Chart Tooltip
A caption over a value, with a tail pointing down at what it describes. The chart components render it on hover; use it directly when you build a custom chart.
Installation
bunx @happlyui/cli@latest add chart-tooltip
Dependencies
Registry dependencies
These are automatically installed when you add this component.
happly-ui-utils
Usage
import * as ChartTooltip from "@/components/ui/chart-tooltip"
<ChartTooltip.Root caption="10 - 19 Group">
<ChartTooltip.Value>168</ChartTooltip.Value>
<ChartTooltip.Unit>Items</ChartTooltip.Unit>
</ChartTooltip.Root>
Examples
With unit
A caption, a value and what the value counts. The bar chart and the donut use this shape.
10 - 19 Group
<ChartTooltip.Root caption="10 - 19 Group">
<ChartTooltip.Value>168</ChartTooltip.Value>
<ChartTooltip.Unit>Items</ChartTooltip.Unit>
</ChartTooltip.Root>
Without unit
Leave the unit out when the card title already names what's being counted.
Tue, Aug 12
<ChartTooltip.Root caption="Tue, Aug 12">
<ChartTooltip.Value>1,284</ChartTooltip.Value>
</ChartTooltip.Root>
With change
Add a Delta after the value to show its change, and what the change is measured against. The line chart uses this shape.
Tue, Aug 12
<ChartTooltip.Root caption="Tue, Aug 12">
<ChartTooltip.Value>1,284</ChartTooltip.Value>
<ChartTooltip.Delta value={4.2}>vs prev.</ChartTooltip.Delta>
</ChartTooltip.Root>
API Reference
ChartTooltip.Root
The box and its tail. Position it above the anchor; it ignores the pointer so it never steals hover.
| Prop | Type | Default | Description |
|---|---|---|---|
caption | ReactNode | - | The muted line above the value |
tailOffset | number | 0 | Px to slide the tail off-centre, when the box is shifted off its anchor (e.g. clamped inside the chart) |
ChartTooltip.Value
The figure, in tabular numerals.
| Prop | Type | Default | Description |
|---|
ChartTooltip.Unit
What the figure counts, beside it.
| Prop | Type | Default | Description |
|---|
ChartTooltip.Delta
A change beside the figure, green when it is zero or up and red when down. Children name what it is measured against.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | - | The change in percent: 100 reads "+100.0%" |