@podoba/react 0.0.46 → 0.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podoba/react",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "type": "module",
5
5
  "description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
6
6
  "repository": {
@@ -28,8 +28,8 @@
28
28
  "typecheck": "tsc --build"
29
29
  },
30
30
  "dependencies": {
31
- "@podoba/tokens": "^0.0.46",
32
- "@podoba/tailwind": "^0.0.46",
31
+ "@podoba/tokens": "^0.0.48",
32
+ "@podoba/tailwind": "^0.0.48",
33
33
  "react-aria-components": "1.18.0",
34
34
  "class-variance-authority": "0.7.1",
35
35
  "clsx": "2.1.1",
@@ -26,7 +26,7 @@ export function CsvPreviewTable({ headers, rows, mapping, label, emptyMessage, .
26
26
  const data: ReactNode[][] = rows.map(row => headers.map(header => row[header] ?? ''))
27
27
  if (mapping) data.unshift(mapping)
28
28
  return <PreviewScroll {...rest}>
29
- <Table<ReactNode[]> appearance="worksheet" className={compact ? 'min-w-168' : 'min-w-256'}
29
+ <Table<ReactNode[]> className={compact ? 'min-w-168' : 'min-w-256'}
30
30
  aria-label={label} emptyMessage={emptyMessage} data={data}
31
31
  columns={headers.map((header, index) => ({ key: String(index), header, render: row => row[index] }))} />
32
32
  </PreviewScroll>
@@ -0,0 +1,56 @@
1
+ /**
2
+ * TableHeaderIcon: the filled column glyphs from gs-platform's GSTable headers
3
+ * (`packages/ui/src/gs-frontend/icons`). They sit before a header label in the muted
4
+ * header ink and are decorative; the label carries the column's name.
5
+ */
6
+ export type TableHeaderIconKind = 'check' | 'document' | 'file' | 'user' | 'calendar' | 'sparkle'
7
+
8
+ export const TABLE_HEADER_ICON_KINDS: readonly TableHeaderIconKind[] = ['check', 'document', 'file', 'user', 'calendar', 'sparkle']
9
+
10
+ export function TableHeaderIcon({ kind }: { kind: TableHeaderIconKind }) {
11
+ if (kind === 'user') {
12
+ return (
13
+ <svg viewBox="0 0 17 16" aria-hidden="true" className="size-4 shrink-0 text-fg-subtle">
14
+ <path d="M8.94916 1.07056e-07C6.97332 -0.000323024 5.06732 0.730853 3.59864 2.05256C2.12995 3.37426 1.2026 5.19289 0.995357 7.15782C0.933839 7.71759 0.933839 8.28241 0.995357 8.84218C1.2026 10.8071 2.12995 12.6257 3.59864 13.9474C5.06732 15.2691 6.97332 16.0003 8.94916 16C11.0709 16 13.1058 15.1571 14.6061 13.6569C16.1064 12.1566 16.9492 10.1217 16.9492 8C16.9492 5.87827 16.1064 3.84344 14.6061 2.34315C13.1058 0.842855 11.0709 1.38672e-07 8.94916 1.07056e-07ZM14.1721 12.5422C13.2988 12.2116 11.8837 11.727 11.0028 11.4654C10.9103 11.4384 10.8993 11.4308 10.8993 11.0512C10.9185 10.7373 11.0052 10.4312 11.1533 10.1538C11.3285 9.76741 11.4477 9.35809 11.5075 8.93813C11.7876 8.56826 11.9678 8.1325 12.0307 7.67279C12.14 7.32648 12.1347 6.95415 12.0155 6.6111C12.0068 6.58964 11.9992 6.56775 11.9928 6.54552C11.9784 6.04518 12.0185 5.54476 12.1122 5.05307C12.1834 4.34609 11.9781 3.63899 11.5392 3.08016C11.2661 2.74673 10.923 2.47743 10.5342 2.29133C10.1454 2.10523 9.72049 2.0069 9.28949 2.00328H8.61643C8.18853 2.00933 7.76713 2.10885 7.38173 2.29487C6.99634 2.48089 6.65626 2.74891 6.38533 3.08016C5.94388 3.63781 5.73689 4.34542 5.80823 5.05307C5.90193 5.54476 5.94197 6.04518 5.92766 6.54552C5.92006 6.57244 5.91247 6.59177 5.90487 6.61455C5.78347 6.9572 5.77813 7.33026 5.88969 7.67624C5.95438 8.13546 6.1344 8.5708 6.41295 8.94158C6.47373 9.36352 6.59219 9.77511 6.76501 10.1648C6.87871 10.4533 6.92864 10.763 6.91135 11.0726C6.91135 11.4536 6.89617 11.4571 6.81126 11.4868C5.90004 11.756 4.54565 12.233 3.73453 12.556C2.53323 11.2066 1.90711 9.44096 1.98987 7.63617C2.07262 5.83138 2.85769 4.13046 4.17743 2.8966C5.49717 1.66274 7.24701 0.993722 9.05329 1.0324C10.8596 1.07109 12.5792 1.8144 13.8449 3.10363C15.0841 4.34322 15.8071 6.00673 15.8678 7.75848C15.9285 9.51023 15.3225 11.2198 14.1721 12.5422Z" fill="currentColor" />
15
+ </svg>
16
+ )
17
+ }
18
+ if (kind === 'file') {
19
+ return (
20
+ <svg viewBox="0 0 20 20" aria-hidden="true" className="size-4 shrink-0 text-fg-subtle">
21
+ <path d="M5 2.5h6l4 4V17.5H5z" fill="currentColor" />
22
+ <path d="M11 2.5v4h4" fill="none" stroke="var(--color-surface)" strokeWidth="1.25" />
23
+ </svg>
24
+ )
25
+ }
26
+ if (kind === 'document') {
27
+ return (
28
+ <svg viewBox="0 0 12 16" aria-hidden="true" className="h-4 w-3 shrink-0 text-fg-subtle">
29
+ <path d="M7.00012 4.25114V2.85945e-06H0.749739C0.65123 -0.000181485 0.553654 0.0190897 0.462609 0.0567111C0.371563 0.0943324 0.28884 0.149563 0.219183 0.219236C0.149527 0.288909 0.0943089 0.371651 0.0566963 0.462718C0.0190837 0.553785 -0.000182991 0.651384 1.30983e-06 0.749915V15.2501C-0.000182991 15.3486 0.0190837 15.4462 0.0566963 15.5373C0.0943089 15.6283 0.149527 15.7111 0.219183 15.7808C0.28884 15.8504 0.371563 15.9057 0.462609 15.9433C0.553654 15.9809 0.65123 16.0002 0.749739 16H11.2496C11.3481 16.0003 11.4458 15.9811 11.5369 15.9435C11.628 15.9059 11.7108 15.8507 11.7806 15.781C11.8503 15.7113 11.9056 15.6286 11.9432 15.5374C11.9809 15.4463 12.0002 15.3487 12 15.2501V5.00105H7.74985C7.55124 5.00031 7.36097 4.92107 7.22052 4.78059C7.08008 4.64012 7.00085 4.4498 7.00012 4.25114ZM2.00023 2.25044C2.00023 2.1842 2.02654 2.12068 2.07336 2.07385C2.12019 2.02701 2.18369 2.0007 2.24991 2.0007H4.7502C4.78299 2.0007 4.81546 2.00716 4.84575 2.01971C4.87604 2.03226 4.90357 2.05066 4.92675 2.07385C4.94994 2.09704 4.96833 2.12457 4.98088 2.15487C4.99343 2.18517 4.99988 2.21764 4.99988 2.25044V2.75061C4.99988 2.78341 4.99343 2.81589 4.98088 2.84618C4.96833 2.87648 4.94994 2.90402 4.92675 2.92721C4.90357 2.9504 4.87604 2.96879 4.84575 2.98134C4.81546 2.99389 4.78299 3.00035 4.7502 3.00035H2.24991C2.21712 3.00035 2.18466 2.99389 2.15437 2.98134C2.12407 2.96879 2.09655 2.9504 2.07336 2.92721C2.05018 2.90402 2.03179 2.87648 2.01924 2.84618C2.00669 2.81589 2.00023 2.78341 2.00023 2.75061V2.25044ZM2.00023 4.25114C2.00023 4.1849 2.02654 4.12138 2.07336 4.07455C2.12019 4.02771 2.18369 4.0014 2.24991 4.0014H4.7502C4.78299 4.0014 4.81546 4.00786 4.84575 4.02041C4.87604 4.03296 4.90357 4.05136 4.92675 4.07455C4.94994 4.09774 4.96833 4.12527 4.98088 4.15557C4.99343 4.18587 4.99988 4.21834 4.99988 4.25114V4.75131C4.99988 4.78411 4.99343 4.81658 4.98088 4.84688C4.96833 4.87718 4.94994 4.90471 4.92675 4.9279C4.90357 4.95109 4.87604 4.96949 4.84575 4.98204C4.81546 4.99459 4.78299 5.00105 4.7502 5.00105H2.24991C2.21712 5.00105 2.18466 4.99459 2.15437 4.98204C2.12407 4.96949 2.09655 4.95109 2.07336 4.9279C2.05018 4.90471 2.03179 4.87718 2.01924 4.84688C2.00669 4.81658 2.00023 4.78411 2.00023 4.75131V4.25114ZM8.02541 12.0028H9.50041C9.63303 12.0028 9.76022 12.0555 9.854 12.1493C9.94778 12.2431 10.0005 12.3703 10.0005 12.503C10.0005 12.6356 9.94778 12.7628 9.854 12.8566C9.76022 12.9504 9.63303 13.0031 9.50041 13.0031H8.02541C7.77468 13.0039 7.52873 12.9345 7.3154 12.8027C7.10208 12.6709 6.92987 12.482 6.81828 12.2574C6.79034 12.1967 6.74558 12.1452 6.68931 12.1092C6.63303 12.0731 6.5676 12.0539 6.50076 12.0539C6.43545 12.0527 6.3712 12.0704 6.31564 12.1047C6.26009 12.1391 6.21559 12.1887 6.18743 12.2476L5.94755 12.7268C5.90608 12.8099 5.8423 12.8797 5.76336 12.9285C5.68442 12.9773 5.59345 13.0032 5.50064 13.0031H5.46497C5.36632 12.9963 5.27193 12.9603 5.19384 12.8996C5.11574 12.8389 5.05747 12.7564 5.02646 12.6625L4.50052 11.085L4.16832 12.0797C4.0787 12.3487 3.9067 12.5825 3.67672 12.7481C3.44673 12.9138 3.17044 13.0027 2.88705 13.0024H2.50029C2.36767 13.0024 2.24048 12.9497 2.1467 12.8559C2.05292 12.7621 2.00023 12.6349 2.00023 12.5023C2.00023 12.3696 2.05292 12.2424 2.1467 12.1486C2.24048 12.0548 2.36767 12.0021 2.50029 12.0021H2.88775C2.96123 12.0022 3.03288 11.9791 3.09251 11.9362C3.15214 11.8932 3.19674 11.8326 3.21996 11.7629L3.78855 10.0553C3.8385 9.90603 3.93408 9.77627 4.06178 9.68433C4.18948 9.5924 4.34284 9.54293 4.50017 9.54293C4.65751 9.54293 4.81087 9.5924 4.93857 9.68433C5.06627 9.77627 5.16185 9.90603 5.2118 10.0553L5.64541 11.3571C5.80562 11.2378 5.98945 11.1542 6.18461 11.1117C6.37976 11.0692 6.58174 11.0689 6.77701 11.1109C6.97228 11.1528 7.15635 11.236 7.31689 11.3548C7.47743 11.4736 7.61074 11.6254 7.70789 11.7999C7.73661 11.86 7.78157 11.9109 7.83769 11.9467C7.8938 11.9826 7.95883 12.002 8.02541 12.0028ZM11.7811 3.28227L8.72199 0.21896C8.65215 0.149283 8.56925 0.0940766 8.47804 0.0565037C8.38683 0.0189308 8.28911 -0.000269597 8.19046 2.85945e-06H7.99953V4.0007H11.9993V3.81043C11.9993 3.61242 11.9209 3.42248 11.7811 3.28227Z" fill="currentColor" />
30
+ </svg>
31
+ )
32
+ }
33
+ if (kind === 'calendar') {
34
+ return (
35
+ <svg viewBox="0 0 16 16" aria-hidden="true" className="size-4 shrink-0 text-fg-subtle">
36
+ <path d="M13.6997 1.62109H12.3438V4.7929H11.0824V1.62109H5.80556V4.7929H4.54417V1.62109H3.18818C1.95833 1.62109 0.949219 2.58774 0.949219 3.77591V5.76961H15.9492V3.77591C15.9492 2.58774 14.9401 1.62109 13.6997 1.62109Z" fill="currentColor" />
37
+ <path d="M14.3725 6.97754H0.949219V13.8347C0.949219 15.0229 1.95833 15.9895 3.19869 15.9895H13.5316C14.8665 15.9895 15.9492 14.9524 15.9492 13.6736V6.97754H14.3725ZM5.10129 10.6931H7.81327V8.09522H9.07466V10.6931H11.7866V11.9014H9.07466V14.4993H7.81327V11.9014H5.10129V10.6931Z" fill="currentColor" />
38
+ <path d="M12.3542 0H11.0928V1.61108H12.3542V0Z" fill="currentColor" />
39
+ <path d="M5.81607 0H4.55469V1.61108H5.81607V0Z" fill="currentColor" />
40
+ </svg>
41
+ )
42
+ }
43
+ if (kind === 'sparkle') {
44
+ return (
45
+ <svg viewBox="0 0 16 16" aria-hidden="true" className="size-4 shrink-0 text-fg">
46
+ <path d="M8 2V6M8 10V14M2 8H6M10 8H14" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
47
+ <path d="M11.657 4.343L13.071 2.929M2.929 13.071L4.343 11.657M13.071 13.071L11.657 11.657M4.343 4.343L2.929 2.929" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
48
+ </svg>
49
+ )
50
+ }
51
+ return (
52
+ <svg viewBox="0 0 16 16" aria-hidden="true" className="size-4 shrink-0 text-fg-subtle">
53
+ <path d="M16 7.99954C16.0001 9.58181 15.531 11.1286 14.652 12.4442C13.773 13.7599 12.5236 14.7853 11.0618 15.3909C9.59999 15.9965 7.99144 16.155 6.43956 15.8463C4.88768 15.5377 3.46218 14.7758 2.34331 13.657C1.22445 12.5382 0.462474 11.1127 0.153755 9.56089C-0.154964 8.00903 0.00343586 6.40047 0.608923 4.93864C1.21441 3.4768 2.23979 2.22735 3.55539 1.34827C4.871 0.469203 6.41773 1.57579e-08 8 1.31562e-08C9.05055 -6.02353e-05 10.0908 0.20681 11.0614 0.608797C12.032 1.01078 12.914 1.60002 13.6568 2.34285C14.3997 3.08568 14.989 3.96756 15.391 4.93814C15.7931 5.90872 16 6.94899 16 7.99954ZM7.07467 12.2353L13.0102 6.3021C13.0581 6.25417 13.0962 6.19728 13.1221 6.13466C13.148 6.07204 13.1614 6.00492 13.1614 5.93715C13.1614 5.86937 13.148 5.80226 13.1221 5.73964C13.0962 5.67702 13.0581 5.62012 13.0102 5.5722L12.2803 4.84046C12.2324 4.79254 12.1755 4.75452 12.1129 4.72858C12.0502 4.70264 11.9831 4.68929 11.9154 4.68929C11.8476 4.68929 11.7805 4.70264 11.7178 4.72858C11.6552 4.75452 11.5983 4.79254 11.5504 4.84046L6.70995 9.68092L4.45005 7.42103C4.40213 7.37311 4.34523 7.33509 4.28261 7.30915C4.22 7.28321 4.15288 7.26986 4.0851 7.26986C4.01733 7.26986 3.95021 7.28321 3.88759 7.30915C3.82498 7.33509 3.76808 7.37311 3.72015 7.42103L2.9898 8.15047C2.94187 8.1984 2.90385 8.2553 2.87791 8.31791C2.85198 8.38053 2.83863 8.44765 2.83863 8.51542C2.83863 8.5832 2.85198 8.65032 2.87791 8.71293C2.90385 8.77555 2.94187 8.83245 2.9898 8.88037L6.34477 12.2353C6.39269 12.2833 6.44959 12.3213 6.51221 12.3472C6.57482 12.3732 6.64194 12.3865 6.70972 12.3865C6.77749 12.3865 6.84461 12.3732 6.90723 12.3472C6.96984 12.3213 7.02674 12.2833 7.07467 12.2353Z" fill="currentColor" />
54
+ </svg>
55
+ )
56
+ }
@@ -1,9 +1,59 @@
1
- import { Table } from './table'
2
- const columns = [{ key: 'name', header: 'Name' }, { key: 'city', header: 'City' }]
3
- const data = [{ name: 'Annual report', city: 'Prague' }]
1
+ import { useState } from 'react'
2
+ import {
3
+ nextTableSort,
4
+ Table,
5
+ TableBody,
6
+ TableCell,
7
+ TableHead,
8
+ TableHeaderCell,
9
+ TableRoot,
10
+ TableRow,
11
+ TableRowHeader,
12
+ TableScroll,
13
+ TableSortHeader,
14
+ type TableSortState,
15
+ } from './table'
16
+ import { TableHeaderIcon } from './table-header-icon'
17
+
18
+ type Task = { task: string; assignee: string; status: string; due: string }
19
+ const data: Task[] = [
20
+ { task: 'Annual report cover', assignee: 'Eva Novak', status: 'In review', due: 'Oct 09, 2026' },
21
+ { task: 'Spring campaign banners', assignee: 'Petr Dvorak', status: 'To do', due: 'Oct 21, 2026' },
22
+ ]
23
+ const columns = [
24
+ { key: 'task', header: 'Task', icon: <TableHeaderIcon kind="check" />, sortable: true, width: '40%' },
25
+ { key: 'assignee', header: 'Assignee', icon: <TableHeaderIcon kind="user" />, sortable: true },
26
+ { key: 'status', header: 'Status', icon: <TableHeaderIcon kind="check" />, sortable: true },
27
+ { key: 'due', header: 'Due Date', icon: <TableHeaderIcon kind="calendar" /> },
28
+ ]
29
+
30
+ function Composed() {
31
+ const [sort, setSort] = useState<TableSortState<'name'> | null>(null)
32
+ return (
33
+ <TableScroll>
34
+ <TableRoot aria-label="Roles">
35
+ <TableHead>
36
+ <tr>
37
+ <TableSortHeader label="Role" direction={sort?.key === 'name' ? sort.dir : null} onSort={() => setSort((previous) => nextTableSort(previous, 'name'))} />
38
+ <TableHeaderCell align="right">Members</TableHeaderCell>
39
+ </tr>
40
+ </TableHead>
41
+ <TableBody>
42
+ <TableRow>
43
+ <TableRowHeader>Editor</TableRowHeader>
44
+ <TableCell align="right">4</TableCell>
45
+ </TableRow>
46
+ </TableBody>
47
+ </TableRoot>
48
+ </TableScroll>
49
+ )
50
+ }
51
+
4
52
  export const examples = {
5
- default: () => <Table columns={columns} data={data} aria-label="Projects" />,
6
- worksheet: () => <Table appearance="worksheet" columns={columns} data={data} aria-label="CSV preview" />,
7
- empty: () => <Table appearance="worksheet" columns={columns} data={[]} emptyMessage="No preview rows available." aria-label="Empty CSV" />,
53
+ default: () => <Table columns={columns} data={data} aria-label="Tasks" />,
54
+ sortable: () => <Table columns={columns} data={data} enableSorting onRowClick={() => {}} aria-label="Tasks" />,
55
+ plain: () => <Table columns={[{ key: 'task', header: 'Task' }, { key: 'due', header: 'Due Date' }]} data={data} aria-label="Tasks" />,
56
+ empty: () => <Table columns={columns} data={[]} emptyMessage="No tasks yet." aria-label="Tasks" />,
57
+ composed: () => <Composed />,
8
58
  }
9
- export const meta = { category: 'Composite', description: 'Default data table and the source Manager worksheet appearance with monospace column labels.' }
59
+ export const meta = { category: 'Composite', description: 'The task-table look: mono header labels with optional glyphs, row and cell rules, sortable headers, pressable rows, and the parts for custom structures.' }
@@ -1,33 +1,154 @@
1
- import { useMemo, useState, type CSSProperties, type HTMLAttributes, type ReactNode } from 'react'
2
- import { ChevronDownIcon, ChevronUpIcon } from './icons'
3
- export const TABLE_APPEARANCES = ['default', 'worksheet', 'team'] as const
4
- export type TableAppearance = (typeof TABLE_APPEARANCES)[number]
1
+ import { useMemo, useState, type CSSProperties, type HTMLAttributes, type ReactNode, type ThHTMLAttributes } from 'react'
2
+ import { uic } from '../utils/uic'
5
3
 
6
4
  /**
7
- * Table — the design-system data table (port of gs-platform's `GSTable`). A light,
8
- * presentational grid: a header row of (optionally sortable) column labels over a
9
- * body of rows. Rows can be clickable (whole-row press → `onRowClick`, keyboard
10
- * accessible). Sorting is CLIENT-SIDE and OPTIONAL: enable it with `enableSorting`
11
- * and mark the sortable columns; clicking a sortable header cycles asc → desc.
5
+ * Table: the design-system data table, in the look of gs-platform's task GSTable. A
6
+ * flat surface, mono header labels in the muted ink (optionally led by a
7
+ * `TableHeaderIcon`), horizontal rules between rows, vertical rules between body
8
+ * cells, 16px cell padding and rows as tall as their content.
12
9
  *
13
- * Presentational only (hard rule #3): no data fetching, no domain coupling. The
14
- * caller supplies `columns` (how to render + sort each cell) and `data` (the rows).
15
- * Styling = Tailwind + design-token CSS vars, matching the rest of podoba.
10
+ * Two ways in:
11
+ * - `<Table columns data />` for a plain data grid: the caller supplies how each
12
+ * column renders and sorts, the table owns the sort state and the row press.
13
+ * - The parts (`TableScroll`, `TableRoot`, `TableHead`, `TableBody`, `TableRow`,
14
+ * `TableHeaderCell`, `TableSortHeader`, `TableCell`, `TableEmptyRow`) for a table
15
+ * whose structure the column API cannot express (row headers, colgroups, skeleton
16
+ * rows, sorting owned by the caller). Both render the same markup and classes.
17
+ *
18
+ * Presentational only: no data fetching, no domain coupling.
16
19
  */
17
20
  export type TableAlign = 'left' | 'right' | 'center'
21
+ export type TableSortDirection = 'asc' | 'desc'
22
+ export type TableSortState<Key extends string = string> = { key: Key; dir: TableSortDirection }
23
+
24
+ const align = {
25
+ left: 'text-left',
26
+ right: 'text-right',
27
+ center: 'text-center',
28
+ }
29
+
30
+ /** Horizontal scroll container on the table surface; wide tables scroll, never squash. */
31
+ export const TableScroll = uic('div', { displayName: 'TableScroll', baseClass: 'w-full min-w-0 overflow-x-auto bg-surface' })
32
+
33
+ export const TableRoot = uic('table', {
34
+ displayName: 'TableRoot',
35
+ baseClass: 'w-full border-collapse border-b border-border-muted text-left text-small leading-4.5 text-fg',
36
+ })
37
+
38
+ export const TableHead = uic('thead', { displayName: 'TableHead', baseClass: 'border-b border-border-muted' })
39
+
40
+ export const TableBody = uic('tbody', { displayName: 'TableBody' })
41
+
42
+ /** A body row. `interactive` adds the pointer, hover fill and inset focus ring of a pressable row. */
43
+ export const TableRow = uic('tr', {
44
+ displayName: 'TableRow',
45
+ baseClass: 'border-b border-border-muted outline-none last:border-b-0',
46
+ variants: {
47
+ interactive: {
48
+ true: 'cursor-pointer transition-colors duration-150 ease-in-out hover:bg-surface-muted focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring motion-reduce:transition-none',
49
+ },
50
+ },
51
+ })
52
+
53
+ /** A column header cell: mono label in the muted ink. A row's own header is `TableRowHeader`. */
54
+ export const TableHeaderCell = uic('th', {
55
+ displayName: 'TableHeaderCell',
56
+ baseClass: 'p-4 align-middle font-mono text-small leading-4.5 font-normal tracking-normal text-fg-muted',
57
+ variants: { align },
58
+ defaultVariants: { align: 'left' },
59
+ defaultProps: { scope: 'col' },
60
+ })
61
+
62
+ /**
63
+ * Icon + label row inside a header cell that does not sort. `align-top` keeps its text
64
+ * on the same line as a plain-text header next to it; a baseline-aligned inline-flex
65
+ * box sits a pixel or two lower.
66
+ */
67
+ export const TableHeaderLabel = uic('span', { displayName: 'TableHeaderLabel', baseClass: 'inline-flex items-center gap-2 whitespace-nowrap align-top' })
68
+
69
+ const cellClass = 'border-l border-border-muted p-4 align-middle text-small leading-4.5 font-normal text-fg first:border-l-0'
70
+
71
+ export const TableCell = uic('td', {
72
+ displayName: 'TableCell',
73
+ baseClass: cellClass,
74
+ variants: { align },
75
+ defaultVariants: { align: 'left' },
76
+ })
77
+
78
+ /** The cell that names its row (`<th scope="row">`): semantically a header, visually a body cell. */
79
+ export const TableRowHeader = uic('th', {
80
+ displayName: 'TableRowHeader',
81
+ baseClass: cellClass,
82
+ variants: { align },
83
+ defaultVariants: { align: 'left' },
84
+ defaultProps: { scope: 'row' },
85
+ })
86
+
87
+ /** The single full-width row shown in place of the body when there is nothing to list. */
88
+ export function TableEmptyRow({ colSpan, children }: { colSpan: number; children: ReactNode }) {
89
+ return (
90
+ <tr>
91
+ <td colSpan={colSpan} className="p-4 text-small leading-4.5 text-fg-muted">{children}</td>
92
+ </tr>
93
+ )
94
+ }
95
+
96
+ export type TableSortHeaderProps = Omit<ThHTMLAttributes<HTMLTableCellElement>, 'children' | 'align'> & {
97
+ label: ReactNode
98
+ /** Leading glyph, usually a `TableHeaderIcon`. */
99
+ icon?: ReactNode
100
+ /** Direction when this column is the active sort, else `null`. */
101
+ direction: TableSortDirection | null
102
+ onSort: () => void
103
+ align?: TableAlign
104
+ }
105
+
106
+ /**
107
+ * A sortable header: the label is the button's accessible name, the arrow is
108
+ * decorative and `aria-sort` on the `<th>` announces the direction. No idle sort
109
+ * glyph; only the active direction shows.
110
+ */
111
+ export function TableSortHeader({ label, icon, direction, onSort, align: alignment = 'left', ...rest }: TableSortHeaderProps) {
112
+ return (
113
+ <TableHeaderCell
114
+ align={alignment}
115
+ aria-sort={direction === 'asc' ? 'ascending' : direction === 'desc' ? 'descending' : 'none'}
116
+ {...rest}
117
+ >
118
+ <button
119
+ type="button"
120
+ onClick={onSort}
121
+ className={`inline-flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-sm align-top font-mono font-normal tracking-normal outline-none hover:text-fg focus-visible:ring-2 focus-visible:ring-ring ${alignment === 'right' ? 'flex-row-reverse' : ''}`}
122
+ >
123
+ {icon}
124
+ {label}
125
+ {direction ? <span aria-hidden="true" className="text-fg">{direction === 'asc' ? '↑' : '↓'}</span> : null}
126
+ </button>
127
+ </TableHeaderCell>
128
+ )
129
+ }
130
+
131
+ /** The sort cycle every table shares: unsorted, ascending, descending, unsorted. */
132
+ export function nextTableSort<Key extends string>(previous: TableSortState<Key> | null, key: Key): TableSortState<Key> | null {
133
+ if (previous?.key !== key) return { key, dir: 'asc' }
134
+ if (previous.dir === 'asc') return { key, dir: 'desc' }
135
+ return null
136
+ }
18
137
 
19
138
  export type TableColumn<Row> = {
20
139
  /** Stable column id (also the default sort key). */
21
140
  key: string
22
141
  /** Header label. */
23
142
  header: ReactNode
143
+ /** Leading header glyph, usually a `TableHeaderIcon`. */
144
+ icon?: ReactNode
24
145
  /** Cell renderer. Defaults to `String(row[key])` when omitted. */
25
146
  render?: (row: Row) => ReactNode
26
147
  /** Whether this column participates in sorting (needs `enableSorting` on the table). */
27
148
  sortable?: boolean
28
149
  /**
29
150
  * Value used to sort this column (string / number). Defaults to the raw
30
- * `row[key]` when the row is an object, else the stringified render output.
151
+ * `row[key]` when the row is an object.
31
152
  */
32
153
  sortValue?: (row: Row) => string | number
33
154
  /** Horizontal alignment of the header + cells (default `left`). */
@@ -37,30 +158,25 @@ export type TableColumn<Row> = {
37
158
  }
38
159
 
39
160
  export type TableProps<Row> = {
40
- /** Worksheet matches Manager's plain GSTable; default preserves existing consumers. */
41
- appearance?: TableAppearance
42
161
  columns: TableColumn<Row>[]
43
162
  data: Row[]
44
163
  /** Stable per-row key. Defaults to the row index (fine for static lists). */
45
164
  getRowKey?: (row: Row, index: number) => string
46
165
  /** Additional semantic/event props for each rendered row. */
47
- getRowProps?: (row: Row) => HTMLAttributes<HTMLTableRowElement>
48
- columnTemplate?: string
166
+ getRowProps?: (row: Row) => HTMLAttributes<HTMLTableRowElement> & Record<`data-${string}`, string | undefined>
49
167
  /** Enable client-side sorting on `sortable` columns. */
50
168
  enableSorting?: boolean
51
- /** Whole-row press handler — renders rows as interactive (hover + keyboard). */
169
+ /** Whole-row press handler: renders rows as interactive (hover + keyboard). */
52
170
  onRowClick?: (row: Row) => void
53
171
  /** Message shown in place of the body when `data` is empty. */
54
172
  emptyMessage?: ReactNode
55
173
  /** Accessible name for the table. */
56
174
  'aria-label'?: string
175
+ /** Classes for the scroll container. */
57
176
  className?: string
58
- }
59
-
60
- const ALIGN_CLASS: Record<TableAlign, string> = {
61
- left: 'text-left',
62
- right: 'text-right',
63
- center: 'text-center',
177
+ /** Classes for the `<table>` itself, e.g. `min-w-*` or `table-fixed`. */
178
+ tableClassName?: string
179
+ 'data-testid'?: string
64
180
  }
65
181
 
66
182
  function defaultSortValue<Row>(column: TableColumn<Row>, row: Row): string | number {
@@ -77,29 +193,22 @@ export function Table<Row>({
77
193
  data,
78
194
  getRowKey,
79
195
  getRowProps,
80
- columnTemplate,
81
196
  enableSorting = false,
82
197
  onRowClick,
83
198
  emptyMessage = 'No rows.',
84
199
  className,
85
- appearance = 'default',
200
+ tableClassName,
201
+ 'data-testid': testId,
86
202
  ...aria
87
203
  }: TableProps<Row>) {
88
- const [sort, setSort] = useState<{ key: string; dir: 'asc' | 'desc' } | null>(null)
89
-
90
- const toggleSort = (key: string) => {
91
- setSort((prev) => {
92
- if (prev?.key !== key) return { key, dir: 'asc' }
93
- return { key, dir: prev.dir === 'asc' ? 'desc' : 'asc' }
94
- })
95
- }
204
+ const [sort, setSort] = useState<TableSortState | null>(null)
96
205
 
97
206
  const sorted = useMemo(() => {
98
207
  if (!enableSorting || !sort) return data
99
208
  const column = columns.find((c) => c.key === sort.key)
100
209
  if (!column) return data
101
210
  const dir = sort.dir === 'asc' ? 1 : -1
102
- // Copy before sort — never mutate the caller's array.
211
+ // Copy before sort: never mutate the caller's array.
103
212
  return [...data].sort((a, b) => {
104
213
  const av = defaultSortValue(column, a)
105
214
  const bv = defaultSortValue(column, b)
@@ -110,101 +219,73 @@ export function Table<Row>({
110
219
 
111
220
  const rowKey = getRowKey ?? ((_row: Row, index: number) => String(index))
112
221
  const interactive = Boolean(onRowClick)
113
- const worksheet = appearance === 'worksheet'
114
- const team = appearance === 'team'
115
- const gridTemplate = columnTemplate ?? `repeat(${columns.length}, minmax(0, 1fr))`
116
222
 
117
223
  return (
118
- <div className={['w-full overflow-x-auto', className].filter(Boolean).join(' ')}>
119
- <table style={team ? { '--table-columns': gridTemplate } as CSSProperties : undefined} className={`w-full border-collapse text-small ${worksheet ? 'border-b border-border font-normal leading-4.5' : ''} ${team ? 'block font-normal leading-4.5' : ''}`} {...aria}>
120
- <thead className={team ? 'block' : undefined}>
121
- <tr className={`${worksheet ? '' : 'border-b border-border'} ${team ? 'grid grid-cols-[var(--table-columns)] gap-3 bg-surface-muted px-4 max-[1023px]:hidden' : ''}`}>
224
+ <TableScroll className={className}>
225
+ <TableRoot className={tableClassName} data-testid={testId} {...aria}>
226
+ <TableHead>
227
+ <tr>
122
228
  {columns.map((column) => {
123
- const align = column.align ?? 'left'
124
- const canSort = enableSorting && column.sortable
125
- const active = sort?.key === column.key
229
+ const alignment = column.align ?? 'left'
230
+ const style: CSSProperties | undefined = column.width ? { width: column.width } : undefined
231
+ if (enableSorting && column.sortable) {
232
+ return (
233
+ <TableSortHeader
234
+ key={column.key}
235
+ style={style}
236
+ align={alignment}
237
+ label={column.header}
238
+ icon={column.icon}
239
+ direction={sort?.key === column.key ? sort.dir : null}
240
+ onSort={() => setSort((previous) => nextTableSort(previous, column.key))}
241
+ />
242
+ )
243
+ }
126
244
  return (
127
- <th
128
- key={column.key}
129
- scope="col"
130
- style={column.width ? { width: column.width } : undefined}
131
- aria-sort={
132
- canSort ? (active ? (sort?.dir === 'asc' ? 'ascending' : 'descending') : 'none') : undefined
133
- }
134
- className={`${ALIGN_CLASS[align]} ${worksheet ? 'border-0 px-3 py-4 align-middle font-mono text-small font-normal leading-4.5 tracking-normal text-fg normal-case bg-surface whitespace-nowrap' : team ? 'border-0 px-0 py-3 align-middle font-mono text-small font-normal leading-4.5 tracking-normal text-fg normal-case whitespace-nowrap' : 'px-4 py-3 text-label font-medium tracking-wide text-fg-muted uppercase'}`}
135
- >
136
- {canSort ? (
137
- <button
138
- type="button"
139
- onClick={() => toggleSort(column.key)}
140
- className={`inline-flex cursor-pointer items-center gap-1 outline-none transition-colors hover:text-fg focus-visible:text-fg ${
141
- align === 'right' ? 'flex-row-reverse' : ''
142
- } ${active ? 'text-fg' : ''}`}
143
- >
144
- {column.header}
145
- {active ? (
146
- sort?.dir === 'asc' ? (
147
- <ChevronUpIcon className="h-3.5 w-3.5" />
148
- ) : (
149
- <ChevronDownIcon className="h-3.5 w-3.5" />
150
- )
151
- ) : null}
152
- </button>
153
- ) : (
154
- column.header
155
- )}
156
- </th>
245
+ <TableHeaderCell key={column.key} style={style} align={alignment}>
246
+ {column.icon ? <TableHeaderLabel>{column.icon}{column.header}</TableHeaderLabel> : column.header}
247
+ </TableHeaderCell>
157
248
  )
158
249
  })}
159
250
  </tr>
160
- </thead>
161
- <tbody className={team ? 'block' : undefined}>
251
+ </TableHead>
252
+ <TableBody>
162
253
  {sorted.length === 0 ? (
163
- <tr>
164
- <td colSpan={columns.length} className={worksheet ? 'border-y border-border px-6 py-4 text-small font-normal leading-4.5 text-fg' : 'px-4 py-10 text-center text-small text-fg-muted'}>
165
- {emptyMessage}
166
- </td>
167
- </tr>
254
+ <TableEmptyRow colSpan={columns.length}>{emptyMessage}</TableEmptyRow>
168
255
  ) : (
169
256
  sorted.map((row, index) => {
170
- const rowProps = getRowProps?.(row)
171
- return (
172
- <tr
173
- key={rowKey(row, index)}
174
- {...rowProps}
175
- {...(interactive
176
- ? {
177
- tabIndex: 0,
178
- role: 'button',
179
- onClick: () => onRowClick?.(row),
180
- onKeyDown: (event: React.KeyboardEvent) => {
181
- if (event.key === 'Enter' || event.key === ' ') {
182
- event.preventDefault()
183
- onRowClick?.(row)
184
- }
185
- },
186
- }
187
- : {})}
188
- className={`${worksheet ? 'min-h-15' : team ? 'grid grid-cols-[var(--table-columns)] gap-3 border-b border-border px-4 py-3 text-label font-normal leading-4.5 max-[1023px]:grid max-[1023px]:grid-cols-1 max-[1023px]:gap-2 max-[1023px]:p-4' : 'border-b border-border/60'} ${team ? 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring' : ''} outline-none ${
189
- interactive
190
- ? 'cursor-pointer transition-colors hover:bg-surface-muted focus-visible:bg-surface-muted focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring'
191
- : ''
192
- }${rowProps?.className ? ` ${rowProps.className}` : ''}`}
193
- >
194
- {columns.map((column) => {
195
- const align = column.align ?? 'left'
196
- return (
197
- <td key={column.key} className={`${ALIGN_CLASS[align]} ${worksheet ? 'border border-border first:border-l-0 last:border-r-0 px-6 py-4 text-small font-normal leading-4.5' : team ? 'px-0 py-0 align-middle text-small font-normal leading-4.5 max-[1023px]:block' : 'px-4 py-3'} align-middle text-fg`}>
257
+ const rowProps = getRowProps?.(row)
258
+ return (
259
+ <TableRow
260
+ key={rowKey(row, index)}
261
+ {...rowProps}
262
+ interactive={interactive}
263
+ {...(interactive
264
+ ? {
265
+ // A pressable row is one control; callers name it via `getRowProps` (`aria-label`).
266
+ tabIndex: 0,
267
+ role: 'button',
268
+ onClick: () => onRowClick?.(row),
269
+ onKeyDown: (event: React.KeyboardEvent) => {
270
+ if (event.key === 'Enter' || event.key === ' ') {
271
+ event.preventDefault()
272
+ onRowClick?.(row)
273
+ }
274
+ },
275
+ }
276
+ : {})}
277
+ >
278
+ {columns.map((column) => (
279
+ <TableCell key={column.key} align={column.align ?? 'left'}>
198
280
  {column.render ? column.render(row) : String(defaultSortValue(column, row))}
199
- </td>
200
- )
201
- })}
202
- </tr>
203
- )
281
+ </TableCell>
282
+ ))}
283
+ </TableRow>
284
+ )
204
285
  })
205
286
  )}
206
- </tbody>
207
- </table>
208
- </div>
287
+ </TableBody>
288
+ </TableRoot>
289
+ </TableScroll>
209
290
  )
210
291
  }
package/src/index.ts CHANGED
@@ -82,6 +82,7 @@ export * from "./components/tile";
82
82
  export * from "./components/preview-info-card";
83
83
  export * from "./components/empty-panel-action";
84
84
  export * from "./components/table";
85
+ export * from "./components/table-header-icon";
85
86
  export * from "./components/dashboard-grid";
86
87
  export * from "./components/task-approval-modal";
87
88
  export * from "./components/request-changes-modal";