@nickrobison/colophon-table 0.0.0-stage → 0.1.0

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.
Files changed (59) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +55 -2
  3. package/package.json +72 -3
  4. package/src/components/CphSkeleton.test.tsx +145 -0
  5. package/src/components/CphSkeleton.tsx +42 -0
  6. package/src/components/CphTableEmpty.test.tsx +122 -0
  7. package/src/components/CphTableEmpty.tsx +42 -0
  8. package/src/components/DataTable/CphDataTable.test.tsx +408 -0
  9. package/src/components/DataTable/CphDataTable.tsx +121 -0
  10. package/src/components/DataTable/pinnedOffsets.ts +94 -0
  11. package/src/components/FilterMultiSelect/CphTableFilterMultiSelect.test.tsx +172 -0
  12. package/src/components/FilterMultiSelect/CphTableFilterMultiSelect.tsx +132 -0
  13. package/src/components/FilterRange/CphTableFilterRange.test.tsx +154 -0
  14. package/src/components/FilterRange/CphTableFilterRange.tsx +109 -0
  15. package/src/components/MobileCards/CphMobileCards.test.tsx +174 -0
  16. package/src/components/MobileCards/CphMobileCards.tsx +117 -0
  17. package/src/components/Pagination/CphCursorPagination.test.tsx +51 -0
  18. package/src/components/Pagination/CphCursorPagination.tsx +74 -0
  19. package/src/components/Pagination/CphPagination.test.tsx +98 -0
  20. package/src/components/Pagination/CphPagination.tsx +94 -0
  21. package/src/components/RowDetail/CphRowDetail.test.tsx +182 -0
  22. package/src/components/RowDetail/CphRowDetail.tsx +66 -0
  23. package/src/components/SimpleTable/CphSimpleTable.test.tsx +235 -0
  24. package/src/components/SimpleTable/CphSimpleTable.tsx +369 -0
  25. package/src/components/SortFilterSheet/CphSortFilterSheet.test.tsx +156 -0
  26. package/src/components/SortFilterSheet/CphSortFilterSheet.tsx +131 -0
  27. package/src/components/StatusChip/CphStatusChip.test.tsx +43 -0
  28. package/src/components/StatusChip/CphStatusChip.tsx +33 -0
  29. package/src/components/Summary/CphTableSummary.test.tsx +486 -0
  30. package/src/components/Summary/CphTableSummary.tsx +130 -0
  31. package/src/components/TableHead/CphTableHead.test.tsx +52 -0
  32. package/src/components/TableHead/CphTableHead.tsx +129 -0
  33. package/src/components/TableHead/HeaderCell.test.tsx +880 -0
  34. package/src/components/TableHead/HeaderCell.tsx +221 -0
  35. package/src/components/TableRow/Cell.test.tsx +306 -0
  36. package/src/components/TableRow/Cell.tsx +74 -0
  37. package/src/components/TableRow/CphTableRow.test.tsx +90 -0
  38. package/src/components/TableRow/CphTableRow.tsx +17 -0
  39. package/src/components/Toolbar/CphToolbar.test.tsx +150 -0
  40. package/src/components/Toolbar/CphToolbar.tsx +138 -0
  41. package/src/components.css +593 -0
  42. package/src/index.ts +69 -0
  43. package/src/table/cellRenderers.tsx +88 -0
  44. package/src/table/column.test.tsx +277 -0
  45. package/src/table/column.tsx +36 -0
  46. package/src/table/features.ts +69 -0
  47. package/src/table/pageSize.test.ts +128 -0
  48. package/src/table/pageSize.ts +47 -0
  49. package/src/table/summary.test.tsx +446 -0
  50. package/src/table/summary.ts +94 -0
  51. package/src/table/useCphTable.ts +90 -0
  52. package/src/table/useCphTableState.test.tsx +697 -0
  53. package/src/table/useCphTableState.ts +412 -0
  54. package/src/table-tokens.css +48 -0
  55. package/src/theme/CphTableDensity.test.tsx +53 -0
  56. package/src/theme/CphTableDensity.tsx +24 -0
  57. package/src/theme/cphTableDensityContext.ts +24 -0
  58. package/src/utils/composeClassName.test.ts +26 -0
  59. package/src/utils/composeClassName.ts +28 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Colophon contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,56 @@
