@flamingo-stack/openframe-frontend-core 0.0.652 → 0.0.653-2289.6601.1

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 (114) hide show
  1. package/dist/{chunk-I3KD7T6K.cjs → chunk-2WQ5XTAZ.cjs} +36 -36
  2. package/dist/{chunk-I3KD7T6K.cjs.map → chunk-2WQ5XTAZ.cjs.map} +1 -1
  3. package/dist/{chunk-4T7E2SWL.cjs → chunk-3RJ4VI3H.cjs} +13 -13
  4. package/dist/{chunk-4T7E2SWL.cjs.map → chunk-3RJ4VI3H.cjs.map} +1 -1
  5. package/dist/{chunk-UEFHMMJX.cjs → chunk-5N2VSYMZ.cjs} +18 -18
  6. package/dist/{chunk-UEFHMMJX.cjs.map → chunk-5N2VSYMZ.cjs.map} +1 -1
  7. package/dist/{chunk-HSPLCV56.js → chunk-5P7MYYNW.js} +2 -2
  8. package/dist/{chunk-ERFHLMWM.cjs → chunk-7CVRBXLS.cjs} +352 -234
  9. package/dist/chunk-7CVRBXLS.cjs.map +1 -0
  10. package/dist/{chunk-TGHSQUTD.js → chunk-C4JQRKXH.js} +2 -2
  11. package/dist/{chunk-AGQZRNYV.js → chunk-CRT6FYWQ.js} +4 -4
  12. package/dist/{chunk-AAITIXRL.cjs → chunk-IIR3FCRM.cjs} +17 -17
  13. package/dist/{chunk-AAITIXRL.cjs.map → chunk-IIR3FCRM.cjs.map} +1 -1
  14. package/dist/{chunk-LDC37FG4.js → chunk-IJNR2VZJ.js} +2 -2
  15. package/dist/{chunk-N4RVPWPM.js → chunk-IR7ZOGRA.js} +2 -2
  16. package/dist/{chunk-ADXTLFG7.js → chunk-KNRGYPW4.js} +5 -5
  17. package/dist/{chunk-LUEURQOY.js → chunk-KQPEXCYU.js} +5 -5
  18. package/dist/{chunk-NTJUFHX2.js → chunk-LGAIEUAL.js} +2 -2
  19. package/dist/{chunk-DVT5JCLD.cjs → chunk-MVIC53FZ.cjs} +3 -3
  20. package/dist/{chunk-DVT5JCLD.cjs.map → chunk-MVIC53FZ.cjs.map} +1 -1
  21. package/dist/{chunk-QZJ4K7SG.js → chunk-NUKLU7RL.js} +2 -2
  22. package/dist/{chunk-EY2OVL3Z.cjs → chunk-NWYLN3FU.cjs} +10 -10
  23. package/dist/{chunk-EY2OVL3Z.cjs.map → chunk-NWYLN3FU.cjs.map} +1 -1
  24. package/dist/{chunk-LECSFMGM.js → chunk-OEJRLL5C.js} +367 -249
  25. package/dist/chunk-OEJRLL5C.js.map +1 -0
  26. package/dist/{chunk-JCVGQDQV.cjs → chunk-OPNV6V2Z.cjs} +33 -33
  27. package/dist/{chunk-JCVGQDQV.cjs.map → chunk-OPNV6V2Z.cjs.map} +1 -1
  28. package/dist/{chunk-2FWS52HR.js → chunk-P6YNSOFB.js} +3 -3
  29. package/dist/{chunk-HM6D2YHS.js → chunk-SE4POCS6.js} +2 -2
  30. package/dist/{chunk-FBKB4HCZ.cjs → chunk-T5QSKERQ.cjs} +3 -3
  31. package/dist/{chunk-FBKB4HCZ.cjs.map → chunk-T5QSKERQ.cjs.map} +1 -1
  32. package/dist/{chunk-ZVLOG2AV.cjs → chunk-T6W3NMA7.cjs} +4 -4
  33. package/dist/{chunk-ZVLOG2AV.cjs.map → chunk-T6W3NMA7.cjs.map} +1 -1
  34. package/dist/{chunk-74EGKPX3.js → chunk-UE7TECNE.js} +2 -2
  35. package/dist/{chunk-QUNY6URW.js → chunk-UQ2OYID7.js} +2 -2
  36. package/dist/{chunk-VIHX7ADQ.cjs → chunk-VZWLSDAU.cjs} +3 -3
  37. package/dist/{chunk-VIHX7ADQ.cjs.map → chunk-VZWLSDAU.cjs.map} +1 -1
  38. package/dist/{chunk-27OZEE3E.cjs → chunk-WRXB3XXK.cjs} +3 -3
  39. package/dist/{chunk-27OZEE3E.cjs.map → chunk-WRXB3XXK.cjs.map} +1 -1
  40. package/dist/{chunk-I5Y6ZALR.cjs → chunk-X24KJHPD.cjs} +51 -51
  41. package/dist/{chunk-I5Y6ZALR.cjs.map → chunk-X24KJHPD.cjs.map} +1 -1
  42. package/dist/{chunk-BRIJIC6E.js → chunk-XFT4FZWM.js} +4 -4
  43. package/dist/{chunk-JWY5ES3H.cjs → chunk-ZG4A6IYE.cjs} +4 -4
  44. package/dist/{chunk-JWY5ES3H.cjs.map → chunk-ZG4A6IYE.cjs.map} +1 -1
  45. package/dist/{chunk-BXE3DLIC.cjs → chunk-ZYAU5PT6.cjs} +17 -17
  46. package/dist/{chunk-BXE3DLIC.cjs.map → chunk-ZYAU5PT6.cjs.map} +1 -1
  47. package/dist/components/case-studies/index.cjs +11 -11
  48. package/dist/components/case-studies/index.js +2 -2
  49. package/dist/components/contact/index.cjs +3 -3
  50. package/dist/components/contact/index.js +2 -2
  51. package/dist/components/docs/index.cjs +6 -6
  52. package/dist/components/docs/index.js +5 -5
  53. package/dist/components/embeds/index.cjs +3 -3
  54. package/dist/components/embeds/index.js +2 -2
  55. package/dist/components/faq/index.cjs +3 -3
  56. package/dist/components/faq/index.js +2 -2
  57. package/dist/components/features/index.cjs +2 -2
  58. package/dist/components/features/index.js +1 -1
  59. package/dist/components/help-center-pages/index.cjs +22 -22
  60. package/dist/components/help-center-pages/index.js +13 -13
  61. package/dist/components/index.cjs +31 -31
  62. package/dist/components/index.js +12 -12
  63. package/dist/components/meeting-scheduler/index.cjs +21 -21
  64. package/dist/components/meeting-scheduler/index.js +1 -1
  65. package/dist/components/navigation/index.cjs +5 -5
  66. package/dist/components/navigation/index.js +4 -4
  67. package/dist/components/onboarding-guides/index.cjs +5 -5
  68. package/dist/components/onboarding-guides/index.js +4 -4
  69. package/dist/components/tickets/index.cjs +6 -6
  70. package/dist/components/tickets/index.js +5 -5
  71. package/dist/components/ui/data-table/data-table-body.d.ts +17 -8
  72. package/dist/components/ui/data-table/data-table-body.d.ts.map +1 -1
  73. package/dist/components/ui/data-table/data-table-infinite-footer.d.ts +37 -3
  74. package/dist/components/ui/data-table/data-table-infinite-footer.d.ts.map +1 -1
  75. package/dist/components/ui/data-table/data-table-load-more.d.ts +35 -0
  76. package/dist/components/ui/data-table/data-table-load-more.d.ts.map +1 -0
  77. package/dist/components/ui/data-table/data-table-row.d.ts +3 -9
  78. package/dist/components/ui/data-table/data-table-row.d.ts.map +1 -1
  79. package/dist/components/ui/data-table/data-table-skeleton.d.ts +9 -0
  80. package/dist/components/ui/data-table/data-table-skeleton.d.ts.map +1 -1
  81. package/dist/components/ui/data-table/data-table.d.ts +6 -0
  82. package/dist/components/ui/data-table/data-table.d.ts.map +1 -1
  83. package/dist/components/ui/data-table/index.d.ts +1 -1
  84. package/dist/components/ui/index.cjs +2 -2
  85. package/dist/components/ui/index.js +1 -1
  86. package/dist/index.cjs +6 -6
  87. package/dist/index.js +5 -5
  88. package/package.json +1 -1
  89. package/src/__tests__/data-table-infinite-footer.test.tsx +246 -0
  90. package/src/__tests__/data-table-row-height.test.tsx +1 -7
  91. package/src/__tests__/data-table-skeleton-row-rhythm.test.tsx +147 -0
  92. package/src/components/ui/data-table/data-table-body.tsx +53 -17
  93. package/src/components/ui/data-table/data-table-infinite-footer.tsx +138 -9
  94. package/src/components/ui/data-table/data-table-load-more.ts +87 -0
  95. package/src/components/ui/data-table/data-table-row.tsx +8 -12
  96. package/src/components/ui/data-table/data-table-skeleton.tsx +10 -0
  97. package/src/components/ui/data-table/data-table.tsx +18 -2
  98. package/src/stories/DataTable.stories.tsx +167 -0
  99. package/dist/chunk-ERFHLMWM.cjs.map +0 -1
  100. package/dist/chunk-LECSFMGM.js.map +0 -1
  101. /package/dist/{chunk-HSPLCV56.js.map → chunk-5P7MYYNW.js.map} +0 -0
  102. /package/dist/{chunk-TGHSQUTD.js.map → chunk-C4JQRKXH.js.map} +0 -0
  103. /package/dist/{chunk-AGQZRNYV.js.map → chunk-CRT6FYWQ.js.map} +0 -0
  104. /package/dist/{chunk-LDC37FG4.js.map → chunk-IJNR2VZJ.js.map} +0 -0
  105. /package/dist/{chunk-N4RVPWPM.js.map → chunk-IR7ZOGRA.js.map} +0 -0
  106. /package/dist/{chunk-ADXTLFG7.js.map → chunk-KNRGYPW4.js.map} +0 -0
  107. /package/dist/{chunk-LUEURQOY.js.map → chunk-KQPEXCYU.js.map} +0 -0
  108. /package/dist/{chunk-NTJUFHX2.js.map → chunk-LGAIEUAL.js.map} +0 -0
  109. /package/dist/{chunk-QZJ4K7SG.js.map → chunk-NUKLU7RL.js.map} +0 -0
  110. /package/dist/{chunk-2FWS52HR.js.map → chunk-P6YNSOFB.js.map} +0 -0
  111. /package/dist/{chunk-HM6D2YHS.js.map → chunk-SE4POCS6.js.map} +0 -0
  112. /package/dist/{chunk-74EGKPX3.js.map → chunk-UE7TECNE.js.map} +0 -0
  113. /package/dist/{chunk-QUNY6URW.js.map → chunk-UQ2OYID7.js.map} +0 -0
  114. /package/dist/{chunk-BRIJIC6E.js.map → chunk-XFT4FZWM.js.map} +0 -0
