Skip to Content
NarakUI

Table

A type-safe data table with custom cells, sortable headers, and expandable rows.

Basic table

createTable<Row>() returns a table bound to one row type, so every column callback is typed. Call it once at module scope, not during render.

getValue returns the content of a default cell. renderCell returns the whole <td>, so its classes are up to you.

NameOwnerStatusUpdated
Visibility reportJasonReadyToday
Competitor briefMayaDraftYesterday
Citation reviewPriyaNeeds reviewMonday

Sortable columns

The consumer owns the sort. Set sortDirection on the sorted column so the header gets aria-sort.

Status
Citation reviewPriyaMondayNeeds review
Competitor briefMayaYesterdayDraft
Visibility reportJasonTodayReady

Expandable rows

Clicking a row, or pressing Enter or Space while it has focus, calls onToggleExpand. Keep the expanded keys in state and pass them to expandedRows. Use isRowExpandable to turn expansion off for some rows. Setting onRowClick replaces the expand toggle.

NameOwnerStatus

Action cells

align applies to the header cell and to cells rendered from getValue. A cell from renderCell sets its own alignment. Button is a block-level flex container, so wrap it in a flex justify-end container to line it up with a right-aligned header.

NameStatusActions
Visibility reportReady
Competitor briefDraft
Citation reviewNeeds review

Installation

pnpm dlx shadcn@latest add @narakui/table

Add "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/table.json.

Properties

Table

PropTypeDefaultDescription
data (Required)T[]—Rows to render.
rowKeykeyof T | ((row: T, index: number) => React.Key)indexProperty or function that returns a stable row key.
aria-labelstring—Accessible name for the table.
aria-labelledbystring—Id of the element that names the table.
expandedRowsReact.Key[][]Keys of the rows that are expanded.
onToggleExpand(rowKey: React.Key, isExpanded: boolean) => void—Called when a row is expanded or collapsed.
isRowExpandable(row: T) => boolean—Returns false for rows that should not expand.
onRowClick(row: T) => void—Called when a row is clicked. Replaces the expand toggle.
isLoadingbooleanfalseShows loadingState, or skeleton rows when loadingState is not set.
loadingStateReactNode—Content shown while loading.
placeholderRowsnumber5Number of skeleton rows while loading, and of rows the empty state fills.
emptyStateReactNode—Content shown when data is empty. Defaults to No data found.
centeredEmptyStatebooleanfalseCenters emptyState in the space below the header instead of in the first row.
density'default' | 'comfortable''default'comfortable fixes a 40px header row and 56px body rows.
headerWeight'medium' | 'regular' | 'mini''medium'Typography of the header cells. Defaults to mini when density is comfortable.
hideHeadbooleanfalseHides the header row.
fixedbooleanfalseUses a fixed table layout, so column widths do not follow content.
fixedHeaderbooleanfalseKeeps the header pinned while the body scrolls.
fixedFooterbooleanfalseKeeps Table.Footer pinned to the bottom while the body scrolls.
disableCardStylesbooleanfalseRemoves the card border and background around the table.
renderRows(data: T[]) => ReactNode[]—Renders the body rows yourself instead of from the columns.
classNamestring—Additional classes for the table element.
wrapperClassNamestring—Additional classes for the wrapper.
headClassNamestring—Additional classes for the thead element.
rowClassNamestring—Additional classes for every body row.

Table.Column

PropTypeDefaultDescription
id (Required)string—Unique column identifier. Without getValue or renderCell, the cell shows row[id].
labelReactNode—Header content.
getValue(row: T, index: number, id: string) => ReactNode—Returns the cell content inside the default cell.
renderCell(row: T, index: number, id: string) => ReactNode—Renders the whole <td> for full control.
renderHeader(column: TableColumnProps<T>) => ReactNode—Renders the whole <th> for full control.
loadingCellReactNode—Cell content while isLoading. Defaults to a full-width skeleton.
sortDirection'asc' | 'desc'—Active sort direction. Sets aria-sort on the header cell so screen readers announce the sort. Set it only on the sorted column.
align'left' | 'center' | 'right''left'Text alignment of the header cell and of cells rendered from getValue.
classNamestring—Additional classes for the header cell and the body cells.
cellClassNamestring—Additional classes for the body cells.
headerClassNamestring—Additional classes for the header cell.
headerColSpannumber—Number of columns the header cell spans.

Table.ExpandableRow

PropTypeDefaultDescription
render(row: T, index: number) => ReactNode—Content shown in one full-width row below an expanded row.
renderRows(row: T, index: number) => ReactNode—Returns one or more <tr> elements shown below an expanded row. Use instead of render.

Table.Footer

PropTypeDefaultDescription
childrenReactNode—Footer content, such as pagination.
classNamestring—Additional classes for the footer.