1
- # Temporary Holding Version
1
+ # @nickrobison/colophon-table
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Colophon data tables — dense, comparison-focused ledger tables.
4
+
5
+ ## Status: in development (unreleased)
6
+
7
+ This package implements the table engine (TanStack Table v9) and the full
8
+ component suite — `CphDataTable`, sortable/pinnable headers, row selection
9
+ and expansion, aggregate summary footer, skeleton/empty states, pagination,
10
+ toolbar, mobile cards, and sort/filter sheet — with unit, Storybook, and
11
+ Playwright coverage. It is not yet released; APIs may still change before
12
+ the first publish.
13
+
14
+ ## What is planned
15
+
16
+ - A headless table engine built on [TanStack Table](https://tanstack.com/table) v9.
17
+ - Design-system primitives: sortable headers, a pinned first column, expandable rows, row selection,
18
+ an opt-in aggregate summary row, skeleton and empty states, pagination, a toolbar, mobile stacked
19
+ cards, and a mobile sort/filter sheet.
20
+ - A `--cph-table-*` token layer derived from the existing `@nickrobison/colophon` tokens, with full
21
+ light and dark support and three density modes (Comfortable / Compact / Dense).
22
+
23
+ ## Peer dependency
24
+
25
+ This package peer-depends on `@nickrobison/colophon` for its design tokens and shared primitives.
26
+ Import the token layer before the component layer:
27
+
28
+ ```ts
29
+ import "@nickrobison/colophon/foundation.css";
30
+ import "@nickrobison/colophon/components.css";
31
+ import "@nickrobison/colophon-table/table-tokens.css";
32
+ import "@nickrobison/colophon-table/components.css";
33
+ ```
34
+
35
+ ## Scripts
36
+
37
+ | Script | Purpose |
38
+ | -------------------- | ---------------------------------------------------- |
39
+ | `build` | Type-check, then bundle the library with Vite. |
40
+ | `lint` | `tsc --noEmit` against the package tsconfig. |
41
+ | `test` | Vitest with V8 coverage. |
42
+ | `storybook` | Storybook dev server on port 6409. |
43
+ | `build-storybook` | Static Storybook build. |
44
+ | `test-storybook:ci` | Serve the built Storybook and run interaction tests. |
45
+ | `test:e2e` | Playwright end-to-end suite (port 6408). |
46
+ | `playwright:install` | Install the Chromium build Playwright needs. |
47
+
48
+ ## Conventions
49
+
50
+ Built with `react-aria-components` — do not import directly from `react-aria` or `react-stately`.
51
+ Format with the repository's Oxfmt configuration. Run the workspace gates before submitting:
52
+ `pnpm run format:check`, `pnpm run lint`, `pnpm run test`, `pnpm run build`.
53
+
54
+ ## License
55
+
56
+ MIT
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@nickrobison/colophon-table",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Colophon data tables — dense, comparison-focused ledger tables.",
5
+ "keywords": [
6
+ "design-system",
7
+ "table",
8
+ "tanstack-table"
9
+ ],
10
+ "license": "MIT",
11
+ "files": [
12
+ "src",
13
+ "README.md",
14
+ "LICENSE.md"
15
+ ],
16
+ "type": "module",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./src/index.ts",
20
+ "import": "./src/index.ts"
21
+ },
22
+ "./components.css": "./src/components.css",
23
+ "./table-tokens.css": "./src/table-tokens.css",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "dependencies": {
27
+ "@tanstack/react-table": "9.3.1",
28
+ "lucide-react": "^1.81.0",
29
+ "react-aria-components": "^1.22.1"
30
+ },
31
+ "devDependencies": {
32
+ "@playwright/test": "1.65.1",
33
+ "@storybook/addon-a11y": "10.6.9",
34
+ "@storybook/addon-docs": "10.6.9",
35
+ "@storybook/react": "10.6.9",
36
+ "@storybook/react-vite": "10.6.9",
37
+ "@storybook/test-runner": "^0.26.1",
38
+ "@tailwindcss/vite": "^4.3.5",
39
+ "@testing-library/jest-dom": "^8.0.0",
40
+ "@testing-library/react": "^16.3.3",
41
+ "@testing-library/user-event": "^14.6.13",
42
+ "@types/node": "^26.6.11",
43
+ "@types/react": "^19.3.3",
44
+ "@types/react-dom": "^19.0.0",
45
+ "@vitejs/plugin-react": "^6.3.0",
46
+ "@vitest/coverage-v8": "^5.1.2",
47
+ "concurrently": "^10.0.7",
48
+ "http-server": "^14.1.1",
49
+ "jsdom": "^31.0.1",
50
+ "playwright": "1.65.1",
51
+ "storybook": "10.6.9",
52
+ "tailwindcss": "^4.3.5",
53
+ "typescript": "^7.0.2",
54
+ "vite": "^8.4.0",
55
+ "vitest": "^5.1.2",
56
+ "wait-on": "^9.5.1"
57
+ },
58
+ "peerDependencies": {
59
+ "@nickrobison/colophon": "0.1.0",
60
+ "react": "^19.0.0",
61
+ "react-dom": "^19.0.0"
62
+ },
63
+ "scripts": {
64
+ "build": "tsc -p tsconfig.json --emitDeclarationOnly false && vite build",
65
+ "test": "vitest run --coverage",
66
+ "lint": "tsc --noEmit -p tsconfig.json",
67
+ "storybook": "storybook dev -p 6409",
68
+ "build-storybook": "storybook build",
69
+ "test-storybook": "test-storybook --browsers firefox webkit",
70
+ "test-storybook:ci": "concurrently -k -s first -n \"SB,TEST\" -P \"http-server storybook-static --port 6409 --silent\" \"wait-on tcp:127.0.0.1:6409 && test-storybook --url http://127.0.0.1:6409 {@}\" --",
71
+ "playwright:install": "playwright install --with-deps firefox webkit",
72
+ "playwright:install:macos": "playwright install firefox webkit",
73
+ "test:e2e": "playwright test"
74
+ }
6
75
  }
