HapplyUI

Components

Table

A styled HTML table component with header, body, row dividers, and cell sub-components. Works well with @tanstack/react-table for sorting, selection, and pagination.


Installation

bunx @happlyui/cli@latest add table

Dependencies

Registry dependencies

These are automatically installed when you add this component.

  • happly-ui-utils
  • divider

Usage

import * as Table from "@/components/ui/table"

<Table.Root>
  <Table.Header>
    <Table.Row>
      <Table.Head>Name</Table.Head>
      <Table.Head>Email</Table.Head>
    </Table.Row>
  </Table.Header>
  <Table.Body>
    <Table.Row>
      <Table.Cell>John</Table.Cell>
      <Table.Cell>john@example.com</Table.Cell>
    </Table.Row>
  </Table.Body>
</Table.Root>

Examples

Data Table

A full data table example with sortable columns, avatars, and action buttons using @tanstack/react-table.

Member name
Title
Status
James Brownjames@example.com
Marketing ManagerSince Aug, 2021
Active
Sophia Williamssophia@example.com
HR AssistantSince Aug, 2021
Active
Arthur Taylorarthur@example.com
Entrepreneur / CEOSince May, 2022
Absent
Emma Wrightemma@example.com
Front-end DeveloperSince Sep, 2022
Active
Matthew Johnsonmatthew@example.com
Data Software EngineerSince Feb, 2022
Active
Laura Perezlaura@example.com
Fashion DesignerSince Mar, 2022
Absent
Wei Chenwei@example.com
Operations ManagerSince July, 2021
Active
<Table.Root>
  <Table.Header>
    <Table.Row>
      <Table.Head>Member</Table.Head>
      <Table.Head>Title</Table.Head>
      <Table.Head>Status</Table.Head>
    </Table.Row>
  </Table.Header>
  <Table.Body>
    <Table.Row>
      <Table.Cell>...</Table.Cell>
    </Table.Row>
    <Table.RowDivider />
    <Table.Row>
      <Table.Cell>...</Table.Cell>
    </Table.Row>
  </Table.Body>
</Table.Root>

Numeric columns

Pass `numeric` to a header and its cells so figures align on their trailing edge with fixed-width digits.

InvoicePlanSeatsAmount
INV-1042Team12$1,188.00
INV-1041Starter3$99.00
INV-1040Enterprise148$17,760.00
<Table.Head numeric>Amount</Table.Head>
<Table.Cell numeric>$1,188.00</Table.Cell>

Empty state

An empty table says what belongs here and how it gets filled, spanning every column.

InvoicePlanAmount

No invoices yet

Invoices appear here once a subscription renews.

<Table.Row>
  <Table.Cell colSpan={3} className="h-32 text-center">
    <p>No invoices yet</p>
    <p>Invoices appear here once a subscription renews.</p>
  </Table.Cell>
</Table.Row>

API Reference

Table.Root

The main table wrapper with horizontal scroll overflow.

PropTypeDefaultDescription

Table.Header

The table header section (thead).

PropTypeDefaultDescription

Table.Head

A table header cell with subtle background and rounded corners. Renders scope="col" by default.

PropTypeDefaultDescription
numericbooleanfalseAligns the column to the trailing edge and renders its digits at a fixed width (tabular-nums)
scope'col' | 'row' | 'colgroup' | 'rowgroup''col'The cells this header applies to

Table.Body

The table body section with configurable spacing from the header.

PropTypeDefaultDescription
spacingnumber8Space in pixels between the header and body

Table.Row

A table row with group hover support.

PropTypeDefaultDescription

Table.RowDivider

A visual divider row between table rows using the Divider component.

PropTypeDefaultDescription
dividerClassNamestring-Additional class name for the inner Divider component

Table.Cell

A table data cell with a 150ms hover background transition.

PropTypeDefaultDescription
numericbooleanfalseAligns the cell to the trailing edge and renders its digits at a fixed width (tabular-nums)

Table.Caption

A table caption element.

PropTypeDefaultDescription

Previous
Status Indicator
Next
Tag