Table
Table component with sortable columns, row selection, custom cells, striped rows and an empty state.
How to use it
Run npx @blossomui/react add table, or copy src/components/UI/Table/Table.tsx into your React project and import it.
import { Table } from './components/ui/Table'Props
TableColumn
| Prop | Type | Description |
|---|---|---|
| key (required) | string | |
| header (required) | string | |
| render | (row: T) => ReactNode | Custom cell. Without it the value of `row[key]` is shown. |
| sortable | boolean | Lets the user sort the rows by this column. |
| sortValue | (row: T) => string | number | Value used to sort the rows when the cell is custom and `row[key]` is not what you see. |
| align | 'left' | 'right' | 'center' |
TableProps
| Prop | Type | Description |
|---|---|---|
| labels | { selectAll?: string; selectRow?: string; previous?: string; next?: string; showing?: (from: number, to: number, total: number) => string; page?: (page: number, total: number) => string } | Texts of the component. Pass only the ones you want to change, for example to translate it. |
| pageSize | number | Rows per page. Without it all the rows are shown. |
| page | number | Current page, starting at 1. Use it with `onPageChange` to control the page. |
| onPageChange | (page: number) => void | |
| color | string | Accent color of this component: any CSS color. Without it the component uses `--blossom-accent`, which is pink by default. |
| columns (required) | TableColumn<T>[] | |
| rows (required) | T[] | |
| rowKey (required) | (row: T) => string | Returns a unique id for each row. |
| selectable | boolean | Adds a checkbox column. |
| onSelectionChange | (selected: T[]) => void | |
| empty | ReactNode | Shown when there are no rows. |
| striped | boolean | |
| caption | string |