Composition
How a Pro component is assembled, with Widget shown in full
Pro follows the core's patterns: compound components whose parts hang off the root, a render prop
where an element must be replaced, and no classNames prop anywhere.
Compound parts, fields, React Aria props and the render prop are in
Composition.
Widget in Full
Every part of a Pro compound component hangs off its root, which is also the element you render:
import {Widget} from "@peakui-pro/react";
import {AreaChart} from "@peakui-pro/react/area-chart";
<Widget>
<Widget.Header>
<Widget.Title>Requests</Widget.Title>
<Widget.Description>Last 30 days</Widget.Description>
<Widget.Legend>
<Widget.LegendItem color="var(--chart-3)">Requests</Widget.LegendItem>
<Widget.LegendItem color="var(--chart-5)">Errors</Widget.LegendItem>
</Widget.Legend>
</Widget.Header>
<Widget.Content>
<AreaChart data={data}>
<AreaChart.Area dataKey="requests" stroke="var(--chart-3)" />
<AreaChart.Area dataKey="errors" stroke="var(--chart-5)" />
</AreaChart>
</Widget.Content>
<Widget.Footer>Updated a minute ago</Widget.Footer>
</Widget>;Widget.LegendItem takes its dot color as a value, not a token name, which is why the chart ramp
appears here as var(--chart-3). The five are on Colors.
A part is used where it belongs and nowhere else: Widget.Title inside Widget.Header, content
inside Widget.Content. Each component page carries its own anatomy.
Heavy Peers Come From a Subpath
A component that needs a large optional dependency is exported from its own subpath, so an app
that renders no chart never resolves recharts:
import {KPIGroup, TrendChip, Widget} from "@peakui-pro/react";
import {AreaChart} from "@peakui-pro/react/area-chart";The table of which component comes from where is in Introduction.
Styling Your Own Element
A Pro class name is just a class name: put it on your own element and the stylesheet applies. It is the escape hatch for a layout the parts do not cover — and it carries no behaviour, so a part is the better answer whenever one fits.
<div className="widget">
<div className="widget__header">
<h3 className="widget__title">A panel of my own</h3>
</div>
</div>