Skip to main content
The DsMeter component displays a numeric value as a graphical meter within a defined range. This component is useful for showing progress, usage statistics, capacity levels, or any metric that has minimum and maximum bounds.

Component Location

Basic Usage

Component API

DsMeter

The root component that manages meter state and provides context to child components.

DsMeterTrack

Container for the meter indicator that represents the full range. Default styling: h-4 w-full overflow-hidden rounded-full bg-secondary

DsMeterIndicator

Visual indicator that shows the current value position within the range. The width is automatically calculated as a percentage based on the current value.

DsMeterLabel

Accessible label for the meter that connects to the root via aria-labelledby.

DsMeterValue

Displays the formatted value, hidden from screen readers since the value is announced via ARIA. Slot Props:
  • formattedValue (string): Formatted value string
  • value (number): Raw numeric value

Usage Examples

Without Label and Value

Minimal meter showing only the visual indicator:

With Custom Formatting

Display a currency value:

With Custom Value Display

Use scoped slots to customize the value display:

Percentage Display

By default, values are treated as percentages (0-100 range):
This displays as “85%”.

Custom Range Display

For non-percentage ranges:

Localized Formatting

Format numbers according to different locales:

Styling

Custom Colors

Change indicator color using Tailwind classes:

Different Sizes

Adjust the meter height:

Custom Layout

Arrange label and value horizontally:

Accessibility

The meter component includes proper accessibility features:
  • Role: role="meter" on the root element
  • ARIA Attributes:
    • aria-valuenow: Current value
    • aria-valuemin: Minimum value
    • aria-valuemax: Maximum value
    • aria-valuetext: Human-readable value
    • aria-labelledby: Links to the label element
  • Screen Reader Support: The value display has aria-hidden="true" since the value is announced via ARIA attributes

Custom Accessibility Text

Provide custom ARIA text for screen readers:

Common Use Cases

Progress Tracking

Resource Usage

Quota Display

Architecture Notes

  1. Context-Based State: The root component provides context to child components using Vue’s provide/inject
  2. Automatic Calculation: The indicator width is calculated automatically based on value, min, and max
  3. Type-Safe: All components have proper TypeScript interfaces
  4. Composable: Build custom layouts by arranging components differently
  5. Formatting: Uses Intl.NumberFormat for locale-aware number formatting