组件

Table

Rows and columns on a ruled page. Every rule is a pencil pull drawn once by the pen and printed by CSS (so a hundred rows cost no drawings), the header has an accountant's double rule, and a hovered or selected row is a highlighter swipe.

安装

terminal
npx shadcn@latest add @wobko/table

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Invoices

The whole family: a header with a double rule, rows ruled by hand in pencil, a footer with its own double rule and a caption written underneath. Hover a row to see the swipe.

Data table

Sorting, selection and pagination with plain React state and no extra dependency. A selected row is a highlighter swipe (`data-state="selected"`), the sorted column says so with `aria-sort` and an arrow, and the header checkbox goes half-ticked when only some rows are chosen. Colored pencil text is 4.7:1 on paper but about 4:1 on the full swipe, so a chosen row writes its status in ink.

Sticky header

`sticky` pins the header row while the body scrolls under it; `containerClassName="max-h-72"` gives the scroller its height. The header carries the paper color (`--ll-table-bg`) and its own double rule.

Team billing

A real screen: a card holding a table of people with faces, roles, a presence dot and what each seat costs, a highlighted row for the person you are looking at, a row button, and a footer with the total.

Demo

Official `table-demo`: seven invoices with a caption, a header, a footer total and a right-aligned amount column. The ruling is pencil: a double rule under the header, a hand-pulled line under each row, the accountant's pair above the total. Row rules are painted by CSS, so a long table costs no drawing per row.

Data table demo

Official `data-table-demo`, rebuilt with plain React state and no TanStack: filter the emails, sort the Email column, hide columns from the Columns menu, tick rows (the header box goes half-ticked when only some of a page are), and page with Previous and Next. Chosen rows are a highlighter swipe. The original's five rows fit on one page, so this one has twelve at five a page. The bordered, rounded wrapper is left off: the table is already ruled by hand.

API 参考

Table

A `<table>` in a scroll container. The container is padded 12 px and pulled back by 12 px (layout unchanged) so a focus ring or swipe at the edge is not clipped. `className` goes to the table, `containerClassName` to the container. The other parts read a context from it and throw a readable error when used outside a `Table` (a browser would drop a stray `<tr>` anyway).

属性类型默认值说明
stickybooleanfalsePin the header row to the top of the container while the body scrolls. Give the container a height with `containerClassName="max-h-72"`. The header takes `--ll-table-bg` (default the card color) so rows scroll under it.
containerClassNamestring-Classes for the scroll container (height, max-width, a different bleed). The container's padding is transparent but real: it overlaps 12 px of whatever sits directly above or below the table, so keep a gap of at least 12 px (a `gap-4` or `mt-4` is plenty), or take the bleed away with `containerClassName="m-0 w-full p-0"` when nothing at the table's edge draws outside its box.

无障碍

  • Real table semantics: table, rowgroup, columnheader, row, cell. Nothing is drawn inside the table elements; the rules and swipes are painted with CSS pseudo-elements and are invisible to assistive technology.
  • Mark the sorted column with `aria-sort="ascending" | "descending"` on its TableHead and put a `<button>` inside it (see the data table example); mark chosen rows with `data-state="selected"` and give their checkbox an accessible name.
  • Windows high contrast replaces the painted rules and swipe with real cell borders and the system highlight colors.
  • Hover only lights the swipe on pointers that can hover (and a row with an open menu, `aria-expanded`, stays lit). Reduced motion removes the fade.
  • Contrast on the swipe: ink is 11:1 on the full (selected) swipe, but green and red pencil text drop to about 4:1 there (4.7:1 on paper). Write status words in ink on selectable rows, as the data table example does, or keep colored text out of them.
  • Calm density (`data-density="calm"`) draws straight hairline rules, a plain bold header and a flat swipe, for dense data.

源码

CLI 会复制进你项目的文件。

正在加载源码