PeakUIPro

Widget

A card that frames a chart, a table or metrics

Usage

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

Anatomy

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

// The widget ships from the package root: it imports no chart, so framing one needs no charting
// library here. Put the chart in `Content`, imported from its own subpath.
export default () => (
  <Widget>
    <Widget.Header>
      <Widget.Title />
      <Widget.Description />
      <Widget.Legend>
        <Widget.LegendItem color="var(--chart-3)" />
      </Widget.Legend>
    </Widget.Header>
    <Widget.Content />
    <Widget.Footer />
  </Widget>
);

Legend colours

color takes any CSS colour, matching the series the item names.

<Widget.LegendItem color="var(--chart-3)">Organic</Widget.LegendItem>
<Widget.LegendItem color="#f43f5e">Paid</Widget.LegendItem>

Examples

With Bar Chart

With Line Chart

With Pie Chart

With KPIs

Dashboard Grid

Customization

Tailwind CSS

<Widget className="max-w-lg">
  <Widget.Content className="p-0">{/* edge to edge */}</Widget.Content>
</Widget>

Global CSS

@layer components {
  .widget {
    --widget-inset: calc(var(--spacing) * 2);
    --widget-legend-dot-size: calc(var(--spacing) * 3);
  }
}

Styling Reference

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

CSS Classes

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

Base Classes

  • .widget - The tinted shell

Element Classes

  • .widget__header - The row above the content; title, description and legend, spread apart
  • .widget__title - The widget's name
  • .widget__description - A quieter line beside the title
  • .widget__content - The raised surface the chart, table or metrics sit on
  • .widget__footer - The row below the content
  • .widget__legend - The set of legend items
  • .widget__legend-item - One series: a dot and its label
  • .widget__legend-item-dot - The coloured dot
  • .widget__legend-item-label - The series name

Slots

  • [data-slot="widget"] - The root
  • [data-slot="widget-header"] - The header row
  • [data-slot="widget-title"] - The title
  • [data-slot="widget-description"] - The description
  • [data-slot="widget-content"] - The content surface
  • [data-slot="widget-footer"] - The footer row
  • [data-slot="widget-legend"] - The legend
  • [data-slot="widget-legend-item"] - A legend item
  • [data-slot="widget-legend-item-dot"] - The dot
  • [data-slot="widget-legend-item-label"] - The label

CSS Variables

VariablePurpose
--widget-insetThe shell's inset around the content
--widget-legend-dot-sizeWidth and height of the legend dot
--widget-legend-dotThe dot's colour; set on the dot by LegendItem's color

API Reference

Widget

PropTypeDefaultDescription
childrenReactNode-The header, content and footer
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div> with your own element
...restComponentProps<'div'>-Native <div> attributes

Widget.Header

PropTypeDefaultDescription
childrenReactNode-The title, description and legend
classNamestring-Additional classes
...restComponentProps<'div'>-Native <div> attributes

Widget.Title

PropTypeDefaultDescription
childrenReactNode-The widget's name
classNamestring-Additional classes
...restComponentProps<'span'>-Native <span> attributes

Widget.Description

PropTypeDefaultDescription
childrenReactNode-A quieter line beside the title
classNamestring-Additional classes
...restComponentProps<'span'>-Native <span> attributes

Widget.Content

PropTypeDefaultDescription
childrenReactNode-The chart, table or metrics
classNamestring-Additional classes; p-0 makes the content edge to edge
...restComponentProps<'div'>-Native <div> attributes

Widget.Footer

PropTypeDefaultDescription
childrenReactNode-Actions or metadata
classNamestring-Additional classes
...restComponentProps<'div'>-Native <div> attributes

Widget.Legend

PropTypeDefaultDescription
childrenReactNode-The Widget.LegendItem entries
classNamestring-Additional classes
...restComponentProps<'div'>-Native <div> attributes

Widget.LegendItem

PropTypeDefaultDescription
colorstring-Required. Any CSS colour for the dot, usually the series' own
childrenReactNode-The series name
classNamestring-Additional classes
...restComponentProps<'div'>-Native <div> attributes

On this page