jbmui

ScoreScale

  • UI
  • adjustable

A read-only score meter with endpoint labels and a controlled marker.

Claridad de la idea6 / 10
Por explorarLista para compartir

Install

npx shadcn@latest add @jbm/score-scale

Needs the @jbm entry in components.json; see Install once.

Also installs @jbm/tokens.

Docs

Usage

Score out of ten with named endpoints
import { ScoreScale } from "@/jbm/ui/score-scale"<ScoreScale label="Claridad" value={6} min={0} max={10}  labels={["Por explorar", "Lista para compartir"]}  formatValue={(v) => `${v} / 10`} />// Read-only meter; clamps values to the range.

Props

Stage
fluid

Width fills its container (minWidth 0); the track spans it less 12px padding per side. Height is about 95 stage pixels at one line each: heading row, 22px gap, 24px track, 10px gap, 12px mono captions. Long label, value, or endpoint captions wrap and add lines.

Read-only meter (role meter, not an input): a label and formatted value above a track with five evenly spaced ticks and a vermilion marker, with endpoint captions below. The marker position is (value − min) / (max − min); the caller controls value. Throws RangeError for non-finite numbers or max ≤ min.

PropTypeDefaultDescription
valuenumberrequiredScore to display. Finite values are clamped to min…max before positioning and formatting.
minnumber0Low end of the scale; the left endpoint caption when labels is omitted.
maxnumber10High end of the scale; must be greater than min. The right endpoint caption when labels is omitted.
labelstringrequiredVisible heading and the meter's accessible name.
labels[string, string]noneEndpoint captions [low, high] shown under the track instead of min and max.
formatValue(value: number) => stringStringFormats the clamped value for the accent readout and aria-valuetext, e.g. (v) => ${v} / 10.

Also accepts React.HTMLAttributes<HTMLDivElement>.

QA checks

  • Drag the score control through min, the middle, and max: the marker sits on the first, center, and last ticks and never leaves the track.
  • Pass a value outside the range: the marker and readout show the clamped value.
  • Check long labels and endpoint captions wrap without overlapping at narrow widths.
  • Screen readers announce a meter with aria-valuetext from formatValue; it is not focusable or draggable itself.