PeakUI

Meter

Shows a quantity within a known range, such as disk usage

Usage

import {Label, Meter} from "@peakui/react";

Anatomy

import {Label, Meter} from "@peakui/react";

export default () => (
  <Meter value={60}>
    <Label />
    <Meter.Output />
    <Meter.Track>
      <Meter.Fill />
    </Meter.Track>
  </Meter>
);

A meter shows where a value sits within a known range (storage used, a score). For the progress of a task that finishes, use ProgressBar.

Examples

Sizes

Colors

Without Label

Without a visible Label, aria-label names the meter.

Custom Value

minValue, maxValue and formatOptions set the range and the display format.

Customization

Tailwind CSS

Global CSS

@layer components {
  .meter__track {
    @apply h-3 rounded-full;
  }

  .meter__fill {
    @apply rounded-full;
  }

  .meter--success {
    --meter-fill: var(--color-success);
  }
}

Styling Reference

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

CSS Classes

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

Base & Element Classes

  • .meter - Base container (grid layout)
  • .meter__output - Value text display
  • .meter__track - Track background
  • .meter__fill - Filled portion of the track

Size Classes

  • .meter--sm - Small size, thinner track
  • .meter--md - Medium size, the default
  • .meter--lg - Large size, thicker track

Color Classes

  • .meter--default
  • .meter--accent
  • .meter--success
  • .meter--warning
  • .meter--danger

Slots

  • [data-slot="meter"]
  • [data-slot="meter-output"]
  • [data-slot="meter-track"]
  • [data-slot="meter-fill"]

CSS Variables

VariablePurpose
--meter-fillFill color, set by the color classes

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Disabled: :disabled, [data-disabled="true"] or [aria-disabled="true"]

API Reference

Meter

PropTypeDefaultDescription
valuenumber0The current value
minValuenumber0The smallest value
maxValuenumber100The largest value
formatOptionsIntl.NumberFormatOptions{style: 'percent'}Display format of the value
valueLabelReactNode-Text announced as the value, such as "2 of 5"
color'default' | 'accent' | 'success' | 'warning' | 'danger''accent'Color of the fill
size'sm' | 'md' | 'lg''md'Height of the track
childrenReactNode | (values: MeterRenderProps) => ReactNode-Content, or a function of the render props
classNamestring | (values: MeterRenderProps) => string-Additional classes, or a function of the render props
...restEvery React Aria Meter attribute is accepted, including aria-label

Meter.Output

PropTypeDefaultDescription
childrenReactNodeformatted valueReplaces the formatted value
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restEvery <span> attribute is accepted

Meter.Track

PropTypeDefaultDescription
childrenReactNode-Holds Meter.Fill
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'div'
...restEvery <div> attribute is accepted

Meter.Fill

PropTypeDefaultDescription
childrenReactNode-Content inside the fill
classNamestring-Additional classes
styleCSSProperties-Merged under the computed width
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'div'
...restEvery <div> attribute is accepted

Render Props

PropTypeDescription
percentagenumber | undefinedThe value as a percentage between minValue and maxValue
valueTextstring | undefinedThe formatted value

On this page