@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
@@ -1,7 +1,11 @@
1
1
  'use client';
2
2
 
3
- import { useEffect, useRef } from 'react';
4
- import { DataTableSkeleton } from './data-table-skeleton';
3
+ import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
4
+ import { useIsomorphicLayoutEffect } from '../../../hooks/ui/use-isomorphic-layout-effect';
5
+ import { Button } from '../button';
6
+ import { useOptionalDataTableContext } from './data-table';
7
+ import { useDataTableLoadMoreStore } from './data-table-load-more';
8
+ import { DataTableSkeleton, ROW_STACK_CLASSES } from './data-table-skeleton';
5
9
 
6
10
  export interface DataTableInfiniteFooterProps {
7
11
  hasNextPage: boolean;
@@ -9,20 +13,88 @@ export interface DataTableInfiniteFooterProps {
9
13
  onLoadMore: () => void;
10
14
  /** Skeleton rows shown while fetching. Default `3`. */
11
15
  skeletonRows?: number;
12
- /** `IntersectionObserver` rootMargin. Default `'200px'`. */
16
+ /**
17
+ * `IntersectionObserver` rootMargin — how far ahead of the sentinel the next
18
+ * page is requested. Default `'0px 0px 100% 0px'`: one scroller-height below
19
+ * the fold, so at a reading pace the rows are there before the user is.
20
+ * A percentage resolves against the scroller, so the lead scales with the
21
+ * screen instead of being two rows on every device.
22
+ */
13
23
  rootMargin?: string;
24
+ /**
25
+ * Rows LOADED so far, before any client-side narrowing. Pass it when the
26
+ * table shows fewer rows than it has fetched — a search box or an ownership
27
+ * filter applied over the loaded pages.
28
+ *
29
+ * The footer parks itself when a fetch adds nothing (see below), and it
30
+ * judges "nothing" by the table's rows. For such a table a page can arrive in
31
+ * full and still add no VISIBLE row, which is not a stall: the match may be on
32
+ * the next page, and walking on is the only way to reach it. This is the
33
+ * count that does move then.
34
+ */
35
+ loadedCount?: number;
36
+ }
37
+
38
+ const DEFAULT_ROOT_MARGIN = '0px 0px 100% 0px';
39
+
40
+ /** Server snapshot: effects have not run, so no body has registered yet. */
41
+ const getNoBody = () => false;
42
+
43
+ /**
44
+ * The nearest ancestor that actually scrolls vertically, or `null` for the
45
+ * viewport.
46
+ *
47
+ * It has to be the observer's `root`, because `rootMargin` grows the ROOT's box
48
+ * and nothing else: on the way up from the target every scrolling ancestor
49
+ * clips the intersection to its own scrollport, margin or not. The apps scroll
50
+ * `AppLayout`'s `<main className="overflow-y-auto">`, not the window, so an
51
+ * observer rooted on the viewport had its 200px lead clipped away entirely —
52
+ * measured, the request went out with the sentinel 7px from the fold, i.e. once
53
+ * the user had already run out of rows, on every page.
54
+ *
55
+ * `scrollHeight > clientHeight` is what makes it "actually scrolls": an
56
+ * `overflow-x-auto` wrapper (tables get one for narrow screens) computes
57
+ * `overflow-y: auto` too, and as a root it would be as tall as the whole table —
58
+ * the sentinel would sit inside it permanently and every page would load at once.
59
+ * `<body>` / `<html>` stop the walk for the same reason: a page that scrolls the
60
+ * document is the viewport case, and the element itself is document-tall.
61
+ */
62
+ function findScrollParent(element: HTMLElement): HTMLElement | null {
63
+ const { body, documentElement } = element.ownerDocument;
64
+ for (let node = element.parentElement; node && node !== body && node !== documentElement; node = node.parentElement) {
65
+ const { overflowY } = getComputedStyle(node);
66
+ if ((overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight) return node;
67
+ }
68
+ return null;
14
69
  }
15
70
 
16
71
  /**
17
72
  * Infinite-scroll trigger for a `DataTable`. Place after `<DataTable.Body>`.
18
- * When the sentinel intersects the viewport, calls `onLoadMore`.
73
+ * When the sentinel comes within `rootMargin` of the scroller's fold, calls
74
+ * `onLoadMore`.
75
+ *
76
+ * The skeleton rows shown while fetching are drawn by the BODY, not here: they
77
+ * have to continue its rows at the same pitch, and only the body knows its gap,
78
+ * `rowClassName` and `rowHeightClassName`. This component asks for them through
79
+ * the table's load-more store (`data-table-load-more.ts`) and draws its own
80
+ * only when there is no body with rows to continue.
81
+ *
82
+ * **It stops asking when asking gets nowhere.** A fetch that ends with no new
83
+ * row — a failed request, or a server answering an empty page that still claims
84
+ * a next one — used to re-arm the observer with the sentinel still in view, so
85
+ * the same request went straight back out: a tight loop against the API, one
86
+ * error toast per lap, until the user scrolled away. Now that outcome parks the
87
+ * auto-trigger and offers a Load more button instead; the next fetch that makes
88
+ * progress re-arms it. A table that narrows its loaded pages on the client must
89
+ * pass `loadedCount`, or a page with no visible match reads as no progress.
19
90
  */
20
91
  export function DataTableInfiniteFooter({
21
92
  hasNextPage,
22
93
  isFetchingNextPage,
23
94
  onLoadMore,
24
95
  skeletonRows = 3,
25
- rootMargin = '200px',
96
+ rootMargin = DEFAULT_ROOT_MARGIN,
97
+ loadedCount,
26
98
  }: DataTableInfiniteFooterProps) {
27
99
  const sentinelRef = useRef<HTMLDivElement>(null);
28
100
  // Refreshed after every commit, declared before the observer effect so it
@@ -33,23 +105,80 @@ export function DataTableInfiniteFooter({
33
105
  onLoadMoreRef.current = onLoadMore;
34
106
  });
35
107
 
108
+ const loadMore = useDataTableLoadMoreStore();
109
+ const bodyDrawsRows = useSyncExternalStore(loadMore.subscribe, loadMore.getHasRowsBody, getNoBody);
110
+ const requestedRows = isFetchingNextPage ? skeletonRows : 0;
111
+ // A layout effect, so the body's re-render lands before paint: no frame
112
+ // between "fetching" and the rows appearing.
113
+ useIsomorphicLayoutEffect(() => {
114
+ loadMore.setSkeletonRows(requestedRows);
115
+ return () => loadMore.setSkeletonRows(0);
116
+ }, [loadMore, requestedRows]);
117
+
118
+ // Did the last fetch add anything? Read off the table's own rows, which needs
119
+ // no cooperation from the consumer — no error prop to forget to pass; only a
120
+ // table that narrows its loaded pages has to say so, through `loadedCount`. The
121
+ // TAIL (how many rows, and which one is last) rather than the count alone: a
122
+ // search that replaces 40 rows with 20 while a page is in flight ends that
123
+ // fetch with FEWER rows, and that is a new list, not a stalled one.
124
+ const tableRows = useOptionalDataTableContext()?.getRowModel().rows;
125
+ const progressCount = loadedCount ?? tableRows?.length;
126
+ const lastRowId = tableRows?.[tableRows.length - 1]?.id ?? '';
127
+ const tail = progressCount === undefined ? null : `${progressCount}:${lastRowId}`;
128
+ // Adjusted during render, not in an effect, so the verdict lands in the same
129
+ // commit as the fetch ending — before the observer effect can re-arm.
130
+ const [wasFetching, setWasFetching] = useState(isFetchingNextPage);
131
+ const [tailAtFetchStart, setTailAtFetchStart] = useState<string | null>(null);
132
+ const [stalledTail, setStalledTail] = useState<string | null>(null);
133
+ if (wasFetching !== isFetchingNextPage) {
134
+ setWasFetching(isFetchingNextPage);
135
+ if (isFetchingNextPage) {
136
+ setTailAtFetchStart(tail);
137
+ setStalledTail(null);
138
+ } else if (tail !== null && tail === tailAtFetchStart) {
139
+ setStalledTail(tail);
140
+ }
141
+ }
142
+ // Keyed on the tail it was decided at: rows that change afterwards (a late
143
+ // render, a new search) lift it without anyone having to remember to.
144
+ const isStalled = hasNextPage && !isFetchingNextPage && stalledTail !== null && stalledTail === tail;
145
+
36
146
  useEffect(() => {
37
- if (!hasNextPage || isFetchingNextPage) return undefined;
147
+ if (!hasNextPage || isFetchingNextPage || isStalled) return undefined;
38
148
  const sentinel = sentinelRef.current;
39
149
  if (!sentinel) return undefined;
150
+ // Re-created after every page, which is also what chains the next request
151
+ // when one page was not enough to push the sentinel out of range: a new
152
+ // observer always reports where its target stands.
40
153
  const observer = new IntersectionObserver(
41
154
  entries => {
42
155
  if (entries[0]?.isIntersecting) onLoadMoreRef.current();
43
156
  },
44
- { rootMargin },
157
+ { root: findScrollParent(sentinel), rootMargin },
45
158
  );
46
159
  observer.observe(sentinel);
47
160
  return () => observer.disconnect();
48
- }, [hasNextPage, isFetchingNextPage, rootMargin]);
161
+ }, [hasNextPage, isFetchingNextPage, isStalled, rootMargin]);
49
162
 
50
163
  return (
51
164
  <>
52
- {isFetchingNextPage && <DataTableSkeleton rows={skeletonRows} />}
165
+ {isFetchingNextPage && !bodyDrawsRows && (
166
+ <div className={ROW_STACK_CLASSES}>
167
+ <DataTableSkeleton rows={skeletonRows} />
168
+ </div>
169
+ )}
170
+ {isStalled && (
171
+ <div className="flex justify-center pt-[var(--spacing-system-mf)]">
172
+ <Button variant="outline" onClick={onLoadMore}>
173
+ Load more
174
+ </Button>
175
+ </div>
176
+ )}
177
+ {/* The skeleton rows are purely visual, so this is the only signal a
178
+ screen reader gets that the list is growing under it. */}
179
+ <div role="status" className="sr-only">
180
+ {isFetchingNextPage ? 'Loading more results' : ''}
181
+ </div>
53
182
  {hasNextPage && <div ref={sentinelRef} className="h-1" aria-hidden="true" />}
54
183
  </>
55
184
  );
@@ -0,0 +1,87 @@
1
+ 'use client';
2
+
3
+ import { createContext, useContext } from 'react';
4
+
5
+ /**
6
+ * The channel between `<DataTable.InfiniteFooter>` and `<DataTable.Body>`.
7
+ *
8
+ * The footer knows WHEN a next page is loading; the body knows HOW a row slot is
9
+ * spaced — its own `gap`, the consumer's `rowClassName`, `rowHeightClassName`.
10
+ * The footer used to draw the load-more skeleton itself, as a sibling of the
11
+ * body: outside the body's gap container and without the row classes, so the
12
+ * placeholder rows sat glued together and the page shifted when the real rows
13
+ * replaced them. Teaching the footer the body's spacing would be a second
14
+ * declaration of it at every call site. Instead the footer states a row count
15
+ * here and the body draws those rows inside its OWN container, so they take the
16
+ * body's spacing by construction.
17
+ *
18
+ * A store rather than context state: the two are siblings, the write happens in
19
+ * a layout effect, and `useSyncExternalStore` re-renders the reader before
20
+ * paint — no frame with the rows in the wrong place.
21
+ */
22
+ export interface DataTableLoadMoreStore {
23
+ subscribe: (listener: () => void) => () => void;
24
+ /** Skeleton rows the footer is asking for; `0` when no page is loading. */
25
+ getSkeletonRows: () => number;
26
+ setSkeletonRows: (rows: number) => void;
27
+ /**
28
+ * Whether a body is on screen WITH rows to continue. Without one (an empty or
29
+ * still-loading body, or no body at all) the footer keeps drawing its own
30
+ * skeleton, as it always has.
31
+ */
32
+ getHasRowsBody: () => boolean;
33
+ /** Returns the unregister function — hand it straight back from an effect. */
34
+ registerRowsBody: () => () => void;
35
+ }
36
+
37
+ export function createDataTableLoadMoreStore(): DataTableLoadMoreStore {
38
+ const listeners = new Set<() => void>();
39
+ let skeletonRows = 0;
40
+ let rowsBodies = 0;
41
+
42
+ const notify = () => {
43
+ for (const listener of listeners) listener();
44
+ };
45
+
46
+ return {
47
+ subscribe: listener => {
48
+ listeners.add(listener);
49
+ return () => {
50
+ listeners.delete(listener);
51
+ };
52
+ },
53
+ getSkeletonRows: () => skeletonRows,
54
+ setSkeletonRows: rows => {
55
+ if (rows === skeletonRows) return;
56
+ skeletonRows = rows;
57
+ notify();
58
+ },
59
+ getHasRowsBody: () => rowsBodies > 0,
60
+ registerRowsBody: () => {
61
+ rowsBodies += 1;
62
+ notify();
63
+ return () => {
64
+ rowsBodies -= 1;
65
+ notify();
66
+ };
67
+ },
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Inert default, so a footer rendered outside a `<DataTable>` keeps working as
73
+ * a bare sentinel instead of throwing over a channel it has no use for.
74
+ */
75
+ const NO_LOAD_MORE_STORE: DataTableLoadMoreStore = {
76
+ subscribe: () => () => {},
77
+ getSkeletonRows: () => 0,
78
+ setSkeletonRows: () => {},
79
+ getHasRowsBody: () => false,
80
+ registerRowsBody: () => () => {},
81
+ };
82
+
83
+ export const DataTableLoadMoreContext = createContext<DataTableLoadMoreStore>(NO_LOAD_MORE_STORE);
84
+
85
+ export function useDataTableLoadMoreStore(): DataTableLoadMoreStore {
86
+ return useContext(DataTableLoadMoreContext);
87
+ }
@@ -15,14 +15,8 @@ export interface DataTableRowProps<T> {
15
15
  /** Dense row height. */
16
16
  compact?: boolean;
17
17
  /**
18
- * Treat the design row height as a minimum: a cell rendering multi-line
19
- * content (e.g. a line-clamped description) grows the row instead of being
20
- * clipped. Default keeps the fixed height.
21
- */
22
- autoHeight?: boolean;
23
- /**
24
- * REPLACES the height this row would otherwise take (`compact`, `autoHeight`
25
- * or the design default). The one place a table states how tall a row is, so
18
+ * REPLACES the height this row would otherwise take (`compact` or the design
19
+ * default). The one place a table states how tall a row is, so
26
20
  * the pad rows and the skeleton can reserve the SAME number — see
27
21
  * `DataTableBodyProps.rowHeightClassName`.
28
22
  *
@@ -79,7 +73,6 @@ function DataTableRowImpl<T>({
79
73
  onClick,
80
74
  href,
81
75
  compact,
82
- autoHeight,
83
76
  rowHeightClassName,
84
77
  className,
85
78
  subRow,
@@ -112,6 +105,11 @@ function DataTableRowImpl<T>({
112
105
 
113
106
  const containerClassName = cn(
114
107
  'overflow-hidden rounded-md border border-ods-border bg-ods-card text-inherit no-underline',
108
+ // A row fades in when it MOUNTS — so a loaded page eases in over the
109
+ // skeleton it replaces instead of snapping, and rows that were already on
110
+ // screen (keyed by id) do not replay it. Opacity only: nothing that moves
111
+ // or resizes the slot, which is the whole point of the fixed row height.
112
+ 'duration-200 animate-in fade-in-0 motion-reduce:animate-none',
115
113
  // A stated slot height goes HERE, on the card, with the cells flexing to
116
114
  // fill whatever the sub-row leaves. `border-box` sizing means the number a
117
115
  // caller writes is the number the row occupies, borders included.
@@ -130,9 +128,7 @@ function DataTableRowImpl<T>({
130
128
  ? 'min-h-0 flex-1 py-0'
131
129
  : compact
132
130
  ? 'py-[var(--spacing-system-xsf)]'
133
- : autoHeight
134
- ? 'min-h-[66px] py-[var(--spacing-system-sf)] md:min-h-[78px]'
135
- : `py-0 ${ROW_HEIGHT_DESKTOP}`,
131
+ : `py-0 ${ROW_HEIGHT_DESKTOP}`,
136
132
  hasSubRow && 'border-b border-ods-border',
137
133
  )}
138
134
  >
@@ -26,6 +26,16 @@ export const ROW_HEIGHT_MOBILE = 'h-[66px]';
26
26
  */
27
27
  export const ROW_SHELL_CLASSES = 'items-center gap-[var(--spacing-system-mf)] px-[var(--spacing-system-mf)]';
28
28
 
29
+ /**
30
+ * The column every row slot stacks in, and the gap between two of them.
31
+ *
32
+ * One constant for the same reason as `ROW_SHELL_CLASSES`: the body's rows, its
33
+ * loading skeleton and the infinite footer's fallback skeleton all stack here,
34
+ * and the footer used to stack in nothing at all — its placeholder rows were
35
+ * bare children of the table root, touching each other.
36
+ */
37
+ export const ROW_STACK_CLASSES = 'flex w-full flex-col gap-[var(--spacing-system-xsf)]';
38
+
29
39
  export interface DataTableSkeletonProps {
30
40
  rows?: number;
31
41
  className?: string;
@@ -1,8 +1,9 @@
1
1
  'use client';
2
2
 
3
3
  import type { Table } from '@tanstack/react-table';
4
- import { createContext, useContext, type ReactNode } from 'react';
4
+ import { createContext, useContext, useState, type ReactNode } from 'react';
5
5
  import { cn } from '../../../utils/cn';
6
+ import { createDataTableLoadMoreStore, DataTableLoadMoreContext } from './data-table-load-more';
6
7
  import './types';
7
8
 
8
9
  // The context holds the table at its ERASED row type; each `useDataTableContext<T>`
@@ -18,6 +19,15 @@ export function useDataTableContext<T = unknown>(): Table<T> {
18
19
  return ctx as Table<T>;
19
20
  }
20
21
 
22
+ /**
23
+ * The table, or `null` outside a `<DataTable>`. For the one sub-component that
24
+ * has a job to do without a table: `<DataTable.InfiniteFooter>` is still a
25
+ * working scroll sentinel there, it just cannot tell whether a page added rows.
26
+ */
27
+ export function useOptionalDataTableContext(): Table<unknown> | null {
28
+ return useContext(DataTableContext);
29
+ }
30
+
21
31
  export interface DataTableProps<T> {
22
32
  table: Table<T>;
23
33
  children: ReactNode;
@@ -25,13 +35,19 @@ export interface DataTableProps<T> {
25
35
  }
26
36
 
27
37
  export function DataTableRoot<T>({ table, children, className }: DataTableProps<T>) {
38
+ // One per table: how `<DataTable.InfiniteFooter>` hands its load-more rows to
39
+ // `<DataTable.Body>` — see `data-table-load-more.ts`.
40
+ const [loadMoreStore] = useState(createDataTableLoadMoreStore);
41
+
28
42
  // Erase the row type on the way in; `useDataTableContext<T>` restores it on
29
43
  // the way out. `Table<T>` is invariant in `T`, so this assertion pair is
30
44
  // what an erased context costs — it replaces a `Table<any>` context that
31
45
  // erased the row type for every consumer, not just at the seam.
32
46
  return (
33
47
  <DataTableContext.Provider value={table as Table<unknown>}>
34
- <div className={cn('flex w-full flex-col', className)}>{children}</div>
48
+ <DataTableLoadMoreContext.Provider value={loadMoreStore}>
49
+ <div className={cn('flex w-full flex-col', className)}>{children}</div>
50
+ </DataTableLoadMoreContext.Provider>
35
51
  </DataTableContext.Provider>
36
52
  );
37
53
  }
@@ -99,6 +99,9 @@ const DEVICES_10 = DEVICES.slice(0, 10);
99
99
  const DEVICES_12 = DEVICES.slice(0, 12);
100
100
  const DEVICES_30 = makeDevices(30);
101
101
  const DEVICES_50 = makeDevices(50);
102
+ /** Stable empty page for the loading-state stories (`data` must be reference-stable). */
103
+ const NO_DEVICES: Device[] = [];
104
+ const noopLoadMore = () => undefined;
102
105
 
103
106
  /* ─────────────────────────── shared cell renderers ──────────────────────────── */
104
107
 
@@ -903,6 +906,124 @@ export const InfiniteScroll: Story = {
903
906
  },
904
907
  };
905
908
 
909
+ /**
910
+ * **Infinite scroll inside a scroll container** — the layout the apps actually
911
+ * ship: `AppLayout` scrolls its `<main className="overflow-y-auto">`, not the
912
+ * window. The table sits in a fixed-height scroller here for the same reason.
913
+ *
914
+ * This is the case to test pre-fetching against. An observer rooted on the
915
+ * viewport has its `rootMargin` clipped by every scrolling ancestor, so a
916
+ * margin that works in the window-scrolled story above does nothing in here.
917
+ */
918
+ export const InfiniteScrollInScrollContainer: Story = {
919
+ render: () => {
920
+ const [rows, setRows] = useState<Device[]>(() => makeDevices(20));
921
+ const [isFetching, setIsFetching] = useState(false);
922
+ const [hasNext, setHasNext] = useState(true);
923
+ const pageRef = useRef(1);
924
+
925
+ const columns = useMemo<ColumnDef<Device>[]>(
926
+ () => [
927
+ { accessorKey: 'hostname', header: 'Hostname', meta: { width: 'w-[200px]' } },
928
+ { accessorKey: 'ipAddress', header: 'IP', meta: { width: 'w-[140px]' } },
929
+ {
930
+ accessorKey: 'status',
931
+ header: 'Status',
932
+ cell: ({ row }) => <StatusTag status={row.original.status} />,
933
+ meta: { width: 'w-[140px]' },
934
+ },
935
+ { accessorKey: 'os', header: 'OS', meta: { width: 'flex-1 min-w-0' } },
936
+ ],
937
+ [],
938
+ );
939
+
940
+ const table = useDataTable<Device>({ data: rows, columns });
941
+
942
+ const loadMore = useCallback(() => {
943
+ if (isFetching || !hasNext) return;
944
+ setIsFetching(true);
945
+ window.setTimeout(() => {
946
+ pageRef.current += 1;
947
+ setRows(prev => [...prev, ...makeDevices(20, prev.length + 1)]);
948
+ setIsFetching(false);
949
+ if (pageRef.current >= 6) setHasNext(false);
950
+ }, 700);
951
+ }, [isFetching, hasNext]);
952
+
953
+ return (
954
+ <div data-testid="scroller" className="h-[640px] overflow-y-auto rounded-md border border-ods-border">
955
+ <div className="p-[var(--spacing-system-mf)]">
956
+ <DataTable table={table}>
957
+ <DataTable.Header stickyHeader stickyHeaderOffset="top-0" />
958
+ <DataTable.Body rowClassName="mb-1" />
959
+ <DataTable.InfiniteFooter
960
+ hasNextPage={hasNext}
961
+ isFetchingNextPage={isFetching}
962
+ onLoadMore={loadMore}
963
+ skeletonRows={2}
964
+ />
965
+ </DataTable>
966
+ </div>
967
+ </div>
968
+ );
969
+ },
970
+ };
971
+
972
+ /**
973
+ * **A page that adds nothing** — the request failed, or the server answered an
974
+ * empty page that still claims a next one. The footer used to re-arm with the
975
+ * sentinel still in view and send the same request again, forever. It now parks
976
+ * the auto-trigger and offers **Load more**; a fetch that makes progress
977
+ * re-arms it.
978
+ *
979
+ * Here the second page fails once: scroll down, press Load more, keep scrolling.
980
+ */
981
+ export const InfiniteScrollStalledPage: Story = {
982
+ render: () => {
983
+ const [rows, setRows] = useState<Device[]>(() => makeDevices(20));
984
+ const [isFetching, setIsFetching] = useState(false);
985
+ const attemptsRef = useRef(0);
986
+
987
+ const columns = useMemo<ColumnDef<Device>[]>(
988
+ () => [
989
+ { accessorKey: 'hostname', header: 'Hostname', meta: { width: 'w-[200px]' } },
990
+ { accessorKey: 'ipAddress', header: 'IP', meta: { width: 'flex-1 min-w-0' } },
991
+ ],
992
+ [],
993
+ );
994
+
995
+ const table = useDataTable<Device>({ data: rows, columns });
996
+
997
+ const loadMore = useCallback(() => {
998
+ if (isFetching) return;
999
+ setIsFetching(true);
1000
+ window.setTimeout(() => {
1001
+ attemptsRef.current += 1;
1002
+ // The first attempt comes back with nothing.
1003
+ if (attemptsRef.current > 1) setRows(prev => [...prev, ...makeDevices(20, prev.length + 1)]);
1004
+ setIsFetching(false);
1005
+ }, 700);
1006
+ }, [isFetching]);
1007
+
1008
+ return (
1009
+ <div data-testid="scroller" className="h-[640px] overflow-y-auto rounded-md border border-ods-border">
1010
+ <div className="p-[var(--spacing-system-mf)]">
1011
+ <DataTable table={table}>
1012
+ <DataTable.Header stickyHeader stickyHeaderOffset="top-0" />
1013
+ <DataTable.Body rowClassName="mb-1" />
1014
+ <DataTable.InfiniteFooter
1015
+ hasNextPage={rows.length < 100}
1016
+ isFetchingNextPage={isFetching}
1017
+ onLoadMore={loadMore}
1018
+ skeletonRows={2}
1019
+ />
1020
+ </DataTable>
1021
+ </div>
1022
+ </div>
1023
+ );
1024
+ },
1025
+ };
1026
+
906
1027
  /**
907
1028
  * **Cursor pagination** — use `<DataTable.CursorFooter>` for a prev/next
908
1029
  * footer with "Showing X of Y" summary. Pair with Relay's `usePaginationFragment`
@@ -1107,6 +1228,52 @@ export const SimulatedInitialLoad: Story = {
1107
1228
  },
1108
1229
  };
1109
1230
 
1231
+ /**
1232
+ * **Skeleton parity** — every skeleton row occupies the slot of the row it
1233
+ * stands in for, so nothing moves when data arrives.
1234
+ *
1235
+ * Left: the loading state. Right: the same table loaded, with the infinite
1236
+ * footer frozen mid-fetch. Both pass `rowClassName="mb-1"` — where tables put
1237
+ * their row spacing — and the string form reaches the skeleton rows too. The
1238
+ * load-more rows are drawn by the BODY, inside the rows' own container, so they
1239
+ * continue the list at the same pitch instead of stacking glued together under
1240
+ * it. Row N on the left lines up with row N on the right.
1241
+ */
1242
+ export const SkeletonParity: Story = {
1243
+ render: () => {
1244
+ // Few enough columns that two tables fit side by side without scrolling.
1245
+ const columns = useMemo<ColumnDef<Device>[]>(
1246
+ () => [
1247
+ { accessorKey: 'hostname', header: 'Hostname', meta: { width: 'flex-1 min-w-0' } },
1248
+ { accessorKey: 'ipAddress', header: 'IP', meta: { width: 'w-[120px] shrink-0', hideAt: 'md' } },
1249
+ {
1250
+ accessorKey: 'status',
1251
+ header: 'Status',
1252
+ cell: ({ row }) => <StatusTag status={row.original.status} />,
1253
+ meta: { width: 'w-[120px] shrink-0' },
1254
+ },
1255
+ ],
1256
+ [],
1257
+ );
1258
+ const loadingTable = useDataTable<Device>({ data: NO_DEVICES, columns });
1259
+ const loadedTable = useDataTable<Device>({ data: DEVICES_6, columns });
1260
+
1261
+ return (
1262
+ <div className="grid grid-cols-2 gap-[var(--spacing-system-lf)] [&>*]:min-w-0">
1263
+ <DataTable table={loadingTable}>
1264
+ <DataTable.Header />
1265
+ <DataTable.Body loading skeletonRows={8} rowClassName="mb-1" />
1266
+ </DataTable>
1267
+ <DataTable table={loadedTable}>
1268
+ <DataTable.Header />
1269
+ <DataTable.Body rowClassName="mb-1" />
1270
+ <DataTable.InfiniteFooter hasNextPage isFetchingNextPage onLoadMore={noopLoadMore} skeletonRows={2} />
1271
+ </DataTable>
1272
+ </div>
1273
+ );
1274
+ },
1275
+ };
1276
+
1110
1277
  /**
1111
1278
  * **Row count** — `<DataTable.RowCount itemName="device" />` reads the row
1112
1279
  * count from the table context and renders `"Showing N devices"`. Two common