Ir al contenido
Español
Tabla con barras de datos viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

The table draws its own card (surface, large radius, card shadow, no border) with an optional title row; the header sits over the card's only hairline and rows have no lines. Each column picks how its cells are drawn with kind. bar: a 6px pill in a rounded track beside the number, proportional to value ÷ column maximum (or max); bars rest in the soft series colour and the largest one is solid. delta: a soft pill with an arrow, in success or danger colour. heat: a rounded block mapped to five colour steps. spark: a small line with a soft area and a dot on the latest point. Once the table is 30% in view (IntersectionObserver) it gets data-shown: bars sweep in with translateX, 30ms apart by row, lines draw with stroke-dashoffset and the dot pops, while every number (summary included) counts up over 900ms. Bars are full-width pills moved inside the track, so their caps stay round. New rows on the same table move bars and numbers from the values on screen to the new ones; sparklines draw again. The crosshair turns the row into a soft pill, the column into a faint band and the crossing cell accent, without dimming anything.

Úsalo para

  • Reports and dashboards where you need exact numbers and a quick comparison: visits by channel, revenue by region, tickets by agent.
  • Tables with several metrics to read across and down: the crosshair keeps people on the right row and column.
  • Rates such as conversion or completion where you want to see the spread: a colour scale beats a column of digits.

Busca otra opción cuando

  • Only the top few matter and there is one metric: use a horizontal ranking bar, it saves space.
  • Trends over time: use a line or bar chart; in-cell bars compare only within a column.
  • Values that can be negative and shown as bars (profit and loss): data bars show non-negative amounts only; use the delta column for signed change.
  • Many columns that need horizontal scrolling: freeze columns first and keep bars to the one or two key columns.

Uso

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

const columns = [
  { key: 'city', title: 'City', width: 90 },
  { key: 'orders', title: 'Orders', kind: 'bar' },
  { key: 'trend', title: 'Trend', width: 78, kind: 'spark' }, // an array of numbers, oldest first
  { key: 'delta', title: 'Change', width: 94, kind: 'delta' }, // 8.4 means +8.4%
]

const rows = [
  { city: 'Lisbon', orders: 1284, trend: [150, 162, 171, 168, 190, 205, 238], delta: 8.4 },
  { city: 'Osaka', orders: 1102, trend: [148, 151, 160, 149, 158, 166, 170], delta: 3.1 },
  { city: 'Toronto', orders: 846, trend: [131, 128, 120, 126, 118, 112, 111], delta: -2.6 },
]

export function OrdersByCity() {
  return (
    <DatabarTable
      title="Orders by city"
      subtitle="This week"
      columns={columns}
      rows={rows}
      rowKey={(r) => r.city}
      // Numbers in the summary count up and are formatted like their column
      summary={{ city: 'Total', orders: 3232, delta: 5.2 }}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
columnsColumn[]—Column definitions: key, title, width, align, kind ('text' | 'bar' | 'delta' | 'heat' | 'spark'), max, min, format (receives the absolute value for delta), render (custom cell; kind is ignored). A spark cell takes an array of numbers.
rowsobject[]—Data rows. Values in bar, delta and heat columns must be numbers, spark values arrays of numbers; other cells show as plain text. Passing new rows to the same table makes bars and numbers move from the old values.
rowKey(row) => string | number—Unique key of each row.
summary{ [columnKey]: ReactNode }—Summary row on a filled band at the bottom, by column key. Numbers count up and use their column's format (a delta column shows a change pill); other content shows as given. It does not take part in bar or colour proportions.
crosshairbooleantrueBrightens the whole row and column of the hovered or focused cell. Off gives a plain row hover and no Tab stop.
rowHeightnumber48Row height in px; dense dashboards can use 40 to 44. At least 44 on touch devices.
emptyTextReactNode'No data'Text shown when there are no rows.
titleReactNode—Card title shown in the title row. A string title also names the table for screen readers when label is not given.
subtitleReactNode—Muted qualifier after the title, such as a period ("This week").
iconReactNode—Icon before the title, drawn in a tinted 32px rounded square. Decorative (aria-hidden).
actionsReactNode—Controls at the right end of the title row (buttons, a switch, a menu).
labelstring—Table name for screen readers (the <caption>). Defaults to title when title is a string.
labelsobject—Replaces the screen-reader text of change cells (up, down, flat); each is a function receiving the formatted change. Shallow-merged over the English defaults.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root <div>.

Accesibilidad

  • The whole table is one Tab stop (role="grid" with a roving tabindex); arrows move cell by cell, Home and End go to the row ends, Ctrl+Home and Ctrl+End to the first and last cell, Esc clears the highlight.
  • Only keyboard focus draws the focus ring and crosshair (:focus-visible); mouse clicks leave no ring.
  • Bars and sparklines are decorative (aria-hidden); screen readers read the final number, not the one counting up. It is a real <table> with <th scope="col"> and label (or a string title) as <caption>.
  • Change is not only red and green: it has an arrow and the number, and is read as "Up 8.4%".
  • Text on colour blocks switches between body and surface colour, keeping contrast in light and dark themes.
  • With reduced motion bars, blocks and lines are in place at once and numbers do not count; on touch screens the header and rows are at least 44px.

Movimiento

First view: bars translateX from empty to their length over 900ms cubic-bezier(0.22, 1, 0.36, 1), 30ms apart by row; heat blocks fade and scale in on the same curve; sparklines draw over 900ms, the area fades in 200ms later and the end dot pops at 60% with a spring; numbers count on JavaScript frames over 900ms in step. Data change: bars and numbers move from the old value to the new one on the same curve. Crosshair colours: 160ms standard.

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.

DatabarTable.jsxdatabar-table.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.

Tablas
Tabla comparativa viene con Pro. La vista previa aparece al desbloquearlo.
Tabla editable viene con Pro. La vista previa aparece al desbloquearlo.