Skip to content

v0.4.0

Choose a tag to compare

@anthony-liddle anthony-liddle released this 23 Oct 21:48
8244600

The table ships its own CSS. Tailwind is no longer needed, every element the table renders has a documented rdt- class, and the stylesheet comes as an unlayered and a layered copy. This is a breaking release; the steps below take a 0.3.0 app across.

Upgrading from 0.3.0

1. Swap the Tailwind wiring for the layered stylesheet

0.3.0 needed your Tailwind to scan the package. Remove that line:

@source "../node_modules/@anthony-liddle/react-data-table/dist"; /* delete */

Then load the layered copy from your CSS entry, after a line that orders the layers, in place of the styles.css import:

@layer theme, base, react-data-table, components, utilities;
@import "tailwindcss";
@import "@anthony-liddle/react-data-table/styles.layer.css";

With Tailwind, use the layered copy, not styles.css. Tailwind's utilities live in a layer, and an unlayered stylesheet beats every layer, so with styles.css a utility you pass through className (a column's text-right, PaginationClient's px-4) would lose to the table's own rules. Import it from CSS rather than JavaScript so the order line always comes first: a layer used before it is ordered sinks below preflight, and the table loses its padding and borders.

Apps without Tailwind or cascade layers keep the single import, import '@anthony-liddle/react-data-table/styles.css'.

2. Check your theme tokens

0.3.0 declared default tokens on :root as bare HSL triplets (--card: 0 0% 100%). 0.4.0 declares none. It reads each token as a full colour and falls back to its own default when you haven't set one.

  • A current shadcn/ui theme (full colours such as --card: oklch(1 0 0)) works as it is.
  • A theme written as triplets: change the values and your own reads together. Write each value as a full colour (--card: hsl(0 0% 100%)), and change every hsl(var(--card)) in your CSS to var(--card), including a Tailwind @theme inline mapping (--color-card: var(--card)). Changing only the values gives hsl(hsl(...)), which is invalid, and every colour that reads the token breaks.
  • No theme of your own, but your app's CSS used the tokens the package declared: they are gone, so declare them yourself. The 0.3.0 defaults, as full colours, are listed in the package's .storybook/preview.css.
  • --drag-selection follows the same rule: 216 100% 58.4% becomes hsl(216 100% 58.4%).

3. Update anything that targets the old classes

0.3.0 0.4.0
.data-table-con .rdt-table
.data-table .rdt-table__table
.data-table-sticky .rdt-table__cell--sticky, .rdt-table__header-cell--sticky, .rdt-sort-header--sticky
.data-table-no-highlight .rdt-table__cell--actions, .rdt-table__expanded-row
.drag-selection-range, -start, -end data-drag-range, data-drag-start, data-drag-end on .rdt-table__row
.drag-selection-dragging data-dragging on .rdt-table__table
.table-row-selected, .modal-table, .data-table-tight, .data-table-no-auto-hover Removed. The package never applied them.

The components no longer carry Tailwind utility classes. The README's Styling section lists every class, state attribute and custom property.

4. If you call useTableDragSelection yourself

getRowClassName(rowIndex) is replaced by getRowDragState(rowIndex), which returns { inRange, isStart, isEnd }, plus an isDragActive flag. DataTable turns these into attributes for you.

Also new

  • styles.layer.css, the same rules inside @layer react-data-table.
  • Custom properties: --rdt-radius, --rdt-font-size, --rdt-header-font-size, --rdt-cell-padding-x, --rdt-cell-padding-y, --rdt-row-selected and --rdt-skeleton. Set them on :root, on any ancestor, or on one row through rowClassName.
  • Selected rows are marked by a 3px bar in the primary colour on their first cell, and carry data-selected. Set --rdt-row-selected to tint them as well.
  • The stylesheet sets everything its own parts rely on, so a global button rule or a CSS reset no longer changes the table's controls.
  • clsx, tailwind-merge, class-variance-authority and @radix-ui/react-slot are no longer dependencies.

Fixes

  • Expanded rows get the light muted tint their markup asked for, and no longer take the row hover highlight.
  • Submenu borders use the border colour, matching the main menu, instead of the text colour.
  • Alignment classes on a column take effect in its cells and in its sortable header. The package's own rules used to beat them.

Full change: #12