Ir al contenido
Español
Barras de rango viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

Each column is a faint full-height track with a range window on it. The window is placed by a full-height box moved with translateY, so a new reading glides into place, and on first view the fill rises inside the window's rounded clip, so the ends stay round. The chip and the axis pill follow the selection; the reading beside the chart counts to the selected period's high and low. Nothing is measured, so the server render is already right.

Úsalo para

  • A low and a high per period where the spread matters: blood pressure, daily temperature, price range, heart rate.
  • A compact week or month view with one reading in focus.
  • Health, travel and finance dashboards with a card per measure.

Busca otra opción cuando

  • One value per period: use a bar chart.
  • More than about 14 periods: the ranges become too thin; use a line chart with a band.
  • Distributions with quartiles: use a box plot.

Uso

import { RangeBars } from './RangeBars.jsx'

const week = [
  { label: 'Monday', short: 'M', low: 78, high: 118 },
  { label: 'Tuesday', short: 'T', low: 82, high: 124 },
  { label: 'Wednesday', short: 'W', low: 80, high: 121 },
  { label: 'Thursday', short: 'T', low: 86, high: 131 },
  { label: 'Friday', short: 'F', low: 83, high: 126 },
  { label: 'Saturday', short: 'S', low: 79, high: 119 },
  { label: 'Sunday', short: 'S', low: 84, high: 129 },
]

export function PressureCard() {
  return (
    <RangeBars
      title="Blood pressure"
      qualifier="This week"
      caption="Latest reading"
      unit="mmHg"
      chip={{ label: 'Now' }}
      status="Steady"
      tone={5}
      data={week}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
title / qualifierstring—Card title (15px semibold) and grey words after it.
iconReactNode—An 18px icon in a 32px square tinted with the card colour.
onAction / actionIcon / actionLabel / action() => void / 'open' | 'more' / string / ReactNode- / 'open'A round chevron or three-dot button at the right of the title row, its accessible name, or your own element instead.
data{ label: string, short?: string, low: number, high: number }[]—One range per period, oldest first. `short` is the axis label (for example one letter per weekday); `label` is shown above the reading and read out.
selected / onSelectnumber / (index) => void—The selected period (defaults to the last one) and a callback when a click, tap or arrow key picks another. Without `selected` the card keeps its own selection.
captionstring—Grey line above the reading while the last period is shown; other periods show their label.
unit / statusstring / ReactNode—A grey unit under the reading, and a tinted pill under it for a short verdict.
chip{ label: string, value?: string }—The chip over the last range, such as “NOW · 129”: an uppercase label and the high value in the card colour. Over other periods it shows the high value alone.
min / maxnumber—The scale; defaults to the data with 12% room at each end.
formatValue / formatRange(n) => string / (low, high) => stringtoLocaleString('en-US') / `${high}/${low}`Formats each number (it also receives in-between values while counting) and the range as it is announced.
tone1-81Card colour (--ds-chart-N). Resting ranges alternate a strong and a soft mix of it; the selected range is solid.
heightnumber156Plot height in px (96-320), including 34px of room for the chip.
textobject—Replaces built-in words (open, more, high, low, chart, announce); shallow-merged over the English defaults.
labelstring—Accessible name of the chart; defaults to the title.
replayKeyany—Change it to play the entrance again.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the card.

Accesibilidad

  • The chart is a focusable group: Left and Right move the selection, Home and End jump, and each step is announced with the period and its range.
  • A hidden table lists every period with its high and low, so nothing depends on the shapes or colour.
  • The selected period is shown by colour, the chip and the ink axis pill together.
  • With reduced motion the ranges and the chip are in place at once and the reading shows its final value.

Movimiento

When 30% of the card is on screen the ranges rise inside their rounded windows over 900ms on cubic-bezier(0.22, 1, 0.36, 1), each starting 24-48ms after the one before; the reading counts on the same curve, timed to the selected range, and the chip springs in at 700ms. Pointing at another day moves the chip in 260ms, the other ranges fade to 45% and the reading counts there in 480ms. A new reading glides its range to the new place in 560ms.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

RangeBars.jsxrange-bars.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Gráficos
Trilateración viene con Pro. La vista previa aparece al desbloquearlo.