Ir al contenido
Español

Cómo funciona

A 12px pill with absolutely placed segments separated by 1px borders in the surface colour, so the gaps stay crisp on any background. The whole bar is revealed with one clip-path sweep from the left on the reveal curve, so it reads as a single stroke rather than separate pieces; the marker then drops onto it on a spring. The marker is a dark chip above a 2px pin that crosses the bar with a ring in the surface colour; near either end it aligns inward. Pointing at a segment or its legend row fades the others to 30%.

Úsalo para

  • Composition of one whole: storage, a budget, time spent, a portfolio.
  • A value placed on a banded scale: a score, a quality index, a risk level.

Busca otra opción cuando

  • Comparing many wholes side by side: use a stacked bar chart.
  • More than about seven categories: group the small ones.

Uso

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

export function StorageUse({ usage }) {
  return (
    <CategoryBar
      label="Storage use"
      total={100}
      data={[
        { name: 'Photos', value: usage.photos },
        { name: 'Documents', value: usage.documents, tone: 3 },
        { name: 'Free', value: 100 - usage.used, tone: 'track' },
      ]}
      marker={{ value: 80, label: 'Alert at 80 GB' }}
      formatValue={(v) => `${v} GB`}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
data{ name: string, value: number, tone?: 1-8 | 'track', color?: string, display?: string }[]—Segments left to right. tone 'track' draws an empty part (free space); display replaces the value in the legend, for example a range.
totalnumber—The whole; defaults to the sum. Anything left over stays empty.
marker{ value: number, label?: string }—A dark chip and a pin at a value, aligned so it stays inside near either end.
boundaries / legendbooleanfalse / trueCumulative values under the segment edges (crowded ones are skipped), and a legend with value and share.
formatValue / formatShare(v) => string / (pct) => string—Number formats; return '' from formatShare to hide shares.
labelstring'Breakdown'Start of the accessible name; every category, its value and share and the marker are appended.

Accesibilidad

  • The bar is one image whose accessible name lists every category with its value and share, and the marker label.
  • The legend repeats it visually and is hidden from screen readers to avoid reading it twice.
  • Hover highlighting is a visual aid only; nothing is lost without a pointer.
  • Reduced motion shows the bar and marker at once.

Movimiento

Bar: one 1000ms clip-path sweep on the reveal curve. Marker: drops from 520ms with a 520ms spring. Highlight: 160ms.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

CategoryBar.jsxcategory-bar.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.