@@ -0,0 +1,246 @@
1
+ import { createColumnHelper } from '@tanstack/react-table';
2
+ import { act, fireEvent, render, screen } from '@testing-library/react';
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
+ import { DataTable } from '../components/ui/data-table';
5
+ import { useDataTable } from '../components/ui/data-table/use-data-table';
6
+
7
+ /**
8
+ * `<DataTable.InfiniteFooter>` decides WHEN the next page is asked for. Two
9
+ * things it got wrong, both invisible in a window-scrolled demo:
10
+ *
11
+ * - It observed against the viewport. The apps scroll a nested `<main>`, and a
12
+ * scrolling ancestor clips the intersection regardless of `rootMargin`, so
13
+ * the pre-fetch lead was zero: the request left once the user had run out of
14
+ * rows.
15
+ * - A fetch that added nothing (an error, an empty page) re-armed the observer
16
+ * with the sentinel still in view, which fired the same request again —
17
+ * forever.
18
+ */
19
+
20
+ interface Row {
21
+ id: string;
22
+ name: string;
23
+ }
24
+
25
+ const columnHelper = createColumnHelper<Row>();
26
+ const columns = [columnHelper.accessor('name', { id: 'name', header: 'Name' })];
27
+ const rows = (n: number): Row[] => Array.from({ length: n }, (_, i) => ({ id: String(i), name: `Row ${i}` }));
28
+
29
+ /** jsdom has no IntersectionObserver; this one records how it was set up and fires on demand. */
30
+ class FakeIntersectionObserver {
31
+ static instances: FakeIntersectionObserver[] = [];
32
+ disconnected = false;
33
+ constructor(
34
+ private readonly callback: IntersectionObserverCallback,
35
+ readonly options: IntersectionObserverInit = {},
36
+ ) {
37
+ FakeIntersectionObserver.instances.push(this);
38
+ }
39
+ observe() {}
40
+ unobserve() {}
41
+ disconnect() {
42
+ this.disconnected = true;
43
+ }
44
+ takeRecords() {
45
+ return [];
46
+ }
47
+ /** The sentinel came into range. */
48
+ intersect() {
49
+ this.callback([{ isIntersecting: true } as IntersectionObserverEntry], this as unknown as IntersectionObserver);
50
+ }
51
+ }
52
+
53
+ const liveObservers = () => FakeIntersectionObserver.instances.filter(observer => !observer.disconnected);
54
+
55
+ function Table({
56
+ data,
57
+ isFetchingNextPage = false,
58
+ onLoadMore,
59
+ loadedCount,
60
+ }: {
61
+ data: Row[];
62
+ isFetchingNextPage?: boolean;
63
+ onLoadMore: () => void;
64
+ loadedCount?: number;
65
+ }) {
66
+ const table = useDataTable({ data, columns });
67
+ return (
68
+ <DataTable table={table}>
69
+ <DataTable.Body<Row> />
70
+ <DataTable.InfiniteFooter
71
+ hasNextPage
72
+ isFetchingNextPage={isFetchingNextPage}
73
+ onLoadMore={onLoadMore}
74
+ loadedCount={loadedCount}
75
+ />
76
+ </DataTable>
77
+ );
78
+ }
79
+
80
+ beforeEach(() => {
81
+ FakeIntersectionObserver.instances = [];
82
+ vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
83
+ });
84
+
85
+ afterEach(() => {
86
+ vi.unstubAllGlobals();
87
+ });
88
+
89
+ describe('DataTable.InfiniteFooter', () => {
90
+ it('asks for the next page one scroller-height ahead, not two rows', () => {
91
+ render(<Table data={rows(3)} onLoadMore={vi.fn()} />);
92
+ expect(liveObservers()[0]?.options.rootMargin).toBe('0px 0px 100% 0px');
93
+ });
94
+
95
+ it('roots the observer on the ancestor that scrolls, so the lead is not clipped away', () => {
96
+ // No layout in jsdom: state the two facts `findScrollParent` reads.
97
+ const scroller = document.createElement('div');
98
+ scroller.style.overflowY = 'auto';
99
+ Object.defineProperty(scroller, 'scrollHeight', { value: 2000 });
100
+ Object.defineProperty(scroller, 'clientHeight', { value: 600 });
101
+ document.body.appendChild(scroller);
102
+
103
+ render(<Table data={rows(3)} onLoadMore={vi.fn()} />, { container: scroller });
104
+
105
+ expect(liveObservers()[0]?.options.root).toBe(scroller);
106
+ scroller.remove();
107
+ });
108
+
109
+ it('does NOT root on a wrapper that only scrolls sideways', () => {
110
+ // `overflow-x: auto` computes `overflow-y: auto` as well, but the wrapper is
111
+ // as tall as its content — as a root it would hold the sentinel permanently
112
+ // and every page would load at once.
113
+ const wrapper = document.createElement('div');
114
+ wrapper.style.overflowY = 'auto';
115
+ Object.defineProperty(wrapper, 'scrollHeight', { value: 2000 });
116
+ Object.defineProperty(wrapper, 'clientHeight', { value: 2000 });
117
+ document.body.appendChild(wrapper);
118
+
119
+ render(<Table data={rows(3)} onLoadMore={vi.fn()} />, { container: wrapper });
120
+
121
+ expect(liveObservers()[0]?.options.root).toBeNull();
122
+ wrapper.remove();
123
+ });
124
+
125
+ it('falls back to the viewport when it is the DOCUMENT that scrolls', () => {
126
+ // `<body>` as a root is document-tall: the sentinel would always be inside
127
+ // it, and every page would load at once.
128
+ const overflowY = document.body.style.overflowY;
129
+ document.body.style.overflowY = 'scroll';
130
+ const scrollHeight = vi.spyOn(document.body, 'scrollHeight', 'get').mockReturnValue(5000);
131
+ const clientHeight = vi.spyOn(document.body, 'clientHeight', 'get').mockReturnValue(800);
132
+
133
+ render(<Table data={rows(3)} onLoadMore={vi.fn()} />);
134
+
135
+ expect(liveObservers()[0]?.options.root).toBeNull();
136
+ document.body.style.overflowY = overflowY;
137
+ scrollHeight.mockRestore();
138
+ clientHeight.mockRestore();
139
+ });
140
+
141
+ it('chains the next page when a fetch made progress', () => {
142
+ const onLoadMore = vi.fn();
143
+ const { rerender } = render(<Table data={rows(3)} onLoadMore={onLoadMore} />);
144
+
145
+ act(() => liveObservers()[0]?.intersect());
146
+ expect(onLoadMore).toHaveBeenCalledTimes(1);
147
+
148
+ rerender(<Table data={rows(3)} isFetchingNextPage onLoadMore={onLoadMore} />);
149
+ expect(liveObservers()).toHaveLength(0);
150
+
151
+ // The page arrived: a fresh observer is armed for the one after it.
152
+ rerender(<Table data={rows(6)} onLoadMore={onLoadMore} />);
153
+ expect(liveObservers()).toHaveLength(1);
154
+ expect(screen.queryByRole('button', { name: 'Load more' })).toBeNull();
155
+ });
156
+
157
+ it('stops auto-loading when a fetch adds NO rows, instead of looping the request', () => {
158
+ const onLoadMore = vi.fn();
159
+ const { rerender } = render(<Table data={rows(3)} onLoadMore={onLoadMore} />);
160
+
161
+ act(() => liveObservers()[0]?.intersect());
162
+ rerender(<Table data={rows(3)} isFetchingNextPage onLoadMore={onLoadMore} />);
163
+ // Failed, or came back empty: same rows, still claims a next page.
164
+ rerender(<Table data={rows(3)} onLoadMore={onLoadMore} />);
165
+
166
+ // Nothing is left armed to fire the same request again…
167
+ expect(liveObservers()).toHaveLength(0);
168
+ expect(onLoadMore).toHaveBeenCalledTimes(1);
169
+ // …and the way forward is the user's to take.
170
+ fireEvent.click(screen.getByRole('button', { name: 'Load more' }));
171
+ expect(onLoadMore).toHaveBeenCalledTimes(2);
172
+ });
173
+
174
+ it('does NOT park when the list was REPLACED while a page was in flight', () => {
175
+ // A new search lands mid-fetch: the in-flight page is dropped and the fetch
176
+ // ends with FEWER rows than it started with. That is a new list to keep
177
+ // loading, not a stalled one.
178
+ const onLoadMore = vi.fn();
179
+ const { rerender } = render(<Table data={rows(6)} onLoadMore={onLoadMore} />);
180
+
181
+ rerender(<Table data={rows(6)} isFetchingNextPage onLoadMore={onLoadMore} />);
182
+ rerender(<Table data={rows(2)} onLoadMore={onLoadMore} />);
183
+
184
+ expect(screen.queryByRole('button', { name: 'Load more' })).toBeNull();
185
+ expect(liveObservers()).toHaveLength(1);
186
+ });
187
+
188
+ it('keeps walking when a page ARRIVED but client-side narrowing showed none of it', () => {
189
+ // A table that filters its loaded pages: 20 more rows were fetched, none
190
+ // matched. The match may be on the next page, so this is not a stall.
191
+ const onLoadMore = vi.fn();
192
+ const { rerender } = render(<Table data={rows(3)} loadedCount={20} onLoadMore={onLoadMore} />);
193
+
194
+ rerender(<Table data={rows(3)} loadedCount={20} isFetchingNextPage onLoadMore={onLoadMore} />);
195
+ rerender(<Table data={rows(3)} loadedCount={40} onLoadMore={onLoadMore} />);
196
+
197
+ expect(screen.queryByRole('button', { name: 'Load more' })).toBeNull();
198
+ expect(liveObservers()).toHaveLength(1);
199
+ });
200
+
201
+ it('still parks such a table when the fetch itself brought nothing', () => {
202
+ const onLoadMore = vi.fn();
203
+ const { rerender } = render(<Table data={rows(3)} loadedCount={20} onLoadMore={onLoadMore} />);
204
+
205
+ rerender(<Table data={rows(3)} loadedCount={20} isFetchingNextPage onLoadMore={onLoadMore} />);
206
+ rerender(<Table data={rows(3)} loadedCount={20} onLoadMore={onLoadMore} />);
207
+
208
+ expect(screen.getByRole('button', { name: 'Load more' })).toBeDefined();
209
+ expect(liveObservers()).toHaveLength(0);
210
+ });
211
+
212
+ it('re-arms once a retry makes progress', () => {
213
+ const onLoadMore = vi.fn();
214
+ const { rerender } = render(<Table data={rows(3)} onLoadMore={onLoadMore} />);
215
+
216
+ rerender(<Table data={rows(3)} isFetchingNextPage onLoadMore={onLoadMore} />);
217
+ rerender(<Table data={rows(3)} onLoadMore={onLoadMore} />);
218
+ expect(screen.getByRole('button', { name: 'Load more' })).toBeDefined();
219
+
220
+ rerender(<Table data={rows(3)} isFetchingNextPage onLoadMore={onLoadMore} />);
221
+ rerender(<Table data={rows(6)} onLoadMore={onLoadMore} />);
222
+
223
+ expect(screen.queryByRole('button', { name: 'Load more' })).toBeNull();
224
+ expect(liveObservers()).toHaveLength(1);
225
+ });
226
+
227
+ it('re-arms when the rows are replaced under a parked footer (a new search)', () => {
228
+ const onLoadMore = vi.fn();
229
+ const { rerender } = render(<Table data={rows(3)} onLoadMore={onLoadMore} />);
230
+
231
+ rerender(<Table data={rows(3)} isFetchingNextPage onLoadMore={onLoadMore} />);
232
+ rerender(<Table data={rows(3)} onLoadMore={onLoadMore} />);
233
+ expect(liveObservers()).toHaveLength(0);
234
+
235
+ rerender(<Table data={rows(5)} onLoadMore={onLoadMore} />);
236
+ expect(liveObservers()).toHaveLength(1);
237
+ });
238
+
239
+ it('tells a screen reader that more is loading', () => {
240
+ const { rerender } = render(<Table data={rows(3)} onLoadMore={vi.fn()} />);
241
+ expect(screen.getByRole('status').textContent).toBe('');
242
+
243
+ rerender(<Table data={rows(3)} isFetchingNextPage onLoadMore={vi.fn()} />);
244
+ expect(screen.getByRole('status').textContent).toBe('Loading more results');
245
+ });
246
+ });
@@ -37,13 +37,7 @@ function Table({
37
37
  const table = useDataTable({ data, columns });
38
38
  return (
39
39
  <DataTable table={table}>
40
- <DataTable.Body<Row>
41
- loading={loading}
42
- minRows={4}
43
- skeletonRows={4}
44
- autoHeight
45
- rowHeightClassName={rowHeightClassName}
46
- />
40
+ <DataTable.Body<Row> loading={loading} minRows={4} skeletonRows={4} rowHeightClassName={rowHeightClassName} />
47
41
  </DataTable>
48
42
  );
49
43
  }
@@ -0,0 +1,147 @@
1
+ import { createColumnHelper } from '@tanstack/react-table';
2
+ import { render } from '@testing-library/react';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { DataTable } from '../components/ui/data-table';
5
+ import { useDataTable } from '../components/ui/data-table/use-data-table';
6
+
7
+ /**
8
+ * A skeleton row stands in for a real row, so it has to occupy the same slot:
9
+ * same container, same gap, same consumer row classes. Two places broke that.
10
+ *
11
+ * - The loading body dropped `rowClassName`. Tables put their row spacing
12
+ * there (`mb-1`), so a loading table stacked 4px tighter per row than the
13
+ * loaded one and every row below the first moved when the data arrived.
14
+ * - The infinite footer drew its load-more skeleton as a bare child of the
15
+ * table root: no gap container, no row classes. The placeholder rows touched
16
+ * each other and the page shifted when the next page replaced them.
17
+ *
18
+ * `data-table-row-height.test.tsx` locks the HEIGHT of every slot; this locks
19
+ * where the slots stack and what spaces them.
20
+ */
21
+
22
+ interface Row {
23
+ id: string;
24
+ name: string;
25
+ }
26
+
27
+ const columnHelper = createColumnHelper<Row>();
28
+ const columns = [columnHelper.accessor('name', { id: 'name', header: 'Name' })];
29
+
30
+ const ROW_SPACING = 'mb-1';
31
+ const ROW_H = 'h-[112px]';
32
+
33
+ const rows = (n: number): Row[] => Array.from({ length: n }, (_, i) => ({ id: String(i), name: `Row ${i}` }));
34
+ const noop = () => undefined;
35
+
36
+ function Table({
37
+ data,
38
+ loading = false,
39
+ isFetchingNextPage = false,
40
+ rowClassName = ROW_SPACING,
41
+ minRows,
42
+ }: {
43
+ data: Row[];
44
+ loading?: boolean;
45
+ isFetchingNextPage?: boolean;
46
+ rowClassName?: string | ((item: Row) => string);
47
+ minRows?: number;
48
+ }) {
49
+ const table = useDataTable({ data, columns });
50
+ return (
51
+ <DataTable table={table}>
52
+ <DataTable.Body<Row>
53
+ loading={loading}
54
+ skeletonRows={3}
55
+ minRows={minRows}
56
+ rowClassName={rowClassName}
57
+ rowHeightClassName={ROW_H}
58
+ />
59
+ <DataTable.InfiniteFooter
60
+ // No next page, so the sentinel (and jsdom's missing IntersectionObserver) stays out of it.
61
+ hasNextPage={false}
62
+ isFetchingNextPage={isFetchingNextPage}
63
+ onLoadMore={noop}
64
+ skeletonRows={2}
65
+ />
66
+ </DataTable>
67
+ );
68
+ }
69
+
70
+ type SlotKind = 'row' | 'skeleton' | 'pad';
71
+
72
+ /**
73
+ * Every row-card slot in the rendered markup, in document order.
74
+ *
75
+ * Read off the markup, as `data-table-row-height.test.tsx` does: what spaces a
76
+ * slot is exactly what ships in its class attribute.
77
+ */
78
+ function slots(container: HTMLElement): { kind: SlotKind; classes: string[] }[] {
79
+ return [...container.innerHTML.matchAll(/class="([^"]*\brounded-md\b[^"]*)"/g)].map(match => {
80
+ const classes = (match[1] ?? '').split(/\s+/);
81
+ const kind: SlotKind = classes.includes('animate-pulse')
82
+ ? 'skeleton'
83
+ : classes.includes('border-transparent')
84
+ ? 'pad'
85
+ : 'row';
86
+ return { kind, classes };
87
+ });
88
+ }
89
+
90
+ const skeletonSlots = (container: HTMLElement) => slots(container).filter(slot => slot.kind === 'skeleton');
91
+
92
+ /** How many row stacks (the body's gap container, or the footer's fallback one) the markup holds. */
93
+ const stackCount = (container: HTMLElement) => container.innerHTML.split('gap-[var(--spacing-system-xsf)]').length - 1;
94
+
95
+ describe('DataTable skeleton row rhythm', () => {
96
+ it('spaces the LOADING skeleton with the same rowClassName as the rows it stands in for', () => {
97
+ const { container } = render(<Table data={[]} loading />);
98
+ const skeleton = skeletonSlots(container);
99
+
100
+ expect(skeleton).toHaveLength(3);
101
+ expect(skeleton.every(slot => slot.classes.includes(ROW_SPACING))).toBe(true);
102
+ });
103
+
104
+ it('gives load-more skeleton rows the row spacing AND the row height', () => {
105
+ const { container } = render(<Table data={rows(2)} isFetchingNextPage />);
106
+ const skeleton = skeletonSlots(container);
107
+
108
+ expect(skeleton).toHaveLength(2);
109
+ expect(skeleton.every(slot => slot.classes.includes(ROW_SPACING) && slot.classes.includes(ROW_H))).toBe(true);
110
+ });
111
+
112
+ it('draws the load-more skeleton INSIDE the body, continuing its rows', () => {
113
+ // Pad rows are the body's last children, so placeholders that come BEFORE
114
+ // them sit in the body's own container — under its gap — and not beside it
115
+ // under the table root, where they used to stack with no gap at all.
116
+ const { container } = render(<Table data={rows(2)} isFetchingNextPage minRows={6} />);
117
+
118
+ expect(slots(container).map(slot => slot.kind)).toEqual(['row', 'row', 'skeleton', 'skeleton', 'pad', 'pad']);
119
+ // One stack: the body's. The footer added none of its own.
120
+ expect(stackCount(container)).toBe(1);
121
+ });
122
+
123
+ it('removes them when the page has arrived', () => {
124
+ const { container, rerender } = render(<Table data={rows(2)} isFetchingNextPage />);
125
+ expect(skeletonSlots(container)).toHaveLength(2);
126
+
127
+ rerender(<Table data={rows(4)} />);
128
+ expect(slots(container).map(slot => slot.kind)).toEqual(['row', 'row', 'row', 'row']);
129
+ });
130
+
131
+ it('skips a FUNCTION rowClassName — there is no item to call it with', () => {
132
+ const { container } = render(<Table data={rows(2)} isFetchingNextPage rowClassName={() => 'from-fn'} />);
133
+ const skeleton = skeletonSlots(container);
134
+
135
+ expect(skeleton).toHaveLength(2);
136
+ expect(skeleton.some(slot => slot.classes.includes('from-fn'))).toBe(false);
137
+ });
138
+
139
+ it('still stacks a skeleton when the body has no rows to continue', () => {
140
+ // An empty body does not take the rows over, so the footer draws its own —
141
+ // in a stack of its own rather than bare under the table root.
142
+ const { container } = render(<Table data={[]} isFetchingNextPage />);
143
+
144
+ expect(skeletonSlots(container)).toHaveLength(2);
145
+ expect(stackCount(container)).toBe(2);
146
+ });
147
+ });
@@ -1,12 +1,14 @@
1
1
  'use client';
2
2
 
3
- import type { ReactNode } from 'react';
3
+ import { useSyncExternalStore, type ReactNode } from 'react';
4
+ import { useIsomorphicLayoutEffect } from '../../../hooks/ui/use-isomorphic-layout-effect';
4
5
  import { cn } from '../../../utils/cn';
5
6
  import type { NoDataProps } from '../no-data';
6
7
  import { useDataTableContext } from './data-table';
7
8
  import { DataTableEmpty } from './data-table-empty';
9
+ import { useDataTableLoadMoreStore } from './data-table-load-more';
8
10
  import { DataTableRow } from './data-table-row';
9
- import { DataTableSkeleton, PlaceholderRows, ReservedEmptyState } from './data-table-skeleton';
11
+ import { DataTableSkeleton, PlaceholderRows, ReservedEmptyState, ROW_STACK_CLASSES } from './data-table-skeleton';
10
12
 
11
13
  export interface DataTableBodyProps<T = unknown> {
12
14
  /** Show skeleton rows while `loading` is true and data is empty. */
@@ -21,22 +23,31 @@ export interface DataTableBodyProps<T = unknown> {
21
23
  /**
22
24
  * Per-row class name. Prefer `useCallback` for function form to avoid
23
25
  * breaking `React.memo` on rows.
26
+ *
27
+ * The STRING form also lands on every skeleton row this body draws — the
28
+ * loading state and the infinite footer's load-more rows. It is where tables
29
+ * put their row spacing (`mb-1` is the common one), and a skeleton without it
30
+ * stacks at a tighter pitch than the rows it stands in for: 4px per row,
31
+ * accumulating, so row 20 of a loading table sat 80px above where it loaded.
32
+ * The function form has no item to be called with and is skipped there.
24
33
  */
25
34
  rowClassName?: string | ((item: T, index: number) => string);
26
35
  /** Dense row height. */
27
36
  compact?: boolean;
28
- /**
29
- * Treat the design row height as a minimum so multi-line cell content grows
30
- * the row instead of clipping. Default keeps the fixed height.
31
- */
32
- autoHeight?: boolean;
33
37
  /**
34
38
  * REPLACES the design row height for THIS table's rows, its pad rows and its
35
39
  * skeleton alike — one number, so they cannot disagree.
36
40
  *
41
+ * It is also the ONLY way to a taller row. There used to be an `autoHeight`
42
+ * flag that let a row grow with its content; it was removed because a row
43
+ * whose height depends on its data cannot be stood in for — every skeleton
44
+ * and pad row is a guess, and the list jumps by the error on every load. Fit
45
+ * the content to the row instead (`TruncateText lines={n}` keeps the rest in
46
+ * a tooltip), or state a taller row here.
47
+ *
37
48
  * Why a prop and not a className: `minRows` promises a stable table height,
38
49
  * but its pad rows and the skeleton were hard-coded to the design height
39
- * while a row passing `autoHeight` renders as tall as its content. A table
50
+ * while the table's real rows were taller. A table
40
51
  * with 112px rows padded a short page with 78px placeholders and came up
41
52
  * 34px per missing row too short — on a 15-row page with 5 results, 340px of
42
53
  * jump against every other page. Appending a height through `rowClassName`
@@ -70,6 +81,9 @@ export interface DataTableBodyProps<T = unknown> {
70
81
  renderSubRow?: (item: T) => ReactNode;
71
82
  }
72
83
 
84
+ /** Server snapshot: no page is loading during a server render. */
85
+ const getNoRows = () => 0;
86
+
73
87
  /**
74
88
  * Renders skeleton / empty state / rows based on table context state. Place
75
89
  * inside `<DataTable>`. Rows use `React.memo` for performance — memoize
@@ -84,7 +98,6 @@ export function DataTableBody<T = unknown>({
84
98
  className,
85
99
  rowClassName,
86
100
  compact,
87
- autoHeight,
88
101
  rowHeightClassName,
89
102
  onRowClick,
90
103
  rowHref,
@@ -93,16 +106,32 @@ export function DataTableBody<T = unknown>({
93
106
  }: DataTableBodyProps<T>) {
94
107
  const table = useDataTableContext<T>();
95
108
  const rows = table.getRowModel().rows;
109
+ const hasRows = rows.length > 0;
96
110
 
97
- if (loading && rows.length === 0) {
111
+ // Load-more skeleton rows requested by `<DataTable.InfiniteFooter>`. Drawn
112
+ // HERE, inside the rows' own container, so they take this body's gap and row
113
+ // classes by construction — see `data-table-load-more.ts`. Only a body that
114
+ // has rows to continue takes them over; an empty or loading one leaves the
115
+ // footer drawing its own, as before.
116
+ const loadMore = useDataTableLoadMoreStore();
117
+ const loadMoreRows = useSyncExternalStore(loadMore.subscribe, loadMore.getSkeletonRows, getNoRows);
118
+ useIsomorphicLayoutEffect(() => (hasRows ? loadMore.registerRowsBody() : undefined), [loadMore, hasRows]);
119
+
120
+ const skeletonRowClassName = typeof rowClassName === 'string' ? rowClassName : undefined;
121
+
122
+ if (loading && !hasRows) {
98
123
  return (
99
- <div className={cn('flex w-full flex-col gap-[var(--spacing-system-xsf)]', className)}>
100
- <DataTableSkeleton rows={skeletonRows} rowHeightClassName={rowHeightClassName} />
124
+ <div className={cn(ROW_STACK_CLASSES, className)}>
125
+ <DataTableSkeleton
126
+ rows={skeletonRows}
127
+ className={skeletonRowClassName}
128
+ rowHeightClassName={rowHeightClassName}
129
+ />
101
130
  </div>
102
131
  );
103
132
  }
104
133
 
105
- if (rows.length === 0) {
134
+ if (!hasRows) {
106
135
  const empty = emptyState ? (
107
136
  <DataTableEmpty {...emptyState} />
108
137
  ) : emptyMessage != null ? (
@@ -127,13 +156,14 @@ export function DataTableBody<T = unknown>({
127
156
  );
128
157
  }
129
158
 
130
- return <div className={cn('flex w-full flex-col gap-[var(--spacing-system-xsf)]', className)}>{empty}</div>;
159
+ return <div className={cn(ROW_STACK_CLASSES, className)}>{empty}</div>;
131
160
  }
132
161
 
133
- const padCount = minRows ? Math.max(0, minRows - rows.length) : 0;
162
+ // Load-more rows are row slots too, so they count against `minRows`.
163
+ const padCount = minRows ? Math.max(0, minRows - rows.length - loadMoreRows) : 0;
134
164
 
135
165
  return (
136
- <div className={cn('flex w-full flex-col gap-[var(--spacing-system-xsf)]', className)}>
166
+ <div className={cn(ROW_STACK_CLASSES, className)}>
137
167
  {rows.map((row, index) => {
138
168
  const item = row.original;
139
169
  const href = rowHref?.(item) ?? undefined;
@@ -145,13 +175,19 @@ export function DataTableBody<T = unknown>({
145
175
  onClick={onRowClick}
146
176
  href={href}
147
177
  compact={compact}
148
- autoHeight={autoHeight}
149
178
  rowHeightClassName={rowHeightClassName}
150
179
  className={cls}
151
180
  subRow={renderSubRow?.(item)}
152
181
  />
153
182
  );
154
183
  })}
184
+ {loadMoreRows > 0 && (
185
+ <DataTableSkeleton
186
+ rows={loadMoreRows}
187
+ className={skeletonRowClassName}
188
+ rowHeightClassName={rowHeightClassName}
189
+ />
190
+ )}
155
191
  {padCount > 0 && <PlaceholderRows count={padCount} rowHeightClassName={rowHeightClassName} />}
156
192
  </div>
157
193
  );