TrendChip
A chip showing a metric's direction and change
Usage
import {TrendChip} from "@peakui-pro/react";Anatomy
Keep parts as direct children: a part inside a fragment or wrapper is not repositioned.
import {TrendChip} from "@peakui-pro/react";
// Rendered as: indicator, then prefix, value and suffix — in that order, however they are written.
// A part inside a fragment or another component is not recognised and renders after the suffix.
// A wrapped Indicator also leaves the default arrow in place: the chip then shows two.
export default () => (
<TrendChip>
<TrendChip.Indicator />
<TrendChip.Prefix />
3.3%
<TrendChip.Suffix />
</TrendChip>
);Examples
Variants
Sizes
Custom Indicator
TrendChip.Indicator takes one icon, or SVG shapes it wraps in its own <svg>.
Prefix And Suffix
Tabular Nums
Stack chips in a column: the value's tabular figures keep the digits aligned.
Customization
Tailwind CSS
<TrendChip className="rounded-full">+3.3%</TrendChip>Global CSS
@layer components {
.trend-chip {
--trend-chip-gap: calc(var(--spacing) * 0.5);
}
.trend-chip--lg {
--trend-chip-indicator-size: calc(var(--spacing) * 5);
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The TrendChip component uses these CSS classes (view source styles):
Base & Size Classes
.trend-chip- Added to the Chip root, beside the Chip's own classes; carries thesmsize.trend-chip--sm- Small size; empty, the base class carries it.trend-chip--md- Medium size.trend-chip--lg- Large size
Element Classes
.trend-chip__indicator- The trend arrow, or the icon that replaces it.trend-chip__value- The figure; tabular numerals.trend-chip__prefix- Text before the value.trend-chip__suffix- Text after the value; regular weight
Data Attributes
[data-trend="up"],[data-trend="down"],[data-trend="neutral"]- The trend, on the root
Slots
[data-slot="chip"]- The root element, a Chip[data-slot="chip-label"]- The Chip label holding prefix, value and suffix[data-slot="trend-chip-indicator"]- The indicator[data-slot="trend-chip-prefix"]- The prefix[data-slot="trend-chip-value"]- The value[data-slot="trend-chip-suffix"]- The suffix
CSS Variables
| Variable | Purpose |
|---|---|
--trend-chip-indicator-size | Width and height of the indicator |
--trend-chip-gap | Gap between prefix, value and suffix |
API Reference
TrendChip
| Prop | Type | Default | Description |
|---|---|---|---|
trend | 'up' | 'down' | 'neutral' | 'up' | Direction of the metric; sets the chip color (success, danger, default) and the default arrow |
size | 'sm' | 'md' | 'lg' | 'sm' | Chip size |
variant | 'primary' | 'secondary' | 'soft' | 'tertiary' | 'soft' | Chip variant |
children | ReactNode | - | Strings and numbers become the value; the parts take fixed places; anything else follows the suffix |
className | string | - | Additional classes |
render | DOMRenderFunction<'span', undefined> | - | Replaces the rendered <span> with your own element |
...rest | ComponentProps<'span'> | - | Every other Chip prop and <span> attribute, except color: the trend decides it |
TrendChip.Indicator
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | None: the arrow of the trend, and nothing for neutral. One <svg> element or icon component: it becomes the indicator. Anything else — several children, <path>, <g>, a fragment: drawn inside an <svg> the part renders itself |
aria-label | string | 'Up' or 'Down' | Name of the default arrow, which is exposed as an image; set it to translate. An icon or shapes passed as children get no name unless you give one |
className | string | - | Additional classes |
...rest | ComponentProps<'svg'> | - | Native <svg> attributes: on the default arrow, on the icon, or on the part's own <svg> — give that one a viewBox |
TrendChip.Prefix
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Text before the value |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered <span> with your own element; E defaults to 'span' |
...rest | ComponentProps<'span'> | - | Native <span> attributes |
TrendChip.Suffix
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Text after the value |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered <span> with your own element; E defaults to 'span' |
...rest | ComponentProps<'span'> | - | Native <span> attributes |