Charts
Token-themed data visualisations — the core multi-series chart plus dependency-free SVG variants for sankey, word-cloud, venn and violin plots.
Preview
March
<div class="flex flex-wrap items-start justify-center gap-8">
<x-ui.chart-tooltip
:title="__('March')"
:items="[
['label' => __('Revenue'), 'value' => '$48.2k', 'color' => 'chart-1'],
['label' => __('Costs'), 'value' => '$21.7k', 'color' => 'chart-2'],
]"
/>
<x-ui.chart-tooltip :items="[['label' => __('Organic → Signups'), 'value' => '35']]" />
</div>
Installation
php artisan ui:add chart-tooltip
Registry contract
php artisan ui:add chart-tooltip
writes only the files below. The CLI validates each file hash before writing and asks before it replaces a local change, unless you pass --force.
-
resources/views/components/ui/chart-tooltip.blade.php
- Registry dependencies
- None — installs on its own.
- Packages
-
composer: jml/brok:^0.2
Use with AI
A brief for your coding agent: install command, usage, props, guidance and the rules. Copy it, or open a prompt about this component in an assistant.
# Brok UI: Chart Tooltip (`chart-tooltip`)
The one tooltip surface every chart shares: a popover with an optional title and swatch/label/value rows, positioned by the SVG charts with Alpine and rendered by the ApexCharts wrapper's custom tooltip.
Brok UI is a Laravel Blade component registry. Installed components are plain Blade files the app owns.
## Install
```bash
php artisan ui:add chart-tooltip
```
## Usage
```blade
<div class="flex flex-wrap items-start justify-center gap-8">
<x-ui.chart-tooltip
:title="__('March')"
:items="[
['label' => __('Revenue'), 'value' => '$48.2k', 'color' => 'chart-1'],
['label' => __('Costs'), 'value' => '$21.7k', 'color' => 'chart-2'],
]"
/>
<x-ui.chart-tooltip :items="[['label' => __('Organic → Signups'), 'value' => '35']]" />
</div>
```
## Props
- `title` (mixed|null, default `null`) — Optional heading, such as a category or date, shown above the rows.
- `items` (array, default `[]`) — Rows to render: each an object with label, value, and an optional color (a chart-N token or class).
## Use when
- Use when trend, distribution, flow, intensity, or relationship questions are easier to answer visually than in raw numbers.
- Building a custom SVG chart (sankey, venn, network, and so on) that needs the same pointer tooltip surface every other chart uses.
- Overriding ApexCharts' default tooltip via its tooltip.custom hook while keeping the token-themed look consistent.
## Avoid when
- Do not use a chart when users mainly need exact lookup or when a single metric would be clearer as text or a stat.
- ApexCharts' built-in tooltip already covers the need; only override it when custom rows or a title are required.
- A persistent, non-pointer-following key to the chart's colours; use chart-legend instead.
## Anti-patterns
- Decorative charts without a meaningful question
## Rules
- Use the `<brok:chart-tooltip>` tag (or `<x-ui.chart-tooltip>`) in Blade; do not rewrite the component.
- Prefer the documented props and variants over utility-class overrides; when a utility must win, use the `!` important modifier.
- Use semantic design tokens (`bg-primary`, `text-muted-foreground`), never raw colour utilities.
- Keep the `data-slot` attributes; they are the styling and test hooks.
## Links
- Docs: https://brokui.dev/docs/components/chart-tooltip
- Registry JSON (files, props, contract): https://brokui.dev/r/open/chart-tooltip.json
Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| title | mixed | null | null | Optional heading, such as a category or date, shown above the rows. |
| items | array | [] | Rows to render: each an object with label, value, and an optional color (a chart-N token or class). |
Slots
default— Alpine-bound content (x-text) for callers that build rows dynamically instead of passing items.
Data slots
Stable hooks for CSS overrides and browser tests.
Behavior
- Never receives pointer events itself (role="presentation", pointer-events-none in the SVG usage) so it never blocks interaction with the chart underneath.
- The same markup is shared by the SVG charts' Alpine positioning and the ApexCharts wrapper's tooltip.custom hook, so both stay visually identical.
- Declares registry capability flags: a11y, responsive, rtl, darkMode, localized.
Guidance
Reveal a visual trend, distribution, flow, or relationship.
Use when
- Use when trend, distribution, flow, intensity, or relationship questions are easier to answer visually than in raw numbers.
- Building a custom SVG chart (sankey, venn, network, and so on) that needs the same pointer tooltip surface every other chart uses.
- Overriding ApexCharts' default tooltip via its tooltip.custom hook while keeping the token-themed look consistent.
Avoid when
- Do not use a chart when users mainly need exact lookup or when a single metric would be clearer as text or a stat.
- ApexCharts' built-in tooltip already covers the need; only override it when custom rows or a title are required.
- A persistent, non-pointer-following key to the chart's colours; use chart-legend instead.
Use instead
- Table for exact lookup
- Stat for a single value
Anti-patterns
- Decorative charts without a meaningful question
- Anatomy
- Theming hooks
Accessibility
- Keyboard
- No component-owned keyboard interaction; native element behavior applies.
- Focus
none
- role="presentation" keeps the floating tooltip out of the accessibility tree; the underlying chart data must stay available another way, such as a table or chart-legend.
- pointer-events-none ensures the tooltip never traps focus or blocks a click on the chart under the pointer.
- Semantic HTML and a stable
data-slotattribute for styling and scripting hooks. - Focus-visible rings use the
ringtoken, so keyboard focus is always visible. - Disabled and invalid states are conveyed to assistive tech, not by color alone.
- Targets WCAG 2.2 AA; verify contrast in light, dark, admin and customer surfaces in the preview.
- Labels go through
__()and layout uses logical properties (ms-*,text-start), so it mirrors underdir="rtl"— flip the preview to RTL to confirm. - Dark mode uses the same semantic tokens under the
darkclass; high contrast follows forced-color system tokens.
Livewire
Livewire can update this component through forwarded wire:* attributes.
Source
The exact, editable file ui:add writes
into your app. Previews render this same code; there are no preview-only components.
@props([
// Optional heading (a category, a date) above the rows.
'title' => null,
// Rows: each ['label' => string, 'value' => string, 'color' => 'chart-1'|token class|null].
// Leave empty and use the slot for Alpine-bound content (`x-text`).
'items' => [],
])
@php
// Swatch colours are fixed utilities (JIT-visible): the neutral chart hues
// plus the status tokens, shared with chart-legend and partition-bar.
// Anything else is used as a class as-is.
$styles = require base_path(config('ui.component_path', 'resources/views/components/ui').'/_styles.php');
$swatches = $styles['chart']['swatches'];
@endphp
{{-- The one tooltip surface every chart shares — the SVG charts position it
with Alpine, the ApexCharts wrapper renders the same markup from its
`tooltip.custom` hook. Keep the classes here and there in step. --}}
<div
data-slot="chart-tooltip"
role="presentation"
{{ $attributes->merge(['class' => 'pointer-events-none z-10 min-w-32 rounded-md border border-border bg-popover px-3 py-2 text-xs text-popover-foreground shadow-md']) }}
>
@if ($title !== null)
<p data-slot="chart-tooltip-title" class="mb-1 font-medium text-muted-foreground">{{ $title }}</p>
@endif
@foreach ($items as $item)
<div data-slot="chart-tooltip-row" class="flex items-center justify-between gap-4">
<span class="flex items-center gap-2">
@if (! empty($item['color']))
<span aria-hidden="true" class="size-2 shrink-0 rounded-full {{ $swatches[$item['color']] ?? $item['color'] }}"></span>
@endif
<span class="text-muted-foreground">{{ $item['label'] ?? '' }}</span>
</span>
<span class="font-medium tabular-nums">{{ $item['value'] ?? '' }}</span>
</div>
@endforeach
{{ $slot }}
</div>
Ownership & lifecycle
Owner, release state, review evidence and adoption for this item.
- Owner
- Platform UI (@JoshJML)
- Current version
-
1.0.2 - Status
- Stable
- License
-
open - Accessibility reviewed
- No review date recorded
- Last breaking change
- No date recorded
- Deprecation
- Not deprecated
- Contract
-
v6 - Foundation
-
≥ 1.0.0