Unified UI

Table

A data table component with sorting indicators, density options, alignment control, and semantic markup.

Basic

A data table component with sorting indicators, density options, alignment control, and proper semantic HTML markup.

A list of recent invoices.
InvoiceStatusMethodAmount
INV-001PaidCredit Card$250.00
INV-002PendingPayPal$150.00
INV-003OverdueBank Transfer$350.00

Installation

Install the component via the CLI in one command.

npx @work-rjkashyap/unified-ui add table
pnpm dlx @work-rjkashyap/unified-ui add table
npx @work-rjkashyap/unified-ui add table
bunx @work-rjkashyap/unified-ui add table

If you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.

Or install the full package

Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.

npm install @work-rjkashyap/unified-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import {
	Table,
	TableHeader,
	TableBody,
	TableFooter,
	TableRow,
	TableHead,
	TableCell,
	TableCaption,
	Badge,
} from "@work-rjkashyap/unified-ui";

Basic Usage

The Table component renders semantic HTML table elements (<table>, <thead>, <tbody>, <tr>, <th>, <td>) styled with design system tokens.

NameEmailRole
Alice Cooperalice@example.comAdmin
Bob Smithbob@example.comEditor

Density

The density prop on the root Table controls the vertical padding of all rows. Two options are available.

Compact

NameValue
Item A100
Item B200

Comfortable (default)

NameValue
Item A100
Item B200
DensityVertical PaddingUse Case
compactReducedData-dense tables, logs, admin panels
comfortableDefaultGeneral-purpose tables, user-facing content

Cell Alignment

Use the align prop on TableHead and TableCell to control horizontal text alignment. This is especially useful for numeric columns.

ProductQuantityPrice
Widget A42$9.99
Widget B17$24.99
AlignClassUse Case
lefttext-leftDefault. Text content, names, descriptions
centertext-centerStatus indicators, quantities, boolean values
righttext-rightNumeric values, prices, percentages

With Caption

Use TableCaption to provide an accessible description of the table's content. The caption is rendered below the table by default.

Monthly revenue breakdown for Q4 2024.
MonthRevenue
October$12,400
November$14,800
December$18,200

Use TableFooter for summary rows like totals.

ItemAmount
Hosting$50.00
Domain$12.00
SSL Certificate$0.00
Total$62.00

Sorting Indicators

The TableHead component supports a sortDirection prop to display a visual sort indicator (arrow). This is a purely visual prop — you handle the sort logic externally.

<Table>
	<TableHeader>
		<TableRow>
			<TableHead
				sortDirection="asc"
				onClick={() => handleSort("name")}
				className="cursor-pointer"
			>
				Name
			</TableHead>
			<TableHead
				sortDirection={null}
				onClick={() => handleSort("email")}
				className="cursor-pointer"
			>
				Email
			</TableHead>
			<TableHead align="right">Actions</TableHead>
		</TableRow>
	</TableHeader>
	<TableBody>{/* Sorted rows */}</TableBody>
</Table>
sortDirectionVisualDescription
"asc"Sorted ascending
"desc"Sorted descending
null / omittedNot sorted / no indicator

Striped Rows

Add a striped prop to the root Table for alternating row backgrounds to improve readability in large data sets.

IDNameStatus
001AliceActive
002BobInactive
003CharlieActive

Responsive Wrapping

For tables that may exceed the viewport width on mobile, wrap the Table in a horizontally scrollable container.

<div className="overflow-x-auto rounded-md border border-border">
	<Table>
		<TableHeader>
			<TableRow>
				<TableHead>ID</TableHead>
				<TableHead>Name</TableHead>
				<TableHead>Email</TableHead>
				<TableHead>Role</TableHead>
				<TableHead>Department</TableHead>
				<TableHead align="right">Joined</TableHead>
			</TableRow>
		</TableHeader>
		<TableBody>{/* Many columns that may overflow */}</TableBody>
	</Table>
</div>

Props

Table

PropTypeDefaultDescription
density"compact" | "comfortable""comfortable"Vertical padding density for all rows.
stripedbooleanfalseWhether to apply alternating row backgrounds.
classNamestringAdditional CSS classes.

TableHeader

PropTypeDefaultDescription
classNamestringAdditional CSS classes.

TableBody

PropTypeDefaultDescription
classNamestringAdditional CSS classes.

TableFooter

PropTypeDefaultDescription
classNamestringAdditional CSS classes.

TableRow

PropTypeDefaultDescription
classNamestringAdditional CSS classes.

TableHead

PropTypeDefaultDescription
align"left" | "center" | "right""left"Horizontal text alignment.
sortDirection"asc" | "desc" | nullSort indicator direction.
classNamestringAdditional CSS classes.

TableCell

PropTypeDefaultDescription
align"left" | "center" | "right""left"Horizontal text alignment.
classNamestringAdditional CSS classes.

TableCaption

PropTypeDefaultDescription
classNamestringAdditional CSS classes.

Accessibility

The Table component uses semantic HTML elements (table, thead, tbody, tfoot, tr, th, td, caption) for full screen reader support without requiring additional ARIA attributes.

  • Uses native HTML table elements which are natively accessible to screen readers and assistive technology.
  • TableCaption renders as a <caption> element, providing an accessible description of the table.
  • TableHead renders as <th> with proper scope attributes for column/row headers.
  • Sort indicators include aria-sort attributes (ascending, descending, none) on sortable column headers.
  • Focus ring is visible on sortable headers when navigated via keyboard.
  • The table is wrapped in a container that allows horizontal scrolling on small viewports without breaking layout.

Design Tokens

TokenUsage
--surfaceTable background
--border-mutedRow borders
--mutedStriped row background, footer background
--foregroundHeader and cell text
--muted-foregroundCaption text
--duration-fastHover transition speed

On this page