Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(design-system): improve table docs (#41215)

Danny White0d8ec0d0116f
diff --git a/apps/design-system/__registry__/index.tsx b/apps/design-system/__registry__/index.tsx
index cf1a7450a49..83defc765c5 100644
--- a/apps/design-system/__registry__/index.tsx
+++ b/apps/design-system/__registry__/index.tsx
@@ -1358,6 +1358,17 @@ export const Index: Record<string, any> = {
subcategory: "undefined",
chunks: []
},
+ "table-cross-link": {
+ name: "table-cross-link",
+ type: "components:example",
+ registryDependencies: ["table"],
+ component: React.lazy(() => import("@/registry/default/example/table-cross-link")),
+ source: "",
+ files: ["registry/default/example/table-cross-link.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
"table-demo": {
name: "table-demo",
type: "components:example",
@@ -1369,6 +1380,61 @@ export const Index: Record<string, any> = {
subcategory: "undefined",
chunks: []
},
+ "table-actions": {
+ name: "table-actions",
+ type: "components:example",
+ registryDependencies: ["table"],
+ component: React.lazy(() => import("@/registry/default/example/table-actions")),
+ source: "",
+ files: ["registry/default/example/table-actions.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
+ "table-icons": {
+ name: "table-icons",
+ type: "components:example",
+ registryDependencies: ["table"],
+ component: React.lazy(() => import("@/registry/default/example/table-icons")),
+ source: "",
+ files: ["registry/default/example/table-icons.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
+ "table-row-link": {
+ name: "table-row-link",
+ type: "components:example",
+ registryDependencies: ["table"],
+ component: React.lazy(() => import("@/registry/default/example/table-row-link")),
+ source: "",
+ files: ["registry/default/example/table-row-link.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
+ "table-row-link-actions": {
+ name: "table-row-link-actions",
+ type: "components:example",
+ registryDependencies: ["table"],
+ component: React.lazy(() => import("@/registry/default/example/table-row-link-actions")),
+ source: "",
+ files: ["registry/default/example/table-row-link-actions.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
+ "table-sort": {
+ name: "table-sort",
+ type: "components:example",
+ registryDependencies: ["table"],
+ component: React.lazy(() => import("@/registry/default/example/table-sort")),
+ source: "",
+ files: ["registry/default/example/table-sort.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
"tabs-demo": {
name: "tabs-demo",
type: "components:example",
diff --git a/apps/design-system/config/docs.ts b/apps/design-system/config/docs.ts
index 7d14cc61da8..57697bbcb5e 100644
--- a/apps/design-system/config/docs.ts
+++ b/apps/design-system/config/docs.ts
@@ -83,6 +83,11 @@ export const docsConfig: DocsConfig = {
href: '/docs/ui-patterns/navigation',
items: [],
},
+ {
+ title: 'Tables',
+ href: '/docs/ui-patterns/tables',
+ items: [],
+ },
],
},
{
diff --git a/apps/design-system/content/docs/accessibility.mdx b/apps/design-system/content/docs/accessibility.mdx
index 8677b350c52..35bebb64804 100644
--- a/apps/design-system/content/docs/accessibility.mdx
+++ b/apps/design-system/content/docs/accessibility.mdx
@@ -27,29 +27,33 @@ Chromium-based browsers and Firefox handle this automatically via the Tab key. S
Interactive page elements should also provide visual feedback upon selection via a `focus-visible` state. We use consistent focus styles such as `inset-focus` so users recognize this state instantly.
-[Button](../components/button) has all of the above built-in. Bespoke interactive elements however, such as the below clickable [TableRow](../components/table), require these props to be added manually:
+[Button](components/button) has all of the above built-in. Bespoke interactive elements however, such as the below interactive [Table Row](components/table#examples), require these props to be added manually:
-```tsx showLineNumbers {3, 5-11}
+```tsx showLineNumbers {4-14}
<TableRow
key={id}
className="relative cursor-pointer h-16 inset-focus"
- onClick={(event) => handleBucketNavigation(name, event)}
+ onClick={(event) => {
+ if (event.currentTarget !== event.target) return
+ handleBucketNavigation(bucket.id, event)
+ }}
onKeyDown={(event) => {
+ if (event.currentTarget !== event.target) return
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
- handleBucketNavigation(name, event)
+ handleBucketNavigation(bucket.id, event)
}
}}
tabIndex={0}
>
- <TableCell>
- <p>{name}</p>
- </TableCell>
+ <TableCell>{name}</TableCell>
</TableRow>
```
Consider also affordances like `ctrl` and `meta` key support for opening in a new tab. Anything that you can do with a mouse input should be replicable by keyboard.
+See the examples within [Table](components/table#examples) for more.
+
### Radio groups
Single-select option groups such as `<input type="radio">` should behave as a single control. Only the first item of radio groups should become focused with the Tab key. The next Tab should move focus from the group to the next focusable control.
diff --git a/apps/design-system/content/docs/components/dropdown-menu.mdx b/apps/design-system/content/docs/components/dropdown-menu.mdx
index daccc38aa88..e7fed432cd7 100644
--- a/apps/design-system/content/docs/components/dropdown-menu.mdx
+++ b/apps/design-system/content/docs/components/dropdown-menu.mdx
@@ -15,12 +15,6 @@ source:
## Installation
-So I guess I can write anything i want in here.
-
-## Props
-
-{/* <ComponentProps component={'/Dropdown'} foo="world" /> */}
-
<Tabs defaultValue="cli">
<TabsList>
diff --git a/apps/design-system/content/docs/components/table.mdx b/apps/design-system/content/docs/components/table.mdx
index 6dcafe2b601..70e82f001cb 100644
--- a/apps/design-system/content/docs/components/table.mdx
+++ b/apps/design-system/content/docs/components/table.mdx
@@ -1,64 +1,134 @@
---
title: Table
-description: A responsive table component for basic data.
+description: A responsive table component for presenting data inline.
component: true
+source:
+ shadcn: true
---
-Table presents basic tabular data presentation within a [Card](/docs/components/card).
+Table is an opinionated `<table>` element for basic tabular data presentation. It is usually presented within a [Card](../components/card).
<ComponentPreview name="table-demo" peekCode wide />
-Columns will naturally take the width of their content. Width specification is therefore not required unless you require columns to span a specific width. An example use-case may be when placing multiple Table instances on the one page, where columns on each table should optically align.
-
-`TableHead` includes a `whitespace-nowrap` utility class to prevent its text from wrapping. `TableCell` must have any custom width specified, as there are legitimate use cases for both wrapping (or truncated) text.
-
## Usage
```tsx
import {
+ Card,
Table,
TableBody,
- TableCaption,
TableCell,
+ TableFooter,
TableHead,
TableHeader,
TableRow,
-} from '@/components/ui/table'
+} from 'ui'
```
```tsx
-<Table>
- <TableCaption>A list of your recent invoices.</TableCaption>
- <TableHeader>
- <TableRow>
- <TableHead>Invoice</TableHead>
- <TableHead>Status</TableHead>
- <TableHead>Method</TableHead>
- <TableHead className="text-right">Amount</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- <TableRow>
- <TableCell className="font-medium">INV001</TableCell>
- <TableCell>Paid</TableCell>
- <TableCell>Credit Card</TableCell>
- <TableCell className="text-right">$250.00</TableCell>
- </TableRow>
- </TableBody>
-</Table>
+<Card>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Column 1</TableHead>
+ <TableHead>Column 2</TableHead>
+ <TableHead>Column 3</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ <TableRow>
+ <TableCell>Value 1</TableCell>
+ <TableCell>Value 2</TableCell>
+ <TableCell>Value 3</TableCell>
+ </TableRow>
+ </TableBody>
+ <TableFooter>
+ <TableRow>
+ <TableCell colSpan={2}>Total</TableCell>
+ <TableCell>Value</TableCell>
+ </TableRow>
+ </TableFooter>
+ </Table>
+</Card>
```
-## Sortable Columns
+## Layout
+
+Columns will naturally take the width of their content unless otherwise specified. Specific column widths may be useful for controlling layout shift or for aligning multiple Table instances vertically.
+
+Table Head includes a `whitespace-nowrap` utility class to prevent its text from wrapping. Table Cell must have any custom width specified, as there are legitimate use cases for both wrapping (or truncated) text.
+
+The Table component is wrapped in a `ShadowScrollArea` by default, which provides horizontal scrolling on smaller screens when the table content exceeds the viewport width.
+
+## Structure
+
+Table is comprised of the following [Shadcn primitives](https://ui.shadcn.com/docs/components/table) which map directly to their HTML counterparts:
+
+| Component | HTML element |
+| ------------- | ------------------------------------------------------------------------------------------- |
+| Table | [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/table) |
+| Table Body | [`<tbody>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/tbody) |
+| Table Caption | [`<caption>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/caption) |
+| Table Cell | [`<td>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/td) |
+| Table Footer | [`<tfoot>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/tfoot) |
+| Table Head | [`<th>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/th) |
+| Table Header | [`<thead>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/thead) |
+| Table Row | [`<tr>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/tr) |
+
+Table and its child components follow their HTML element counterparts for semantics, accessibility, and best practices.
-Use `TableHeadSort` inside `TableHead` to enable column sorting.
+### Table Caption
+
+Table Caption describes a table’s purpose or content. Think of it like the label of a diagram. It should only contain a single text node.
+
+Just like its `<caption>` counterpart, Table Caption should be the first child of a Table element (before a Table Body) irrespective of its final visual positioning.
+
+### Table Footer
+
+Table Footer is a semantic grouping for the final rows of a table, typically used for column summaries, totals, or footnotes that relate to the data in the body of the table.
+
+Table Footer typically contains the same child elements as a Table Body, such as Table Row and Table Cell, and is a sibling of Table Body.
+
+## Examples
+
+### Empty state
+
+When displaying an empty state within a table, dim the Table Head text to indicate that no data is present. Use consistent zero results presentation across your application to maintain a cohesive user experience.
+
+<ComponentPreview name="empty-state-zero-items-table" />
+
+To prevent the empty state row from being highlighted on hover, apply the `[&>td]:hover:bg-inherit` class to the Table Row containing the empty state message.
+
+```tsx showLineNumbers {1}
+<TableRow className="[&>td]:hover:bg-inherit">
+ <TableCell colSpan={3}>
+ <p className="text-sm text-foreground">No results found</p>
+ <p className="text-sm text-foreground-lighter">
+ Your search for “test” did not return any results
+ </p>
+ </TableCell>
+</TableRow>
+```
+
+See [Empty States](../ui-patterns/empty-states) for more information.
+
+### Sortable columns
+
+Use `TableHeadSort` inside Table Head to enable column sorting. This component provides visual indicators for sort state (ascending, descending, or unsorted) and handles click interactions.
+
+```tsx
+import { TableHeadSort } from 'ui'
+```
| Prop | Type | Description |
| -------------- | -------------------------- | ------------------------------------------------------------------ |
| `column` | `string` | Unique identifier for the column |
| `currentSort` | `string` | Current sort state in format `"column:order"` (e.g., `"name:asc"`) |
| `onSortChange` | `(column: string) => void` | Callback fired when column header is clicked |
+| `children` | `ReactNode` | The label text for the column header |
+| `className` | `string` | Optional additional CSS classes |
-```tsx
+```tsx showLineNumbers {2}
<TableHead>
<TableHeadSort column="name" currentSort={sort} onSortChange={handleSortChange}>
Name
@@ -66,10 +136,85 @@ Use `TableHeadSort` inside `TableHead` to enable column sorting.
</TableHead>
```
-## Data Table
+The component displays:
+
+- An up arrow when the column is sorted ascending
+- A down arrow when the column is sorted descending
+- A chevrons icon when the column is not currently sorted (visible on hover)
+
+<ComponentPreview name="table-sort" />
+
+### Row icons
+
+When adding icon columns to your table, use [Accessibility](../accessibility) markup by including a screen reader-only label in the corresponding Table Head using the `sr-only` class. This ensures that assistive technologies can properly identify the column's purpose. Remove these icon cells when loading or displaying zero results to maintain a clean and consistent table structure.
+
+<ComponentPreview name="table-icons" />
+
+```tsx showLineNumbers {4, 5, 13, 14}
+<Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1">
+ <span className="sr-only">Icon</span>
+ </TableHead>
+ <TableHead>Name</TableHead>
+ <TableHead>Email</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ <TableRow>
+ <TableCell className="w-1">
+ <IconName size={16} className="text-foreground-muted" />
+ </TableCell>
+ <TableCell>Value</TableCell>
+ <TableCell>Value</TableCell>
+ </TableRow>
+ </TableBody>
+</Table>
+```
+
+### Actions
+
+Action should be placed in the last column of each Table Row to maintain a logical reading flow. Users scan table data from left to right, so positioning actions on the right ensures they encounter the primary information first before reaching interactive controls.
+
+#### Multiple actions
+
+When multiple actions are available for a row, display one primary action as a button and place additional options in an overflow menu. This keeps the table clean and scannable while providing access to all necessary actions without overwhelming the user.
+
+<ComponentPreview name="table-actions" />
+
+#### Cross-links
+
+You may need to link to related resources from within table cells. In these cases, use the `text-link-table-cell` CSS class to provide a visual hint that the text is interactive while maintaining its appearance as tertiary content.
+
+<ComponentPreview name="table-cross-link" />
+
+Avoid making the entire row interactive when using cross-links. Multiple interactive areas within a single row increases the chance of mis-taps and creates ambiguity about which action will be triggered. Keep cross-links as discrete, scannable elements within their respective cells, and maintain a dedicated action column for primary row-level actions.
+
+#### Row-level navigation
+
+The entire Table Row may be tappable. This pattern is most effective when navigation is the sole or primary action for each row, as it provides a large, easy-to-target interaction area.
+
+Avoid adding other actions when using row-level navigation, as multiple interactive areas within a single row create competing affordances and increase interaction complexity.
+
+<ComponentPreview name="table-row-link" />
+
+When implementing row-level navigation, pay close attention to [Accessibility](/accessibility#focus-management) requirements. The row must be keyboard accessible with proper focus management, including:
+
+- Handling `Enter` and `Space` key presses for activation
+- Providing visual focus indicators using classes like `inset-focus`
+- Supporting modifier keys (`Ctrl`/`Cmd`) for opening links in new tabs
+
+#### Row navigation with actions
+
+If you must combine row-level navigation with additional actions, nest all secondary actions in an overflow menu and maintain a [ChevronRight](https://lucide.dev/icons/chevron-right) visual indicator to signal that the row is navigable. This pattern preserves the primary navigation affordance while keeping secondary actions accessible but unobtrusive.
+
+<ComponentPreview name="table-row-link-actions" />
+
+This hybrid approach requires careful attention to event handling. Ensure that taps on action buttons stop event propagation to prevent triggering row navigation, and maintain clear visual separation between the navigable row area and the action controls.
-You can use the `<Table />` component to build more complex data tables. Combine it with [@tanstack/react-table](https://tanstack.com/table/v8) to create tables with sorting, filtering and pagination.
+## Related
-See the [Data Table](/docs/components/data-table) documentation for more information.
+Use the Table component for simple, static tabular data presentation with a fixed number of rows. Consider using [Data Table](../components/data-table) for more complex cases as it provides built-in sorting, filtering, and pagination capabilities.
-You can also see an example of a data table in the [Tasks](/examples/tasks) demo.
+Refer to [Tables](../ui-patterns/tables) for broader guidance and best practices on presenting tabular data.
diff --git a/apps/design-system/content/docs/ui-patterns/tables.mdx b/apps/design-system/content/docs/ui-patterns/tables.mdx
new file mode 100644
index 00000000000..0a20ea26ea2
--- /dev/null
+++ b/apps/design-system/content/docs/ui-patterns/tables.mdx
@@ -0,0 +1,30 @@
+---
+title: Tables
+description: Display structured data in a scannable, organized way.
+---
+
+Tables are a fundamental pattern for displaying structured data in rows and columns. They provide a scannable, organized way to present collections of related information, making it easy for users to compare values, identify patterns, and take action on specific items.
+
+The choice of table component depends on several factors: the complexity of the data, the level of interactivity required, the amount of data being displayed, and the context within the page layout.
+
+## Components
+
+There are two main table components, each optimized for different use cases:
+
+### Table
+
+The [Table](../components/table) component is designed for simple, static tabular data presentation. Use it when:
+
+- Displaying a fixed, known number of rows
+- The data is primarily read-only
+- Sort, filter, or search actions are not required or can be basic
+
+### Data Table
+
+The [Data Table](../components/data-table) component is designed for immersive, data-heavy experiences. Use it when:
+
+- Displaying large datasets that require pagination
+- Users need to perform complex sort, filter, or search actions through the data
+- Row selection is required
+- The table is the primary focus of the page
+- Full-viewport layouts are appropriate
diff --git a/apps/design-system/registry/default/example/empty-state-zero-items-table.tsx b/apps/design-system/registry/default/example/empty-state-zero-items-table.tsx
index f2a5e37dfc1..385c9ed8172 100644
--- a/apps/design-system/registry/default/example/empty-state-zero-items-table.tsx
+++ b/apps/design-system/registry/default/example/empty-state-zero-items-table.tsx
@@ -6,9 +6,9 @@ export default function EmptyStateZeroItemsTable() {
<Table>
<TableHeader>
<TableRow>
- <TableHead className="text-foreground-muted">Table name</TableHead>
- <TableHead className="text-foreground-muted">Date created</TableHead>
- <TableHead />
+ <TableHead className="text-foreground-muted">Name</TableHead>
+ <TableHead className="text-foreground-muted">Created</TableHead>
+ <TableHead className="text-foreground-muted">Updated</TableHead>
</TableRow>
</TableHeader>
<TableBody>
diff --git a/apps/design-system/registry/default/example/table-actions.tsx b/apps/design-system/registry/default/example/table-actions.tsx
new file mode 100644
index 00000000000..e89e76a8b40
--- /dev/null
+++ b/apps/design-system/registry/default/example/table-actions.tsx
@@ -0,0 +1,61 @@
+import { EllipsisVertical, User } from 'lucide-react'
+import { Button, Card, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
+
+const users = [
+ {
+ name: 'Feathers McGraw',
+ email: '[email protected]',
+ },
+ {
+ name: 'Piella Bakewell',
+ email: '[email protected]',
+ },
+ {
+ name: 'Wendolene Ramsbottom',
+ email: '[email protected]',
+ },
+]
+
+export default function TableActions() {
+ return (
+ <Card className="w-full">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1">
+ <span className="sr-only">Icon</span>
+ </TableHead>
+ <TableHead>Name</TableHead>
+ <TableHead>Email</TableHead>
+ <TableHead className="w-1">
+ <span className="sr-only">Actions</span>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {users.map((user) => (
+ <TableRow key={user.email}>
+ <TableCell className="w-1">
+ <User size={16} className="text-foreground-muted" />
+ </TableCell>
+ <TableCell>{user.name}</TableCell>
+ <TableCell className="text-foreground-lighter">{user.email}</TableCell>
+ <TableCell className="flex items-center gap-x-2">
+ <Button type="default" size="tiny">
+ Inspect
+ </Button>
+ <Button
+ icon={<EllipsisVertical />}
+ aria-label={`More actions`}
+ type="default"
+ size="tiny"
+ className="w-7"
+ />
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+}
diff --git a/apps/design-system/registry/default/example/table-cross-link.tsx b/apps/design-system/registry/default/example/table-cross-link.tsx
new file mode 100644
index 00000000000..9de6df040e7
--- /dev/null
+++ b/apps/design-system/registry/default/example/table-cross-link.tsx
@@ -0,0 +1,91 @@
+import { DatabaseZap, Edit2, EllipsisVertical } from 'lucide-react'
+import Link from 'next/link'
+import { Button, Card, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
+
+const triggers = [
+ {
+ name: 'trigger_purchase',
+ table: 'stock',
+ function: 'check_stock_levels',
+ },
+ {
+ name: 'trigger_refund',
+ table: 'stock',
+ function: 'process_return',
+ },
+ {
+ name: 'trigger_update',
+ table: 'inventory',
+ function: 'update_quantity',
+ },
+]
+
+export default function TableCrossLink() {
+ return (
+ <Card className="w-full">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1">
+ <span className="sr-only">Icon</span>
+ </TableHead>
+ <TableHead>Name</TableHead>
+ <TableHead>Table</TableHead>
+ <TableHead>Function</TableHead>
+ <TableHead className="w-1">
+ <span className="sr-only">Actions</span>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {triggers.map((trigger) => (
+ <TableRow key={trigger.name}>
+ <TableCell className="w-1">
+ <DatabaseZap size={16} className="text-foreground-muted" />
+ </TableCell>
+ <TableCell>{trigger.name}</TableCell>
+ <TableCell>
+ <Link
+ className="text-link-table-cell text-foreground-lighter hover:text-foreground duration-100"
+ // Demo purposes only
+ href="/"
+ onClick={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+ }}
+ >
+ {trigger.table}
+ </Link>
+ </TableCell>
+ <TableCell>
+ <Link
+ className="text-link-table-cell text-foreground-lighter hover:text-foreground duration-100"
+ // Demo purposes only
+ href="/"
+ onClick={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+ }}
+ >
+ {trigger.function}
+ </Link>
+ </TableCell>
+ <TableCell className="flex items-center gap-x-2">
+ <Button type="default" size="tiny" icon={<Edit2 />}>
+ Edit
+ </Button>
+ <Button
+ icon={<EllipsisVertical />}
+ aria-label={`More actions`}
+ type="default"
+ size="tiny"
+ className="w-7"
+ />
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+}
diff --git a/apps/design-system/registry/default/example/table-demo.tsx b/apps/design-system/registry/default/example/table-demo.tsx
index 6ee6dad665a..b26830b3514 100644
--- a/apps/design-system/registry/default/example/table-demo.tsx
+++ b/apps/design-system/registry/default/example/table-demo.tsx
@@ -64,9 +64,9 @@ const invoices = [
export default function TableDemo() {
return (
- <Card className="w-full pb-4">
+ <Card className="w-full">
<Table>
- <TableCaption>A list of your recent invoices</TableCaption>
+ <TableCaption className="border-0">A list of your recent invoices</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
@@ -79,7 +79,7 @@ export default function TableDemo() {
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.invoice}>
- <TableCell className="text-foreground">{invoice.invoice}</TableCell>
+ <TableCell className="text-foreground font-mono">{invoice.invoice}</TableCell>
<TableCell className="text-foreground-lighter">{invoice.paymentStatus}</TableCell>
<TableCell className="text-foreground-lighter">{invoice.paymentMethod}</TableCell>
<TableCell className="hidden md:table-cell text-foreground-muted">
@@ -89,7 +89,7 @@ export default function TableDemo() {
</TableRow>
))}
</TableBody>
- <TableFooter className="border-t">
+ <TableFooter>
<TableRow>
<TableCell colSpan={4}>Total</TableCell>
<TableCell className="text-right">$2,250.00</TableCell>
diff --git a/apps/design-system/registry/default/example/table-icons.tsx b/apps/design-system/registry/default/example/table-icons.tsx
new file mode 100644
index 00000000000..7ec8f38adee
--- /dev/null
+++ b/apps/design-system/registry/default/example/table-icons.tsx
@@ -0,0 +1,46 @@
+import { User } from 'lucide-react'
+import { Card, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
+
+const users = [
+ {
+ name: 'Feathers McGraw',
+ email: '[email protected]',
+ },
+ {
+ name: 'Piella Bakewell',
+ email: '[email protected]',
+ },
+ {
+ name: 'Wendolene Ramsbottom',
+ email: '[email protected]',
+ },
+]
+
+export default function TableIcons() {
+ return (
+ <Card className="w-full">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1">
+ <span className="sr-only">Icon</span>
+ </TableHead>
+ <TableHead>Name</TableHead>
+ <TableHead>Email</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {users.map((user) => (
+ <TableRow key={user.email}>
+ <TableCell className="w-1">
+ <User size={16} className="text-foreground-muted" />
+ </TableCell>
+ <TableCell>{user.name}</TableCell>
+ <TableCell className="text-foreground-lighter">{user.email}</TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+}
diff --git a/apps/design-system/registry/default/example/table-row-link-actions.tsx b/apps/design-system/registry/default/example/table-row-link-actions.tsx
new file mode 100644
index 00000000000..ee82a507b7e
--- /dev/null
+++ b/apps/design-system/registry/default/example/table-row-link-actions.tsx
@@ -0,0 +1,103 @@
+import { ChevronRight, EllipsisVertical, Shield } from 'lucide-react'
+import { Button, Card, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
+
+const policies = [
+ {
+ id: 'policy-1',
+ name: 'Anyone can view all active listings',
+ command: 'select',
+ appliedTo: 'public',
+ },
+ {
+ id: 'policy-2',
+ name: 'Users can delete their own listings',
+ command: 'delete',
+ appliedTo: 'authenticated',
+ },
+ {
+ id: 'policy-3',
+ name: 'Admins can update any listing',
+ command: 'update',
+ appliedTo: 'authenticated',
+ },
+]
+
+const handlePolicyNavigation = (
+ bucketId: string,
+ event: React.MouseEvent | React.KeyboardEvent
+) => {
+ const url = `/${bucketId}`
+ if (event.metaKey || event.ctrlKey) {
+ // window.open(`${url}`, '_blank') Disabled for demo purposes
+ } else {
+ // router.push(url) Disabled for demo purposes
+ }
+}
+
+export default function TableRowLinkActions() {
+ return (
+ <Card className="w-full">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1">
+ <span className="sr-only">Icon</span>
+ </TableHead>
+ <TableHead>Name</TableHead>
+ <TableHead>Command</TableHead>
+ <TableHead>Applied to</TableHead>
+ <TableHead className="w-1">
+ <span className="sr-only">Actions</span>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {policies.map((policy) => (
+ <TableRow
+ key={policy.id}
+ className="relative cursor-pointer inset-focus"
+ onClick={(event) => {
+ if (event.currentTarget !== event.target) return
+ handlePolicyNavigation(policy.id, event)
+ }}
+ onKeyDown={(event) => {
+ if (event.currentTarget !== event.target) return
+ if (event.key === 'Enter' || event.key === ' ') {
+ event.preventDefault()
+ handlePolicyNavigation(policy.id, event)
+ }
+ }}
+ tabIndex={0}
+ >
+ <TableCell className="w-1">
+ <Shield aria-label="policy icon" size={16} className="text-foreground-muted" />
+ </TableCell>
+ <TableCell>{policy.name}</TableCell>
+ <TableCell>
+ <code className="text-foreground-muted text-code-inline uppercase">
+ {policy.command}
+ </code>
+ </TableCell>
+ <TableCell className="text-foreground-lighter">{policy.appliedTo}</TableCell>
+ <TableCell className="flex justify-end items-center h-full gap-3">
+ <Button
+ icon={<EllipsisVertical />}
+ aria-label={`More actions`}
+ type="default"
+ size="tiny"
+ className="w-7"
+ />
+ <div>
+ <ChevronRight aria-hidden={true} size={14} className="text-foreground-muted/60" />
+ </div>
+ <button tabIndex={-1} className="sr-only">
+ Go to policy
+ </button>
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+}
diff --git a/apps/design-system/registry/default/example/table-row-link.tsx b/apps/design-system/registry/default/example/table-row-link.tsx
new file mode 100644
index 00000000000..2ea3ec14436
--- /dev/null
+++ b/apps/design-system/registry/default/example/table-row-link.tsx
@@ -0,0 +1,92 @@
+import { FilesBucket as FilesBucketIcon } from 'icons'
+import { ChevronRight } from 'lucide-react'
+import { Card, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
+
+const buckets = [
+ {
+ id: 'avatars',
+ name: 'avatars',
+ updated: '2 hours ago',
+ },
+ {
+ id: 'listing-photos',
+ name: 'listing-photos',
+ updated: '1 day ago',
+ },
+ {
+ id: 'documents',
+ name: 'documents',
+ updated: '3 days ago',
+ },
+]
+
+const handleBucketNavigation = (
+ bucketId: string,
+ event: React.MouseEvent | React.KeyboardEvent
+) => {
+ const url = `/${bucketId}`
+ if (event.metaKey || event.ctrlKey) {
+ // window.open(`${url}`, '_blank') Disabled for demo purposes
+ } else {
+ // router.push(url) Disabled for demo purposes
+ }
+}
+
+export default function TableRowLink() {
+ return (
+ <Card className="w-full">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1">
+ <span className="sr-only">Icon</span>
+ </TableHead>
+ <TableHead>Name</TableHead>
+ <TableHead>Updated</TableHead>
+ <TableHead className="w-1">
+ <span className="sr-only">Actions</span>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {buckets.map((bucket) => (
+ <TableRow
+ key={bucket.id}
+ className="relative cursor-pointer inset-focus"
+ onClick={(event) => {
+ if (event.currentTarget !== event.target) return
+ handleBucketNavigation(bucket.id, event)
+ }}
+ onKeyDown={(event) => {
+ if (event.currentTarget !== event.target) return
+ if (event.key === 'Enter' || event.key === ' ') {
+ event.preventDefault()
+ handleBucketNavigation(bucket.id, event)
+ }
+ }}
+ tabIndex={0}
+ >
+ <TableCell className="w-1">
+ <FilesBucketIcon
+ aria-label="bucket icon"
+ size={16}
+ className="text-foreground-muted"
+ />
+ </TableCell>
+ <TableCell>{bucket.name}</TableCell>
+ <TableCell className="text-foreground-muted">{bucket.updated}</TableCell>
+ <TableCell>
+ <div className="flex justify-end items-center h-full">
+ <ChevronRight aria-hidden={true} size={14} className="text-foreground-muted/60" />
+ </div>
+ <button tabIndex={-1} className="sr-only">
+ Go to bucket
+ </button>
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+}
diff --git a/apps/design-system/registry/default/example/table-sort.tsx b/apps/design-system/registry/default/example/table-sort.tsx
new file mode 100644
index 00000000000..4a29d1f0230
--- /dev/null
+++ b/apps/design-system/registry/default/example/table-sort.tsx
@@ -0,0 +1,143 @@
+import { useMemo, useState } from 'react'
+
+import {
+ Card,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeadSort,
+ TableHeader,
+ TableRow,
+} from 'ui'
+
+const products = [
+ {
+ name: 'Wireless Mouse',
+ category: 'Electronics',
+ price: 29.99,
+ description: 'Ergonomic wireless mouse with long battery life',
+ },
+ {
+ name: 'Keyboard',
+ category: 'Electronics',
+ price: 79.99,
+ description: 'Mechanical keyboard with RGB lighting',
+ },
+ {
+ name: 'Monitor Stand',
+ category: 'Furniture',
+ price: 35.5,
+ description: 'Wooden monitor stand with cable management',
+ },
+ {
+ name: 'Webcam',
+ category: 'Electronics',
+ price: 99.99,
+ description: '4K webcam with auto-focus',
+ },
+ {
+ name: 'Desk Chair',
+ category: 'Furniture',
+ price: 199.99,
+ description: 'Ergonomic office chair with lumbar support',
+ },
+ {
+ name: 'USB-C Hub',
+ category: 'Electronics',
+ price: 49.99,
+ description: 'Multi-port USB-C hub with HDMI output',
+ },
+]
+
+type ProductSort =
+ | 'name:asc'
+ | 'name:desc'
+ | 'category:asc'
+ | 'category:desc'
+ | 'price:asc'
+ | 'price:desc'
+type ProductSortColumn = 'name' | 'category' | 'price'
+type ProductSortOrder = 'asc' | 'desc'
+
+export default function TableSort() {
+ const [sort, setSort] = useState<ProductSort>('name:asc')
+
+ const handleSortChange = (column: ProductSortColumn) => {
+ const [currentCol, currentOrder] = sort.split(':') as [ProductSortColumn, ProductSortOrder]
+ if (currentCol === column) {
+ // Cycle through: asc -> desc -> no sort (default)
+ if (currentOrder === 'asc') {
+ setSort(`${column}:desc` as ProductSort)
+ } else {
+ // Reset to default sort (name:asc)
+ setSort('name:asc')
+ }
+ } else {
+ // New column, start with asc
+ setSort(`${column}:asc` as ProductSort)
+ }
+ }
+
+ const sortedProducts = useMemo(() => {
+ const [sortCol, sortOrder] = sort.split(':') as [ProductSortColumn, ProductSortOrder]
+ const orderMultiplier = sortOrder === 'asc' ? 1 : -1
+
+ return [...products].sort((a, b) => {
+ if (sortCol === 'name') {
+ return a.name.localeCompare(b.name) * orderMultiplier
+ }
+ if (sortCol === 'category') {
+ return a.category.localeCompare(b.category) * orderMultiplier
+ }
+ if (sortCol === 'price') {
+ return (a.price - b.price) * orderMultiplier
+ }
+ return 0
+ })
+ }, [sort])
+
+ return (
+ <Card className="w-full">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>
+ <TableHeadSort column="name" currentSort={sort} onSortChange={handleSortChange}>
+ Product
+ </TableHeadSort>
+ </TableHead>
+ <TableHead>
+ <TableHeadSort column="category" currentSort={sort} onSortChange={handleSortChange}>
+ Category
+ </TableHeadSort>
+ </TableHead>
+ <TableHead className="hidden md:table-cell">Description</TableHead>
+ <TableHead className="text-right">
+ <TableHeadSort
+ className="justify-end"
+ column="price"
+ currentSort={sort}
+ onSortChange={handleSortChange}
+ >
+ Price
+ </TableHeadSort>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {sortedProducts.map((product) => (
+ <TableRow key={product.name}>
+ <TableCell className="text-foreground">{product.name}</TableCell>
+ <TableCell className="text-foreground-lighter">{product.category}</TableCell>
+ <TableCell className="hidden md:table-cell text-foreground-muted">
+ {product.description}
+ </TableCell>
+ <TableCell className="text-right">${product.price.toFixed(2)}</TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+}
diff --git a/apps/design-system/registry/examples.ts b/apps/design-system/registry/examples.ts
index f3fcc100e0a..eaf8ea11310 100644
--- a/apps/design-system/registry/examples.ts
+++ b/apps/design-system/registry/examples.ts
@@ -791,12 +791,48 @@ export const examples: Registry = [
registryDependencies: ['switch', 'form'],
files: ['example/switch-form.tsx'],
},
+ {
+ name: 'table-cross-link',
+ type: 'components:example',
+ registryDependencies: ['table'],
+ files: ['example/table-cross-link.tsx'],
+ },
{
name: 'table-demo',
type: 'components:example',
registryDependencies: ['table'],
files: ['example/table-demo.tsx'],
},
+ {
+ name: 'table-actions',
+ type: 'components:example',
+ registryDependencies: ['table'],
+ files: ['example/table-actions.tsx'],
+ },
+ {
+ name: 'table-icons',
+ type: 'components:example',
+ registryDependencies: ['table'],
+ files: ['example/table-icons.tsx'],
+ },
+ {
+ name: 'table-row-link',
+ type: 'components:example',
+ registryDependencies: ['table'],
+ files: ['example/table-row-link.tsx'],
+ },
+ {
+ name: 'table-row-link-actions',
+ type: 'components:example',
+ registryDependencies: ['table'],
+ files: ['example/table-row-link-actions.tsx'],
+ },
+ {
+ name: 'table-sort',
+ type: 'components:example',
+ registryDependencies: ['table'],
+ files: ['example/table-sort.tsx'],
+ },
{
name: 'tabs-demo',
type: 'components:example',