Table

Table

A flexible data table component for displaying structured data with support for sorting, selection, responsive design, and interactive rows.


Import

tsx
import { Table } from "asheeui";

Usage

tsx
"use client";
import { type ColumnDef, Table } from "asheeui";
interface User {
name: string;
age: number;
email: string;
}
const columns: ColumnDef<User>[] = [
{ header: "Name", cell: (row) => row.name },
{ header: "Age", cell: (row) => row.age },
{ header: "Email", cell: (row) => row.email },
];
const data: User[] = [
{ name: "John Doe", age: 30, email: "john@example.com" },
{ name: "Jane Smith", age: 25, email: "jane@example.com" },
];
export default function Basic() {
return <Table columns={columns} data={data} />;
}

Examples

Variant

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

Size

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

Radius

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

With row selection

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com
Bob Wilson42bob@example.com

Selected: none

Row selection color

Primary Color

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

Secondary Color

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

Danger Color

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

Success Color

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

Warning Color

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

With interactive rows

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

With custom row key accessor

NameAge
John Doe30
Jane Smith25

Empty state

NameAgeEmail
No users found

Custom empty message

NameAgeEmail
No data available

With custom cell rendering

NameStatus
John Doe
active
Jane Smith
inactive

Custom styling

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

With grid classes

NameAgeEmail
John Doe30john@example.com
Jane Smith25jane@example.com

Props

PropTypeDefaultDescription
dataTData[]NoneArray of row data objects (required)
columnsColumnDef<TData>[]NoneColumn definitions (required)
variant"grid" | "striped" | "bordered" | "ghost""grid"*Visual style
size"sm" | "md" | "lg""md"*Density/size scale
color"none" | "default" | "primary" | "secondary" | "danger" | "warning" | "success""primary"*Selection/hover color
radius"none" | "xs" | "sm" | "md" | "lg" | "xl" | "full""md"*Corner rounding
rowKeyAccessor(row: TData) => string | numberNoneReturns unique key per row
selectedRowKeystring | numberNoneKey of selected row
isClickablebooleanfalseEnables interactive rows
handleClick(data: TData, rowId?: string | number) => voidNoneRow click handler
handleDoubleClick(data: TData, rowId?: string | number) => voidNoneRow double-click handler
emptyMessageReactNode"No items available"Empty state content
headerClassNamestringNoneExtra classes for header
rowClassNamestringNoneExtra classes for each row
cellClassNamestringNoneExtra classes for each cell
classNamestringNoneExtra classes, merged with internal styles

* Falls back through Global Configuration if not set. See below.

ColumnDef

PropTypeDescription
idstringOptional explicit key for React rendering
headerReactNodeHeader content (required)
cell(row: TData) => ReactNodeCell renderer (required)

Global Configuration

Table reads defaults from four places, in this order of precedence:

  1. Instance prop: set directly on <Table />
  2. Component config: components.table in your ashee.config
  3. Theme default: defaultColor / defaultRadius in your ashee.config
  4. Built-in fallback: component's internal default values

Component config

ts
// ashee.config.ts
import type { ExternalConfig } from "asheeui";
export const config: ExternalConfig = {
components: {
table: {
size: "md",
variant: "grid",
color: "primary",
radius: "md",
},
},
};

Built-in fallbacks

ts
{
size: "md",
variant: "grid",
color: "primary",
radius: "md",
}

Accessibility

  • Uses semantic <table>, <thead>, and <tbody> elements
  • Header cells use scope="col"
  • Interactive rows are keyboard accessible with Enter and Space keys
  • Uses aria-selected for selected rows
  • Implements focus-visible rings for keyboard navigation
  • TabIndex management for interactive rows
  • Empty state is conveyed properly to screen readers

Notes

  • Variant: grid adds borders between cells, striped alternates row backgrounds, bordered adds borders around the table, ghost removes all borders.
  • Interactive Rows: When isClickable is true or click handlers are provided, rows become interactive with hover effects and keyboard support.
  • Row Selection: Use selectedRowKey to highlight a specific row. The row's color is determined by the color prop.
  • Empty State: The emptyMessage prop allows customization of the content displayed when data is empty.
  • Row Key Accessor: For better performance with dynamic data, provide a rowKeyAccessor function to generate unique row keys.
  • Sticky Header: The table header is sticky by default for better scrolling UX.
Previous

← Switch

Next

Tabs →