PeakUIPro

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 the sm size
  • .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

VariablePurpose
--trend-chip-indicator-sizeWidth and height of the indicator
--trend-chip-gapGap between prefix, value and suffix

API Reference

TrendChip

PropTypeDefaultDescription
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
childrenReactNode-Strings and numbers become the value; the parts take fixed places; anything else follows the suffix
classNamestring-Additional classes
renderDOMRenderFunction<'span', undefined>-Replaces the rendered <span> with your own element
...restComponentProps<'span'>-Every other Chip prop and <span> attribute, except color: the trend decides it

TrendChip.Indicator

PropTypeDefaultDescription
childrenReactNode-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-labelstring'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
classNamestring-Additional classes
...restComponentProps<'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

PropTypeDefaultDescription
childrenReactNode-Text before the value
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <span> with your own element; E defaults to 'span'
...restComponentProps<'span'>-Native <span> attributes

TrendChip.Suffix

PropTypeDefaultDescription
childrenReactNode-Text after the value
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <span> with your own element; E defaults to 'span'
...restComponentProps<'span'>-Native <span> attributes

On this page