@dloizides/ui-tables 1.15.0 → 1.18.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.
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { memo, useState, useMemo, useCallback, useEffect, useRef, useLayoutEffect } from 'react';
1
+ import React2, { memo, useState, useMemo, useCallback, useEffect, useRef, useLayoutEffect } from 'react';
2
2
  import { StyleSheet, View, Text, Platform, useWindowDimensions, Pressable, Switch, TextInput } from 'react-native';
3
3
  import { useUi } from '@dloizides/ui-feedback';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
+ import { useReducedMotion, FadeIn } from '@dloizides/ui-motion';
5
6
  import { createPortal } from 'react-dom';
6
7
  import { Field, controlStyles, DateRangeControl, TypeaheadControl, DEFAULT_TYPEAHEAD_MIN_CHARS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, SelectControl } from '@dloizides/ui-forms';
7
8
  export { DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, isUnmatched, suggestOptions } from '@dloizides/ui-forms';
@@ -9,8 +10,11 @@ export { DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, isUnmat
9
10
  // src/StatCard/StatCard.tsx
10
11
 
11
12
  // src/DataTable/constants.ts
12
- var CARD_STACK_BREAKPOINT = 640;
13
+ var CARD_STACK_BREAKPOINT = 768;
13
14
  var DEFAULT_PAGE_SIZE_OPTIONS = [25, 50, 100, 200];
15
+ var ROW_ENTRANCE_STAGGER_CAP = 10;
16
+ var ROW_ENTRANCE_STAGGER_STEP_MS = 30;
17
+ var rowEntranceDelayMs = (index) => Math.min(index, ROW_ENTRANCE_STAGGER_CAP) * ROW_ENTRANCE_STAGGER_STEP_MS;
14
18
  var TABLE_TEST_IDS = {
15
19
  root: "ui-data-table",
16
20
  head: "ui-data-table-head",
@@ -20,6 +24,8 @@ var TABLE_TEST_IDS = {
20
24
  rowDetailInfix: "row-detail",
21
25
  /** Infix of a row's select checkbox: `${tableTestID}-select-${key}`. */
22
26
  rowSelectInfix: "select",
27
+ /** Infix of a row's entrance-fade wrapper: `${tableTestID}-fade-${key}`. */
28
+ rowFadeInfix: "fade",
23
29
  /** Suffix of the header (select-all-on-page) checkbox: `${tableTestID}-select-all`. */
24
30
  selectAllSuffix: "select-all",
25
31
  /** Suffix of the select-all-matching banner: `${tableTestID}-select-banner`. */
@@ -39,6 +45,7 @@ var rowTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowInfix}
39
45
  var rowDetailTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowDetailInfix}-${key}`;
40
46
  var rowSelectTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowSelectInfix}-${key}`;
41
47
  var selectAllTestID = (tableTestID) => `${tableTestID}-${TABLE_TEST_IDS.selectAllSuffix}`;
48
+ var rowFadeTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowFadeInfix}-${key}`;
42
49
  var TABLE_I18N = {
43
50
  loading: "uiTables.loading",
44
51
  empty: "uiTables.empty",
@@ -149,8 +156,8 @@ var STATE_PAD_V = 34;
149
156
  var HEAD_FONT = 12;
150
157
  var CELL_FONT = 14;
151
158
  var STATE_FONT = 14;
152
- var CARD_LINE_PAD_V = 3;
153
- var CARD_LINE_GAP = 12;
159
+ var CARD_LINE_PAD_V = 5;
160
+ var CARD_LABEL_GAP = 3;
154
161
  var PILL_RADIUS = 999;
155
162
  var PAGER_GAP = 8;
156
163
  var PAGER_SIZE_GAP = 6;
@@ -204,9 +211,22 @@ var tableStyles = StyleSheet.create({
204
211
  /** Full-width panel under an expanded row — spans every column (the wrap is a column flexbox). */
205
212
  rowDetail: { width: FULL_WIDTH, paddingHorizontal: ROW_PAD_H, paddingVertical: ROW_PAD_V, borderTopWidth: BORDER_WIDTH },
206
213
  card: { paddingHorizontal: ROW_PAD_H, paddingVertical: ROW_PAD_V, borderTopWidth: BORDER_WIDTH },
207
- cardLine: { flexDirection: "row", justifyContent: "space-between", alignItems: "baseline", paddingVertical: CARD_LINE_PAD_V, gap: CARD_LINE_GAP },
214
+ /**
215
+ * A card line is a VERTICAL label:value pair — the header sits ABOVE its value, both
216
+ * left-aligned, so a narrow phone column never cramps the value against the label the
217
+ * way the old `space-between` row did (an Actions cell of buttons or a long text value
218
+ * now gets the full card width). `paddingVertical` gives the stacked lines their rhythm.
219
+ */
220
+ cardLine: { flexDirection: "column", alignItems: "stretch", paddingVertical: CARD_LINE_PAD_V, gap: CARD_LABEL_GAP },
208
221
  cardLabel: { fontSize: HEAD_FONT, fontWeight: "600", textTransform: "uppercase", letterSpacing: LABEL_LETTER_SPACING },
209
- cardValue: { flexShrink: 1, alignItems: "flex-end" }
222
+ cardValue: { alignItems: "flex-start" },
223
+ /**
224
+ * A zero-footprint carrier for the `ui-data-table-head` test id in the card-stack layout
225
+ * (which has no visible header row). `display: 'none'` keeps it out of layout AND the
226
+ * accessibility tree, while the `data-testid` stays queryable — so an E2E selector that
227
+ * targets the head survives at every viewport width.
228
+ */
229
+ headSentinel: { display: "none" }
210
230
  });
211
231
  var selectionStyles = StyleSheet.create({
212
232
  /** The fixed-width gutter holding the checkbox, in both the header and every row. */
@@ -313,10 +333,15 @@ function RowCells({
313
333
  styleOverrides: o
314
334
  }) {
315
335
  if (stacked) {
316
- return /* @__PURE__ */ jsx(Fragment, { children: columns.map((col) => /* @__PURE__ */ jsxs(View, { style: [tableStyles.cardLine, o?.cardLine], children: [
317
- /* @__PURE__ */ jsx(Text, { style: [tableStyles.cardLabel, { color: labelColor }, o?.cardLabel], children: col.header }),
318
- /* @__PURE__ */ jsx(View, { style: [tableStyles.cardValue, o?.cardValue], children: cellContent(col, row, textColor, o) })
319
- ] }, col.key)) });
336
+ return /* @__PURE__ */ jsx(Fragment, { children: columns.map((col) => (
337
+ // The SAME per-cell test id the desktop cell carries (`${rowTestID}-${col.key}`),
338
+ // so an E2E selector like `${rowTestID}-${col.key}` resolves in BOTH layouts — the
339
+ // card-stack must not silently drop the hooks a wide-viewport test relies on.
340
+ /* @__PURE__ */ jsxs(View, { style: [tableStyles.cardLine, o?.cardLine], testID: `${rowTestID2}-${col.key}`, children: [
341
+ /* @__PURE__ */ jsx(Text, { style: [tableStyles.cardLabel, { color: labelColor }, o?.cardLabel], children: col.header }),
342
+ /* @__PURE__ */ jsx(View, { style: [tableStyles.cardValue, o?.cardValue], children: cellContent(col, row, textColor, o) })
343
+ ] }, col.key)
344
+ )) });
320
345
  }
321
346
  return /* @__PURE__ */ jsx(Fragment, { children: columns.map((col) => /* @__PURE__ */ jsx(
322
347
  DesktopCell,
@@ -817,10 +842,13 @@ function DataTable(props) {
817
842
  allMatchingSelected,
818
843
  onSelectAllMatchingChange,
819
844
  keyboardNavigation = false,
845
+ animateRows = true,
820
846
  stackBreakpoint = CARD_STACK_BREAKPOINT,
821
847
  testID = TABLE_TEST_IDS.root
822
848
  } = props;
823
849
  const { theme, t } = useUi();
850
+ const reducedMotion = useReducedMotion();
851
+ const animateRowEntrance = animateRows && !reducedMotion;
824
852
  const { colors } = theme;
825
853
  const { width } = useWindowDimensions();
826
854
  const stacked = width < stackBreakpoint;
@@ -863,28 +891,31 @@ function DataTable(props) {
863
891
  if (rows.length === 0) {
864
892
  return stateView(loading ? loadingLabel ?? t(TABLE_I18N.loading) : emptyLabel ?? t(TABLE_I18N.empty));
865
893
  }
866
- const renderRow = (row, key, style) => /* @__PURE__ */ jsx(
867
- DataTableRow,
868
- {
869
- columns,
870
- expanded: expandedRowKeys?.includes(key) ?? false,
871
- getRowAccessibilityLabel,
872
- keyboardNavigation,
873
- renderRowDetail,
874
- roving,
875
- row,
876
- rowKey: key,
877
- selection,
878
- stacked,
879
- style,
880
- styleOverrides: o,
881
- tableTestID: testID,
882
- onHoverIn: () => setHoveredKey(key),
883
- onHoverOut: () => setHoveredKey((current) => current === key ? void 0 : current),
884
- onRowPress
885
- },
886
- key
887
- );
894
+ const renderRow = (row, key, index, style) => {
895
+ const node = /* @__PURE__ */ jsx(
896
+ DataTableRow,
897
+ {
898
+ columns,
899
+ expanded: expandedRowKeys?.includes(key) ?? false,
900
+ getRowAccessibilityLabel,
901
+ keyboardNavigation,
902
+ renderRowDetail,
903
+ roving,
904
+ row,
905
+ rowKey: key,
906
+ selection,
907
+ stacked,
908
+ style,
909
+ styleOverrides: o,
910
+ tableTestID: testID,
911
+ onHoverIn: () => setHoveredKey(key),
912
+ onHoverOut: () => setHoveredKey((current) => current === key ? void 0 : current),
913
+ onRowPress
914
+ }
915
+ );
916
+ if (!animateRowEntrance) return /* @__PURE__ */ jsx(React2.Fragment, { children: node }, key);
917
+ return /* @__PURE__ */ jsx(FadeIn, { delay: rowEntranceDelayMs(index), testID: rowFadeTestID(testID, key), children: node }, key);
918
+ };
888
919
  const banner = /* @__PURE__ */ jsx(
889
920
  SelectAllBanner,
890
921
  {
@@ -900,10 +931,11 @@ function DataTable(props) {
900
931
  if (stacked) {
901
932
  return /* @__PURE__ */ jsxs(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, "aria-busy": loading, children: [
902
933
  banner,
934
+ /* @__PURE__ */ jsx(View, { style: tableStyles.headSentinel, testID: TABLE_TEST_IDS.head, "aria-hidden": true }),
903
935
  rows.map((row, i) => {
904
936
  const key = rowKeys[i] ?? keyExtractor(row);
905
937
  const bg = rowBg(row, i, key);
906
- return renderRow(row, key, [
938
+ return renderRow(row, key, i, [
907
939
  tableStyles.card,
908
940
  { borderTopColor: colors.border },
909
941
  i === FIRST_ROW_INDEX ? { borderTopWidth: 0 } : null,
@@ -937,7 +969,7 @@ function DataTable(props) {
937
969
  rows.map((row, i) => {
938
970
  const key = rowKeys[i] ?? keyExtractor(row);
939
971
  const bg = rowBg(row, i, key);
940
- return renderRow(row, key, [tableStyles.row, { borderTopColor: colors.border }, bg ? { backgroundColor: bg } : null, o?.row]);
972
+ return renderRow(row, key, i, [tableStyles.row, { borderTopColor: colors.border }, bg ? { backgroundColor: bg } : null, o?.row]);
941
973
  })
942
974
  ]
943
975
  }
@@ -1766,6 +1798,6 @@ function usePagedRows(rows, options = {}) {
1766
1798
  };
1767
1799
  }
1768
1800
 
1769
- export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, fieldTestID, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, useFilterDraft, usePagedRows };
1801
+ export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, fieldTestID, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, useFilterDraft, usePagedRows };
1770
1802
  //# sourceMappingURL=index.mjs.map
1771
1803
  //# sourceMappingURL=index.mjs.map