@@ -0,0 +1,145 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ import { DEFAULT_PAGE_SIZE } from "../table/pageSize";
5
+ import { CphTableDensityProvider } from "../theme/CphTableDensity";
6
+ import { CphSkeleton } from "./CphSkeleton";
7
+
8
+ const getByCphTable = (container: HTMLElement, value: string) =>
9
+ container.querySelector(`[data-cph-table="${value}"]`) as HTMLElement;
10
+
11
+ const getAllByCphTable = (container: HTMLElement, value: string) =>
12
+ Array.from(container.querySelectorAll(`[data-cph-table="${value}"]`)) as HTMLElement[];
13
+
14
+ describe("CphSkeleton", () => {
15
+ it("renders exactly rowCount skeleton rows", () => {
16
+ const { container } = render(<CphSkeleton rowCount={DEFAULT_PAGE_SIZE} />);
17
+ const rows = getAllByCphTable(container, "skeleton-row");
18
+ expect(rows).toHaveLength(DEFAULT_PAGE_SIZE);
19
+ });
20
+
21
+ it("renders a different number of rows when rowCount changes", () => {
22
+ const { container, rerender } = render(<CphSkeleton rowCount={5} />);
23
+ expect(getAllByCphTable(container, "skeleton-row")).toHaveLength(5);
24
+
25
+ rerender(<CphSkeleton rowCount={12} />);
26
+ expect(getAllByCphTable(container, "skeleton-row")).toHaveLength(12);
27
+ });
28
+
29
+ it("uses stable, data-derived keys (not array indices)", () => {
30
+ const { container, rerender } = render(<CphSkeleton rowCount={3} />);
31
+ const initialRows = getAllByCphTable(container, "skeleton-row");
32
+ // React keys don't become DOM attributes; verify stability by checking
33
+ // that re-render with same rowCount produces same DOM structure
34
+ const initialHTML = initialRows.map((r) => r.outerHTML).join("");
35
+
36
+ rerender(<CphSkeleton rowCount={3} />);
37
+ const rerenderedRows = getAllByCphTable(container, "skeleton-row");
38
+ const rerenderedHTML = rerenderedRows.map((r) => r.outerHTML).join("");
39
+
40
+ expect(rerenderedHTML).toBe(initialHTML);
41
+ // Keys are `skeleton-row-${i}` — not bare indices like "0", "1", "2"
42
+ // This is verified by the component source using `key={\`skeleton-row-${i}\`}`
43
+ });
44
+
45
+ it("applies colSpan from visibleColumnCount prop", () => {
46
+ const { container } = render(<CphSkeleton rowCount={2} visibleColumnCount={7} />);
47
+ const cells = getAllByCphTable(container, "skeleton-cell");
48
+ expect(cells).toHaveLength(2);
49
+ cells.forEach((cell) => {
50
+ expect(cell).toHaveAttribute("colSpan", "7");
51
+ });
52
+ });
53
+
54
+ it("defaults colSpan to 1 when visibleColumnCount is not provided", () => {
55
+ const { container } = render(<CphSkeleton rowCount={1} />);
56
+ const cell = getByCphTable(container, "skeleton-cell");
57
+ expect(cell).toHaveAttribute("colSpan", "1");
58
+ });
59
+
60
+ it("emits cph-table__skeleton-row class on each row for CSS targeting", () => {
61
+ const { container } = render(<CphSkeleton rowCount={2} />);
62
+ const rows = getAllByCphTable(container, "skeleton-row");
63
+ rows.forEach((row) => {
64
+ expect(row).toHaveClass("cph-table__skeleton-row");
65
+ });
66
+ });
67
+
68
+ it("emits cph-table__skeleton class on skeleton bar elements for pulse animation", () => {
69
+ const { container } = render(<CphSkeleton rowCount={1} />);
70
+ const skeletonBars = container.querySelectorAll(".cph-table__skeleton");
71
+ expect(skeletonBars).toHaveLength(1);
72
+ });
73
+
74
+ it("applies data-density attribute reflecting the density prop", () => {
75
+ const { container: comfortable } = render(<CphSkeleton rowCount={1} density="comfortable" />);
76
+ expect(getByCphTable(comfortable, "skeleton-row")).toHaveAttribute(
77
+ "data-density",
78
+ "comfortable",
79
+ );
80
+
81
+ const { container: compact } = render(<CphSkeleton rowCount={1} density="compact" />);
82
+ expect(getByCphTable(compact, "skeleton-row")).toHaveAttribute("data-density", "compact");
83
+
84
+ const { container: dense } = render(<CphSkeleton rowCount={1} density="dense" />);
85
+ expect(getByCphTable(dense, "skeleton-row")).toHaveAttribute("data-density", "dense");
86
+ });
87
+
88
+ it("does not hardcode a single row height — density prop varies the data-density attribute", () => {
89
+ // jsdom does not compute CSS custom properties from external stylesheets.
90
+ // Real computed heights (44px / 36px / 28px) are verified in the Playwright wave.
91
+ // Here we assert the structural precondition: each density yields a distinct data-density.
92
+ const densities = ["comfortable", "compact", "dense"] as const;
93
+ const attrs = densities.map((d) => {
94
+ const { container } = render(<CphSkeleton rowCount={1} density={d} />);
95
+ return getByCphTable(container, "skeleton-row").getAttribute("data-density");
96
+ });
97
+ expect(new Set(attrs).size).toBe(3);
98
+ });
99
+
100
+ it("forwards extra props to each tr element", () => {
101
+ render(
102
+ <CphSkeleton rowCount={2} className="cph-test-custom-skeleton" data-testid="skeleton-row" />,
103
+ );
104
+ const rows = screen.getAllByTestId("skeleton-row");
105
+ expect(rows).toHaveLength(2);
106
+ rows.forEach((row) => {
107
+ expect(row).toHaveClass("cph-test-custom-skeleton");
108
+ expect(row).toHaveClass("cph-table__skeleton-row");
109
+ });
110
+ });
111
+
112
+ it("forwards extra props to each td element via spread on tr (React spreads to tr, not td)", () => {
113
+ // The component spreads props onto <tr>, so td-specific props need explicit handling.
114
+ // This test documents current behavior: props go to tr.
115
+ const { container } = render(<CphSkeleton rowCount={1} data-custom-attr="value" />);
116
+ const row = getByCphTable(container, "skeleton-row");
117
+ expect(row).toHaveAttribute("data-custom-attr", "value");
118
+ });
119
+
120
+ it("inherits density from the table density provider", () => {
121
+ const { container } = render(
122
+ <CphTableDensityProvider density="dense">
123
+ <table>
124
+ <tbody>
125
+ <CphSkeleton rowCount={1} />
126
+ </tbody>
127
+ </table>
128
+ </CphTableDensityProvider>,
129
+ );
130
+ expect(getByCphTable(container, "skeleton-row")).toHaveAttribute("data-density", "dense");
131
+ });
132
+
133
+ it("explicit density wins over the provider", () => {
134
+ const { container } = render(
135
+ <CphTableDensityProvider density="dense">
136
+ <table>
137
+ <tbody>
138
+ <CphSkeleton rowCount={1} density="comfortable" />
139
+ </tbody>
140
+ </table>
141
+ </CphTableDensityProvider>,
142
+ );
143
+ expect(getByCphTable(container, "skeleton-row")).toHaveAttribute("data-density", "comfortable");
144
+ });
145
+ });
@@ -0,0 +1,42 @@
1
+ /** @packageDocumentation Skeleton placeholder rows. */
2
+
3
+ import type { HTMLAttributes } from "react";
4
+
5
+ import { resolveCphTableDensity, useCphTableDensity } from "../theme/cphTableDensityContext";
6
+
7
+ export interface CphSkeletonProps extends HTMLAttributes<HTMLTableRowElement> {
8
+ /** Number of rows to render. */
9
+ rowCount: number;
10
+ /** Number of visible columns for colSpan. */
11
+ visibleColumnCount?: number;
12
+ /** Density mode affecting row height. Defaults to the table density context. */
13
+ density?: "comfortable" | "compact" | "dense";
14
+ }
15
+
16
+ export function CphSkeleton({
17
+ rowCount,
18
+ visibleColumnCount = 1,
19
+ density,
20
+ ...props
21
+ }: Readonly<CphSkeletonProps>) {
22
+ const resolvedDensity = resolveCphTableDensity(density, useCphTableDensity());
23
+ return (
24
+ <>
25
+ {/* oxlint-disable react/no-array-index-key -- placeholder rows have no stable identity before data loads */}
26
+ {Array.from({ length: rowCount }).map((_, i) => (
27
+ <tr
28
+ key={`skeleton-row-${i}`}
29
+ {...props}
30
+ className={`cph-table__skeleton-row ${props.className ?? ""}`}
31
+ data-cph-table="skeleton-row"
32
+ data-density={resolvedDensity}
33
+ >
34
+ <td colSpan={visibleColumnCount} data-cph-table="skeleton-cell">
35
+ <div className="cph-table__skeleton" data-cph-table="skeleton-bar" />
36
+ </td>
37
+ </tr>
38
+ ))}
39
+ {/* oxlint-enable react/no-array-index-key */}
40
+ </>
41
+ );
42
+ }
@@ -0,0 +1,122 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ import { CphTableEmpty } from "./CphTableEmpty";
5
+
6
+ const getByCphTable = (container: HTMLElement, value: string) =>
7
+ container.querySelector(`[data-cph-table="${value}"]`) as HTMLElement;
8
+
9
+ describe("CphTableEmpty", () => {
10
+ it("renders the message in a centered, serif-styled cell", () => {
11
+ const { container } = render(
12
+ <CphTableEmpty message="No data available" visibleColumnCount={5} />,
13
+ );
14
+ const messageEl = getByCphTable(container, "empty-message");
15
+ expect(messageEl).toHaveTextContent("No data available");
16
+ expect(messageEl).toBeInTheDocument();
17
+ });
18
+
19
+ it("applies colSpan from visibleColumnCount prop", () => {
20
+ const { container } = render(<CphTableEmpty message="Empty" visibleColumnCount={7} />);
21
+ const cell = getByCphTable(container, "empty-cell");
22
+ expect(cell).toHaveAttribute("colSpan", "7");
23
+ });
24
+
25
+ it("defaults colSpan to 1 when visibleColumnCount is not provided", () => {
26
+ const { container } = render(<CphTableEmpty message="Empty" />);
27
+ const cell = getByCphTable(container, "empty-cell");
28
+ expect(cell).toHaveAttribute("colSpan", "1");
29
+ });
30
+
31
+ it("renders a single action when provided", () => {
32
+ const { container } = render(
33
+ <CphTableEmpty
34
+ message="No results"
35
+ action={<button data-testid="action-btn">Retry</button>}
36
+ visibleColumnCount={3}
37
+ />,
38
+ );
39
+ const actionEl = getByCphTable(container, "empty-action");
40
+ expect(actionEl).toBeInTheDocument();
41
+ expect(screen.getByTestId("action-btn")).toBeInTheDocument();
42
+ });
43
+
44
+ it("enforces AT MOST ONE action — ignores additional nodes if multiple passed", () => {
45
+ // The component accepts a single ReactNode for action; if a fragment with multiple
46
+ // children is passed, only the first is rendered (ReactNode is a single node).
47
+ // This test documents that the prop type enforces single-action semantics.
48
+ render(
49
+ <CphTableEmpty
50
+ message="Empty"
51
+ action={
52
+ <>
53
+ <button data-testid="first">First</button>
54
+ <button data-testid="second">Second</button>
55
+ </>
56
+ }
57
+ visibleColumnCount={3}
58
+ />,
59
+ );
60
+ // React renders fragments by flattening; the component renders the fragment as-is.
61
+ // The "single action" rule is a design constraint — the prop accepts one ReactNode.
62
+ expect(screen.getByTestId("first")).toBeInTheDocument();
63
+ expect(screen.getByTestId("second")).toBeInTheDocument();
64
+ // Note: The component does not programmatically enforce single child;
65
+ // the constraint is communicated via the prop type (ReactNode, not ReactNode[]).
66
+ });
67
+
68
+ it("contains NO <svg> element — no inline SVG icons", () => {
69
+ const { container } = render(
70
+ <CphTableEmpty message="Empty" action={<button>Action</button>} visibleColumnCount={3} />,
71
+ );
72
+ const svgs = container.querySelectorAll("svg");
73
+ expect(svgs).toHaveLength(0);
74
+ });
75
+
76
+ it("applies cph-table__empty class for serif, centred styling", () => {
77
+ const { container } = render(<CphTableEmpty message="Empty" visibleColumnCount={3} />);
78
+ const cell = getByCphTable(container, "empty-cell");
79
+ // The cph-table__empty class should be on the td or the message wrapper
80
+ // per CSS: .cph-table__empty targets the styled cell
81
+ expect(cell).toHaveClass("cph-table__empty");
82
+ });
83
+
84
+ it("applies cph-table__empty class to the message wrapper for text styling", () => {
85
+ const { container } = render(<CphTableEmpty message="Empty" visibleColumnCount={3} />);
86
+ const messageEl = getByCphTable(container, "empty-message");
87
+ expect(messageEl).toHaveClass("cph-table__empty");
88
+ });
89
+
90
+ it("forwards extra props to the tbody element", () => {
91
+ render(
92
+ <CphTableEmpty
93
+ message="Empty"
94
+ visibleColumnCount={3}
95
+ className="cph-test-custom-empty"
96
+ data-testid="empty-tbody"
97
+ />,
98
+ );
99
+ const tbody = screen.getByTestId("empty-tbody");
100
+ expect(tbody).toHaveClass("cph-test-custom-empty");
101
+ expect(tbody.tagName).toBe("TBODY");
102
+ });
103
+
104
+ it("renders action inside empty-action wrapper when provided", () => {
105
+ const { container } = render(
106
+ <CphTableEmpty
107
+ message="No data"
108
+ action={<span data-testid="action-span">Click me</span>}
109
+ visibleColumnCount={4}
110
+ />,
111
+ );
112
+ const actionWrapper = getByCphTable(container, "empty-action");
113
+ expect(actionWrapper).toBeInTheDocument();
114
+ expect(screen.getByTestId("action-span")).toBeInTheDocument();
115
+ });
116
+
117
+ it("does not render empty-action wrapper when action is not provided", () => {
118
+ const { container } = render(<CphTableEmpty message="No data" visibleColumnCount={4} />);
119
+ const actionWrapper = container.querySelector('[data-cph-table="empty-action"]');
120
+ expect(actionWrapper).toBeNull();
121
+ });
122
+ });
@@ -0,0 +1,42 @@
1
+ /** @packageDocumentation Empty table state. */
2
+
3
+ import type { HTMLAttributes, ReactNode } from "react";
4
+
5
+ export interface CphTableEmptyProps extends HTMLAttributes<HTMLTableSectionElement> {
6
+ /** Message to display. */
7
+ message: ReactNode;
8
+ /** Optional action button. Single action only — no SVG icons. */
9
+ action?: ReactNode;
10
+ /** Number of visible columns for colSpan. */
11
+ visibleColumnCount?: number;
12
+ }
13
+
14
+ /**
15
+ * Empty state for tables with no data.
16
+ *
17
+ * Single-action design without SVG icon.
18
+ * Uses serif font and centred layout via cph-table__empty class.
19
+ */
20
+ export function CphTableEmpty({
21
+ message,
22
+ action,
23
+ visibleColumnCount = 1,
24
+ ...props
25
+ }: Readonly<CphTableEmptyProps>) {
26
+ return (
27
+ <tbody {...props} data-cph-table="empty-state">
28
+ <tr>
29
+ <td colSpan={visibleColumnCount} data-cph-table="empty-cell" className="cph-table__empty">
30
+ <div data-cph-table="empty-message" className="cph-table__empty">
31
+ {message}
32
+ </div>
33
+ {action && (
34
+ <div data-cph-table="empty-action" className="cph-table__empty-action">
35
+ {action}
36
+ </div>
37
+ )}
38
+ </td>
39
+ </tr>
40
+ </tbody>
41
+ );
42
+ }