@dloizides/ui-tables 1.9.2 → 1.10.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/CHANGELOG.md +45 -0
- package/README.md +70 -0
- package/dist/index.d.mts +108 -7
- package/dist/index.d.ts +108 -7
- package/dist/index.js +722 -154
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +709 -139
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { memo, useState, useMemo, useCallback, useRef, useLayoutEffect, useEffect } from 'react';
|
|
2
2
|
import { StyleSheet, View, Text, Platform, useWindowDimensions, Pressable } from 'react-native';
|
|
3
3
|
import { useUi } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
@@ -47,6 +47,70 @@ var StatCard = memo(({ label, value, testID }) => {
|
|
|
47
47
|
);
|
|
48
48
|
});
|
|
49
49
|
StatCard.displayName = "StatCard";
|
|
50
|
+
|
|
51
|
+
// src/DataTable/constants.ts
|
|
52
|
+
var CARD_STACK_BREAKPOINT = 640;
|
|
53
|
+
var DEFAULT_PAGE_SIZE_OPTIONS = [25, 50, 100, 200];
|
|
54
|
+
var TABLE_TEST_IDS = {
|
|
55
|
+
root: "ui-data-table",
|
|
56
|
+
head: "ui-data-table-head",
|
|
57
|
+
/** Infix of a row's test id: `${tableTestID}-row-${key}`. */
|
|
58
|
+
rowInfix: "row",
|
|
59
|
+
/** Infix of an expanded row's detail panel: `${tableTestID}-row-detail-${key}`. */
|
|
60
|
+
rowDetailInfix: "row-detail",
|
|
61
|
+
/** Infix of a row's select checkbox: `${tableTestID}-select-${key}`. */
|
|
62
|
+
rowSelectInfix: "select",
|
|
63
|
+
/** Suffix of the header (select-all-on-page) checkbox: `${tableTestID}-select-all`. */
|
|
64
|
+
selectAllSuffix: "select-all",
|
|
65
|
+
/** Suffix of the select-all-matching banner: `${tableTestID}-select-banner`. */
|
|
66
|
+
selectBannerSuffix: "select-banner",
|
|
67
|
+
/** Suffix of the banner's action: `${tableTestID}-select-banner-action`. */
|
|
68
|
+
selectBannerActionSuffix: "select-banner-action",
|
|
69
|
+
filterBar: "ui-filters",
|
|
70
|
+
results: "ui-results",
|
|
71
|
+
pager: "ui-pager",
|
|
72
|
+
pagerInfo: "ui-pager-info",
|
|
73
|
+
pagerPrev: "ui-pager-prev",
|
|
74
|
+
pagerNext: "ui-pager-next"
|
|
75
|
+
};
|
|
76
|
+
var rowTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowInfix}-${key}`;
|
|
77
|
+
var rowDetailTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowDetailInfix}-${key}`;
|
|
78
|
+
var rowSelectTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowSelectInfix}-${key}`;
|
|
79
|
+
var selectAllTestID = (tableTestID) => `${tableTestID}-${TABLE_TEST_IDS.selectAllSuffix}`;
|
|
80
|
+
var TABLE_I18N = {
|
|
81
|
+
loading: "uiTables.loading",
|
|
82
|
+
empty: "uiTables.empty",
|
|
83
|
+
rowLabel: "uiTables.rowLabel",
|
|
84
|
+
rowHint: "uiTables.rowHint",
|
|
85
|
+
/** Accessible name of the full-width detail panel under an expanded row. */
|
|
86
|
+
rowDetail: "uiTables.rowDetail",
|
|
87
|
+
/** Accessible name of a row's select checkbox. */
|
|
88
|
+
selectRow: "uiTables.select.row",
|
|
89
|
+
selectRowHint: "uiTables.select.rowHint",
|
|
90
|
+
/** Accessible name of the header (select-all-on-page) checkbox. */
|
|
91
|
+
selectAll: "uiTables.select.all",
|
|
92
|
+
selectAllHint: "uiTables.select.allHint",
|
|
93
|
+
/** Banner, offer state: "All {{p1}} rows on this page are selected." */
|
|
94
|
+
selectPageSelected: "uiTables.select.pageSelected",
|
|
95
|
+
/** Banner, offer action: "Select all {{p1}} matching this filter". */
|
|
96
|
+
selectAllMatching: "uiTables.select.allMatching",
|
|
97
|
+
selectAllMatchingHint: "uiTables.select.allMatchingHint",
|
|
98
|
+
/** Banner, active state: "All {{p1}} rows matching this filter are selected." */
|
|
99
|
+
selectMatchingSelected: "uiTables.select.matchingSelected",
|
|
100
|
+
/** Banner, active action: "Clear selection". */
|
|
101
|
+
selectClear: "uiTables.select.clear",
|
|
102
|
+
selectClearHint: "uiTables.select.clearHint",
|
|
103
|
+
results: "uiTables.results",
|
|
104
|
+
pagerInfo: "uiTables.pager.info",
|
|
105
|
+
pagerPrev: "uiTables.pager.prev",
|
|
106
|
+
pagerNext: "uiTables.pager.next",
|
|
107
|
+
pagerPrevHint: "uiTables.pager.prevHint",
|
|
108
|
+
pagerNextHint: "uiTables.pager.nextHint",
|
|
109
|
+
pagerRows: "uiTables.pager.rows",
|
|
110
|
+
pagerRowsOptionHint: "uiTables.pager.rowsOptionHint",
|
|
111
|
+
/** Accessible hint for the dropdown-variant rows-per-page trigger button. */
|
|
112
|
+
pagerRowsTriggerHint: "uiTables.pager.rowsTriggerHint"
|
|
113
|
+
};
|
|
50
114
|
var BORDER_WIDTH = 1;
|
|
51
115
|
var BORDER_RADIUS = 12;
|
|
52
116
|
var COLUMN_GAP = 16;
|
|
@@ -78,6 +142,14 @@ var HEAD_LETTER_SPACING = 0.4;
|
|
|
78
142
|
var LABEL_LETTER_SPACING = 0.3;
|
|
79
143
|
var STICKY_Z = 2;
|
|
80
144
|
var FULL_WIDTH = "100%";
|
|
145
|
+
var SELECT_COL_WIDTH = 20;
|
|
146
|
+
var CHECKBOX_SIZE = 18;
|
|
147
|
+
var CHECKBOX_RADIUS = 4;
|
|
148
|
+
var CHECKBOX_GLYPH_FONT = 11;
|
|
149
|
+
var CHECKBOX_GLYPH_LINE = 13;
|
|
150
|
+
var BANNER_PAD_V = 8;
|
|
151
|
+
var BANNER_FONT = 13;
|
|
152
|
+
var BANNER_GAP = 6;
|
|
81
153
|
var STICKY_WEB_STYLE = {
|
|
82
154
|
position: "sticky",
|
|
83
155
|
top: 0,
|
|
@@ -108,6 +180,40 @@ var tableStyles = StyleSheet.create({
|
|
|
108
180
|
cardLabel: { fontSize: HEAD_FONT, fontWeight: "600", textTransform: "uppercase", letterSpacing: LABEL_LETTER_SPACING },
|
|
109
181
|
cardValue: { flexShrink: 1, alignItems: "flex-end" }
|
|
110
182
|
});
|
|
183
|
+
var selectionStyles = StyleSheet.create({
|
|
184
|
+
/** The fixed-width gutter holding the checkbox, in both the header and every row. */
|
|
185
|
+
selectCell: { width: SELECT_COL_WIDTH, alignItems: "flex-start", justifyContent: "center" },
|
|
186
|
+
/** The checkbox's pressable area (the hit target is grown further with `hitSlop`). */
|
|
187
|
+
checkboxHit: { alignItems: "center", justifyContent: "center" },
|
|
188
|
+
checkbox: {
|
|
189
|
+
width: CHECKBOX_SIZE,
|
|
190
|
+
height: CHECKBOX_SIZE,
|
|
191
|
+
borderRadius: CHECKBOX_RADIUS,
|
|
192
|
+
borderWidth: BORDER_WIDTH,
|
|
193
|
+
alignItems: "center",
|
|
194
|
+
justifyContent: "center"
|
|
195
|
+
},
|
|
196
|
+
checkboxGlyph: { fontSize: CHECKBOX_GLYPH_FONT, lineHeight: CHECKBOX_GLYPH_LINE, fontWeight: "700" },
|
|
197
|
+
/**
|
|
198
|
+
* The cells of a SELECTABLE row, wrapped so the checkbox can sit OUTSIDE the pressable
|
|
199
|
+
* area. `flex: 1` so the cells still claim the row minus the checkbox gutter.
|
|
200
|
+
*/
|
|
201
|
+
rowContent: { flex: 1, flexDirection: "row", columnGap: COLUMN_GAP, alignItems: "center" },
|
|
202
|
+
/** The same, for the card-stack: a card's lines are a column, not a row. */
|
|
203
|
+
cardContent: { flex: 1 },
|
|
204
|
+
/** The select-all-matching banner, spanning the table above the header. */
|
|
205
|
+
banner: {
|
|
206
|
+
flexDirection: "row",
|
|
207
|
+
flexWrap: "wrap",
|
|
208
|
+
alignItems: "center",
|
|
209
|
+
justifyContent: "center",
|
|
210
|
+
gap: BANNER_GAP,
|
|
211
|
+
paddingHorizontal: ROW_PAD_H,
|
|
212
|
+
paddingVertical: BANNER_PAD_V
|
|
213
|
+
},
|
|
214
|
+
bannerText: { fontSize: BANNER_FONT },
|
|
215
|
+
bannerAction: { fontSize: BANNER_FONT, fontWeight: "700", textDecorationLine: "underline" }
|
|
216
|
+
});
|
|
111
217
|
var chromeStyles = StyleSheet.create({
|
|
112
218
|
filters: { flexDirection: "row", flexWrap: "wrap", alignItems: "flex-end", columnGap: COLUMN_GAP, rowGap: PAGER_GAP, borderWidth: BORDER_WIDTH, borderRadius: BORDER_RADIUS, paddingHorizontal: ROW_PAD_H, paddingVertical: ROW_PAD_V },
|
|
113
219
|
filtersSpacer: { flexGrow: 1 },
|
|
@@ -154,7 +260,7 @@ function cellContent(column, row, textColor, overrides) {
|
|
|
154
260
|
}
|
|
155
261
|
return content;
|
|
156
262
|
}
|
|
157
|
-
function DesktopCell({ column, row, textColor, testID, styleOverrides }) {
|
|
263
|
+
function DesktopCell({ column, row, textColor, testID, styleOverrides, inGrid }) {
|
|
158
264
|
return /* @__PURE__ */ jsx(
|
|
159
265
|
View,
|
|
160
266
|
{
|
|
@@ -163,49 +269,504 @@ function DesktopCell({ column, row, textColor, testID, styleOverrides }) {
|
|
|
163
269
|
styleOverrides?.cellWrap
|
|
164
270
|
],
|
|
165
271
|
testID,
|
|
272
|
+
...inGrid === true ? { role: "cell" } : null,
|
|
166
273
|
children: cellContent(column, row, textColor, styleOverrides)
|
|
167
274
|
}
|
|
168
275
|
);
|
|
169
276
|
}
|
|
277
|
+
function RowCells({
|
|
278
|
+
columns,
|
|
279
|
+
row,
|
|
280
|
+
stacked,
|
|
281
|
+
inGrid,
|
|
282
|
+
rowTestID: rowTestID2,
|
|
283
|
+
textColor,
|
|
284
|
+
labelColor,
|
|
285
|
+
styleOverrides: o
|
|
286
|
+
}) {
|
|
287
|
+
if (stacked) {
|
|
288
|
+
return /* @__PURE__ */ jsx(Fragment, { children: columns.map((col) => /* @__PURE__ */ jsxs(View, { style: [tableStyles.cardLine, o?.cardLine], children: [
|
|
289
|
+
/* @__PURE__ */ jsx(Text, { style: [tableStyles.cardLabel, { color: labelColor }, o?.cardLabel], children: col.header }),
|
|
290
|
+
/* @__PURE__ */ jsx(View, { style: [tableStyles.cardValue, o?.cardValue], children: cellContent(col, row, textColor, o) })
|
|
291
|
+
] }, col.key)) });
|
|
292
|
+
}
|
|
293
|
+
return /* @__PURE__ */ jsx(Fragment, { children: columns.map((col) => /* @__PURE__ */ jsx(
|
|
294
|
+
DesktopCell,
|
|
295
|
+
{
|
|
296
|
+
column: col,
|
|
297
|
+
inGrid,
|
|
298
|
+
row,
|
|
299
|
+
styleOverrides: o,
|
|
300
|
+
testID: `${rowTestID2}-${col.key}`,
|
|
301
|
+
textColor
|
|
302
|
+
},
|
|
303
|
+
col.key
|
|
304
|
+
)) });
|
|
305
|
+
}
|
|
306
|
+
var CHECK_GLYPH = "\u2713";
|
|
307
|
+
var MIXED_GLYPH = "\u2013";
|
|
308
|
+
var CHECKBOX_HIT_SLOP = { top: 12, bottom: 12, left: 12, right: 12 };
|
|
309
|
+
var TRANSPARENT = "transparent";
|
|
310
|
+
function toCheckedValue(state) {
|
|
311
|
+
if (state === "all" /* All */) return true;
|
|
312
|
+
return state === "some" /* Some */ ? "mixed" : false;
|
|
313
|
+
}
|
|
314
|
+
function toGlyph(state) {
|
|
315
|
+
if (state === "all" /* All */) return CHECK_GLYPH;
|
|
316
|
+
return state === "some" /* Some */ ? MIXED_GLYPH : void 0;
|
|
317
|
+
}
|
|
318
|
+
function SelectionCheckbox({
|
|
319
|
+
state,
|
|
320
|
+
label,
|
|
321
|
+
hint,
|
|
322
|
+
onToggle,
|
|
323
|
+
brandColor,
|
|
324
|
+
borderColor,
|
|
325
|
+
surfaceColor,
|
|
326
|
+
testID
|
|
327
|
+
}) {
|
|
328
|
+
const checked = toCheckedValue(state);
|
|
329
|
+
const glyph = toGlyph(state);
|
|
330
|
+
const filled = state !== "none" /* None */;
|
|
331
|
+
return /* @__PURE__ */ jsx(
|
|
332
|
+
Pressable,
|
|
333
|
+
{
|
|
334
|
+
accessibilityHint: hint,
|
|
335
|
+
accessibilityLabel: label,
|
|
336
|
+
accessibilityRole: "checkbox",
|
|
337
|
+
accessibilityState: { checked },
|
|
338
|
+
"aria-checked": checked,
|
|
339
|
+
hitSlop: CHECKBOX_HIT_SLOP,
|
|
340
|
+
style: selectionStyles.checkboxHit,
|
|
341
|
+
testID,
|
|
342
|
+
onPress: onToggle,
|
|
343
|
+
children: /* @__PURE__ */ jsx(
|
|
344
|
+
View,
|
|
345
|
+
{
|
|
346
|
+
style: [
|
|
347
|
+
selectionStyles.checkbox,
|
|
348
|
+
{ borderColor: filled ? brandColor : borderColor, backgroundColor: filled ? brandColor : TRANSPARENT }
|
|
349
|
+
],
|
|
350
|
+
children: glyph === void 0 ? null : /* @__PURE__ */ jsx(Text, { style: [selectionStyles.checkboxGlyph, { color: surfaceColor }], children: glyph })
|
|
351
|
+
}
|
|
352
|
+
)
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
var TAB_INDEX_INACTIVE = -1;
|
|
357
|
+
function webKeyProps(onKeyDown) {
|
|
358
|
+
return onKeyDown === void 0 ? {} : { onKeyDown };
|
|
359
|
+
}
|
|
360
|
+
function focusProps(keyboard) {
|
|
361
|
+
if (keyboard === void 0) return {};
|
|
362
|
+
return {
|
|
363
|
+
tabIndex: keyboard.tabIndex,
|
|
364
|
+
onFocus: keyboard.onFocus,
|
|
365
|
+
ref: (node) => keyboard.registerNode(node),
|
|
366
|
+
...webKeyProps(keyboard.onKeyDown)
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function TableRow({
|
|
370
|
+
testID,
|
|
371
|
+
style,
|
|
372
|
+
children,
|
|
373
|
+
a11y,
|
|
374
|
+
onPress,
|
|
375
|
+
onHoverIn,
|
|
376
|
+
onHoverOut,
|
|
377
|
+
selectionSlot,
|
|
378
|
+
stacked,
|
|
379
|
+
keyboard
|
|
380
|
+
}) {
|
|
381
|
+
const interactive = onPress !== void 0;
|
|
382
|
+
const hover = interactive ? { onHoverIn, onHoverOut } : null;
|
|
383
|
+
if (selectionSlot === void 0) {
|
|
384
|
+
return interactive ? /* @__PURE__ */ jsx(Pressable, { style, testID, onPress, ...hover, ...a11y, ...focusProps(keyboard), children }) : /* @__PURE__ */ jsx(View, { style, testID, ...a11y, ...focusProps(keyboard), children });
|
|
385
|
+
}
|
|
386
|
+
const contentStyle = stacked ? selectionStyles.cardContent : selectionStyles.rowContent;
|
|
387
|
+
const content = interactive ? /* @__PURE__ */ jsx(
|
|
388
|
+
Pressable,
|
|
389
|
+
{
|
|
390
|
+
style: contentStyle,
|
|
391
|
+
tabIndex: keyboard === void 0 ? void 0 : TAB_INDEX_INACTIVE,
|
|
392
|
+
onPress,
|
|
393
|
+
...hover,
|
|
394
|
+
children
|
|
395
|
+
}
|
|
396
|
+
) : /* @__PURE__ */ jsx(View, { style: contentStyle, children });
|
|
397
|
+
return /* @__PURE__ */ jsxs(View, { style, testID, ...a11y, ...focusProps(keyboard), children: [
|
|
398
|
+
/* @__PURE__ */ jsx(View, { style: selectionStyles.selectCell, children: selectionSlot }),
|
|
399
|
+
content
|
|
400
|
+
] });
|
|
401
|
+
}
|
|
402
|
+
function DataTableRow({
|
|
403
|
+
row,
|
|
404
|
+
rowKey,
|
|
405
|
+
style,
|
|
406
|
+
columns,
|
|
407
|
+
stacked,
|
|
408
|
+
tableTestID,
|
|
409
|
+
selection,
|
|
410
|
+
keyboardNavigation,
|
|
411
|
+
roving,
|
|
412
|
+
onRowPress,
|
|
413
|
+
getRowAccessibilityLabel,
|
|
414
|
+
renderRowDetail,
|
|
415
|
+
expanded,
|
|
416
|
+
onHoverIn,
|
|
417
|
+
onHoverOut,
|
|
418
|
+
styleOverrides: o
|
|
419
|
+
}) {
|
|
420
|
+
const { theme, t } = useUi();
|
|
421
|
+
const { colors } = theme;
|
|
422
|
+
const rowID = rowTestID(tableTestID, rowKey);
|
|
423
|
+
const isExpandable = renderRowDetail !== void 0;
|
|
424
|
+
const { selectable } = selection;
|
|
425
|
+
const isSelected = selectable && selection.isSelected(rowKey);
|
|
426
|
+
const a11y = {
|
|
427
|
+
accessibilityLabel: getRowAccessibilityLabel?.(row) ?? t(TABLE_I18N.rowLabel),
|
|
428
|
+
accessibilityHint: t(TABLE_I18N.rowHint),
|
|
429
|
+
accessibilityRole: onRowPress ? "button" : "text",
|
|
430
|
+
...isExpandable || selectable ? { accessibilityState: { ...isExpandable ? { expanded } : null, ...selectable ? { selected: isSelected } : null } } : null,
|
|
431
|
+
...isExpandable ? { "aria-expanded": expanded } : null,
|
|
432
|
+
...selectable ? { "aria-selected": isSelected } : null,
|
|
433
|
+
// A navigable table is a real grid, so its rows are grid rows — selectable or not.
|
|
434
|
+
// `role` wins over `accessibilityRole` on RNW.
|
|
435
|
+
...keyboardNavigation ? { role: "row" } : null
|
|
436
|
+
};
|
|
437
|
+
const rowNode = /* @__PURE__ */ jsx(
|
|
438
|
+
TableRow,
|
|
439
|
+
{
|
|
440
|
+
a11y,
|
|
441
|
+
keyboard: keyboardNavigation ? {
|
|
442
|
+
tabIndex: roving.tabIndexFor(rowKey),
|
|
443
|
+
onKeyDown: roving.keyDownFor(rowKey),
|
|
444
|
+
onFocus: () => roving.onRowFocus(rowKey),
|
|
445
|
+
registerNode: (node) => roving.registerRow(rowKey, node)
|
|
446
|
+
} : void 0,
|
|
447
|
+
selectionSlot: selectable ? /* @__PURE__ */ jsx(
|
|
448
|
+
SelectionCheckbox,
|
|
449
|
+
{
|
|
450
|
+
borderColor: colors.border,
|
|
451
|
+
brandColor: theme.palette.primary["500"],
|
|
452
|
+
hint: t(TABLE_I18N.selectRowHint),
|
|
453
|
+
label: getRowAccessibilityLabel?.(row) ?? t(TABLE_I18N.selectRow),
|
|
454
|
+
state: isSelected ? "all" /* All */ : "none" /* None */,
|
|
455
|
+
surfaceColor: colors.surface,
|
|
456
|
+
testID: rowSelectTestID(tableTestID, rowKey),
|
|
457
|
+
onToggle: () => selection.toggleRow(rowKey)
|
|
458
|
+
}
|
|
459
|
+
) : void 0,
|
|
460
|
+
stacked,
|
|
461
|
+
style,
|
|
462
|
+
testID: rowID,
|
|
463
|
+
onHoverIn,
|
|
464
|
+
onHoverOut,
|
|
465
|
+
onPress: onRowPress === void 0 ? void 0 : () => onRowPress(row),
|
|
466
|
+
children: /* @__PURE__ */ jsx(
|
|
467
|
+
RowCells,
|
|
468
|
+
{
|
|
469
|
+
columns,
|
|
470
|
+
inGrid: keyboardNavigation,
|
|
471
|
+
labelColor: colors.textSecondary,
|
|
472
|
+
row,
|
|
473
|
+
rowTestID: rowID,
|
|
474
|
+
stacked,
|
|
475
|
+
styleOverrides: o,
|
|
476
|
+
textColor: colors.text
|
|
477
|
+
}
|
|
478
|
+
)
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
if (!isExpandable || !expanded) return rowNode;
|
|
482
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
483
|
+
rowNode,
|
|
484
|
+
/* @__PURE__ */ jsx(
|
|
485
|
+
View,
|
|
486
|
+
{
|
|
487
|
+
accessibilityLabel: t(TABLE_I18N.rowDetail),
|
|
488
|
+
accessibilityRole: "summary",
|
|
489
|
+
style: [tableStyles.rowDetail, { borderTopColor: colors.border, backgroundColor: colors.background }, o?.rowDetail],
|
|
490
|
+
testID: rowDetailTestID(tableTestID, rowKey),
|
|
491
|
+
children: renderRowDetail(row)
|
|
492
|
+
}
|
|
493
|
+
)
|
|
494
|
+
] });
|
|
495
|
+
}
|
|
496
|
+
function SelectAllBanner({
|
|
497
|
+
mode,
|
|
498
|
+
pageCount,
|
|
499
|
+
matchingCount,
|
|
500
|
+
onAction,
|
|
501
|
+
testID,
|
|
502
|
+
actionTestID,
|
|
503
|
+
styleOverride
|
|
504
|
+
}) {
|
|
505
|
+
const { theme, t } = useUi();
|
|
506
|
+
const { colors, palette } = theme;
|
|
507
|
+
if (mode === "hidden" /* Hidden */) return null;
|
|
508
|
+
const active = mode === "active" /* Active */;
|
|
509
|
+
const message = active ? t(TABLE_I18N.selectMatchingSelected, matchingCount.toLocaleString()) : t(TABLE_I18N.selectPageSelected, pageCount.toLocaleString());
|
|
510
|
+
const actionLabel = active ? t(TABLE_I18N.selectClear) : t(TABLE_I18N.selectAllMatching, matchingCount.toLocaleString());
|
|
511
|
+
const actionHint = active ? t(TABLE_I18N.selectClearHint) : t(TABLE_I18N.selectAllMatchingHint);
|
|
512
|
+
return /* @__PURE__ */ jsxs(
|
|
513
|
+
View,
|
|
514
|
+
{
|
|
515
|
+
accessibilityLiveRegion: "polite",
|
|
516
|
+
style: [selectionStyles.banner, { backgroundColor: colors.background }, styleOverride],
|
|
517
|
+
testID,
|
|
518
|
+
children: [
|
|
519
|
+
/* @__PURE__ */ jsx(Text, { style: [selectionStyles.bannerText, { color: colors.textSecondary }], children: message }),
|
|
520
|
+
/* @__PURE__ */ jsx(
|
|
521
|
+
Pressable,
|
|
522
|
+
{
|
|
523
|
+
accessibilityHint: actionHint,
|
|
524
|
+
accessibilityLabel: actionLabel,
|
|
525
|
+
accessibilityRole: "button",
|
|
526
|
+
testID: actionTestID,
|
|
527
|
+
onPress: onAction,
|
|
528
|
+
children: /* @__PURE__ */ jsx(Text, { style: [selectionStyles.bannerAction, { color: palette.primary["500"] }], children: actionLabel })
|
|
529
|
+
}
|
|
530
|
+
)
|
|
531
|
+
]
|
|
532
|
+
}
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
function TableHeader({ columns, stickyHeader, selection, inGrid, styleOverrides: o }) {
|
|
536
|
+
const { theme, t } = useUi();
|
|
537
|
+
const { colors } = theme;
|
|
538
|
+
return /* @__PURE__ */ jsxs(
|
|
539
|
+
View,
|
|
540
|
+
{
|
|
541
|
+
style: [tableStyles.headRow, { backgroundColor: colors.background }, stickyHeader ? STICKY_HEADER_STYLE : null, o?.headRow],
|
|
542
|
+
testID: TABLE_TEST_IDS.head,
|
|
543
|
+
...inGrid ? { role: "row" } : null,
|
|
544
|
+
children: [
|
|
545
|
+
selection === void 0 ? null : /* @__PURE__ */ jsx(View, { style: [selectionStyles.selectCell, o?.selectCell], children: /* @__PURE__ */ jsx(
|
|
546
|
+
SelectionCheckbox,
|
|
547
|
+
{
|
|
548
|
+
borderColor: colors.border,
|
|
549
|
+
brandColor: theme.palette.primary["500"],
|
|
550
|
+
hint: t(TABLE_I18N.selectAllHint),
|
|
551
|
+
label: t(TABLE_I18N.selectAll),
|
|
552
|
+
state: selection.state,
|
|
553
|
+
surfaceColor: colors.surface,
|
|
554
|
+
testID: selection.testID,
|
|
555
|
+
onToggle: selection.onToggleAll
|
|
556
|
+
}
|
|
557
|
+
) }),
|
|
558
|
+
columns.map((col) => /* @__PURE__ */ jsx(
|
|
559
|
+
Text,
|
|
560
|
+
{
|
|
561
|
+
style: [tableStyles.headCell, { color: colors.textSecondary, flex: col.weight ?? 1, textAlign: col.numeric ? "right" : "left" }, o?.headCell],
|
|
562
|
+
...inGrid ? { role: "columnheader" } : null,
|
|
563
|
+
children: col.header
|
|
564
|
+
},
|
|
565
|
+
col.key
|
|
566
|
+
))
|
|
567
|
+
]
|
|
568
|
+
}
|
|
569
|
+
);
|
|
570
|
+
}
|
|
170
571
|
|
|
171
|
-
// src/DataTable/
|
|
172
|
-
var
|
|
173
|
-
var
|
|
174
|
-
var
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
572
|
+
// src/DataTable/rowNav.ts
|
|
573
|
+
var FIRST_INDEX = 0;
|
|
574
|
+
var ONE_ROW = 1;
|
|
575
|
+
var NOT_FOUND = -1;
|
|
576
|
+
function toRowNavAction(key) {
|
|
577
|
+
switch (key) {
|
|
578
|
+
case "ArrowDown":
|
|
579
|
+
return "next" /* Next */;
|
|
580
|
+
case "ArrowUp":
|
|
581
|
+
return "prev" /* Prev */;
|
|
582
|
+
case "Home":
|
|
583
|
+
return "first" /* First */;
|
|
584
|
+
case "End":
|
|
585
|
+
return "last" /* Last */;
|
|
586
|
+
case " ":
|
|
587
|
+
case "Spacebar":
|
|
588
|
+
return "toggle" /* Toggle */;
|
|
589
|
+
case "Enter":
|
|
590
|
+
return "activate" /* Activate */;
|
|
591
|
+
default:
|
|
592
|
+
return void 0;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function nextRowIndex(currentIndex, action, rowCount) {
|
|
596
|
+
if (rowCount === FIRST_INDEX) return void 0;
|
|
597
|
+
const lastIndex = rowCount - ONE_ROW;
|
|
598
|
+
switch (action) {
|
|
599
|
+
case "next" /* Next */:
|
|
600
|
+
return Math.min(currentIndex + ONE_ROW, lastIndex);
|
|
601
|
+
case "prev" /* Prev */:
|
|
602
|
+
return Math.max(currentIndex - ONE_ROW, FIRST_INDEX);
|
|
603
|
+
case "first" /* First */:
|
|
604
|
+
return FIRST_INDEX;
|
|
605
|
+
case "last" /* Last */:
|
|
606
|
+
return lastIndex;
|
|
607
|
+
default:
|
|
608
|
+
return void 0;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function resolveTabbableKey(rowKeys, focusedKey) {
|
|
612
|
+
if (rowKeys.length === FIRST_INDEX) return void 0;
|
|
613
|
+
if (focusedKey !== void 0 && rowKeys.includes(focusedKey)) return focusedKey;
|
|
614
|
+
return rowKeys[FIRST_INDEX];
|
|
615
|
+
}
|
|
616
|
+
function focusedRowIndex(rowKeys, focusedKey) {
|
|
617
|
+
const index = focusedKey === void 0 ? NOT_FOUND : rowKeys.indexOf(focusedKey);
|
|
618
|
+
return index === NOT_FOUND ? FIRST_INDEX : index;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// src/DataTable/useRovingFocus.ts
|
|
622
|
+
var TAB_INDEX_ACTIVE = 0;
|
|
623
|
+
var TAB_INDEX_INACTIVE2 = -1;
|
|
624
|
+
var IS_WEB = Platform.OS === "web";
|
|
625
|
+
function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
|
|
626
|
+
const [focusedKey, setFocusedKey] = useState(void 0);
|
|
627
|
+
const nodes = useRef(/* @__PURE__ */ new Map());
|
|
628
|
+
const tabbableKey = enabled ? resolveTabbableKey(rowKeys, focusedKey) : void 0;
|
|
629
|
+
const registerRow = useCallback((key, node) => {
|
|
630
|
+
if (node === null || node === void 0) {
|
|
631
|
+
nodes.current.delete(key);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
nodes.current.set(key, node);
|
|
635
|
+
}, []);
|
|
636
|
+
const focusRow = useCallback((key) => {
|
|
637
|
+
setFocusedKey(key);
|
|
638
|
+
nodes.current.get(key)?.focus?.();
|
|
639
|
+
}, []);
|
|
640
|
+
const handleKey = useCallback(
|
|
641
|
+
(event, key) => {
|
|
642
|
+
const action = toRowNavAction(event.key);
|
|
643
|
+
if (action === void 0) return;
|
|
644
|
+
if (action === "toggle" /* Toggle */) {
|
|
645
|
+
if (onToggleKey === void 0) return;
|
|
646
|
+
event.preventDefault();
|
|
647
|
+
onToggleKey(key);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
if (action === "activate" /* Activate */) {
|
|
651
|
+
if (onActivateKey === void 0) return;
|
|
652
|
+
event.preventDefault();
|
|
653
|
+
onActivateKey(key);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
const target = nextRowIndex(focusedRowIndex(rowKeys, key), action, rowKeys.length);
|
|
657
|
+
if (target === void 0) return;
|
|
658
|
+
const targetKey = rowKeys[target];
|
|
659
|
+
if (targetKey === void 0) return;
|
|
660
|
+
event.preventDefault();
|
|
661
|
+
focusRow(targetKey);
|
|
662
|
+
},
|
|
663
|
+
[rowKeys, onToggleKey, onActivateKey, focusRow]
|
|
664
|
+
);
|
|
665
|
+
const keyDownFor = useCallback(
|
|
666
|
+
(key) => {
|
|
667
|
+
if (!enabled || !IS_WEB) return void 0;
|
|
668
|
+
return (event) => handleKey(event, key);
|
|
669
|
+
},
|
|
670
|
+
[enabled, handleKey]
|
|
671
|
+
);
|
|
672
|
+
const tabIndexFor = useCallback(
|
|
673
|
+
(key) => key === tabbableKey ? TAB_INDEX_ACTIVE : TAB_INDEX_INACTIVE2,
|
|
674
|
+
[tabbableKey]
|
|
675
|
+
);
|
|
676
|
+
const onRowFocus = useCallback((key) => setFocusedKey(key), []);
|
|
677
|
+
return { tabIndexFor, registerRow, onRowFocus, keyDownFor };
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// src/DataTable/selection.ts
|
|
681
|
+
var NONE = 0;
|
|
682
|
+
function toggleSelectedKey(selectedKeys, key) {
|
|
683
|
+
return selectedKeys.includes(key) ? selectedKeys.filter((selected) => selected !== key) : [...selectedKeys, key];
|
|
684
|
+
}
|
|
685
|
+
function countSelectedOnPage(selectedKeys, pageKeys) {
|
|
686
|
+
return pageKeys.filter((key) => selectedKeys.includes(key)).length;
|
|
687
|
+
}
|
|
688
|
+
function resolveHeaderCheckboxState(selectedKeys, pageKeys) {
|
|
689
|
+
if (pageKeys.length === NONE) return "none" /* None */;
|
|
690
|
+
const selectedOnPage = countSelectedOnPage(selectedKeys, pageKeys);
|
|
691
|
+
if (selectedOnPage === NONE) return "none" /* None */;
|
|
692
|
+
return selectedOnPage === pageKeys.length ? "all" /* All */ : "some" /* Some */;
|
|
693
|
+
}
|
|
694
|
+
function toggleAllOnPage(selectedKeys, pageKeys) {
|
|
695
|
+
const state = resolveHeaderCheckboxState(selectedKeys, pageKeys);
|
|
696
|
+
if (state === "all" /* All */) return selectedKeys.filter((key) => !pageKeys.includes(key));
|
|
697
|
+
const merged = [...selectedKeys];
|
|
698
|
+
pageKeys.forEach((key) => {
|
|
699
|
+
if (!merged.includes(key)) merged.push(key);
|
|
700
|
+
});
|
|
701
|
+
return merged;
|
|
702
|
+
}
|
|
703
|
+
function resolveSelectAllBannerMode(headerState, allMatchingSelected, pageCount, matchingCount) {
|
|
704
|
+
if (allMatchingSelected) return "active" /* Active */;
|
|
705
|
+
const pageFullySelected = headerState === "all" /* All */ && pageCount > NONE;
|
|
706
|
+
const moreBeyondThisPage = matchingCount > pageCount;
|
|
707
|
+
return pageFullySelected && moreBeyondThisPage ? "offer" /* Offer */ : "hidden" /* Hidden */;
|
|
708
|
+
}
|
|
709
|
+
function isRowSelected(selectedKeys, key, allMatchingSelected) {
|
|
710
|
+
return allMatchingSelected || selectedKeys.includes(key);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// src/DataTable/useTableSelection.ts
|
|
714
|
+
var NO_KEYS = [];
|
|
715
|
+
var NO_MATCHES = 0;
|
|
716
|
+
function useTableSelection({
|
|
717
|
+
pageKeys,
|
|
718
|
+
selectedRowKeys,
|
|
719
|
+
onSelectionChange,
|
|
720
|
+
matchingCount,
|
|
721
|
+
allMatchingSelected,
|
|
722
|
+
onSelectAllMatchingChange
|
|
723
|
+
}) {
|
|
724
|
+
const selectable = onSelectionChange !== void 0;
|
|
725
|
+
const selected = selectedRowKeys ?? NO_KEYS;
|
|
726
|
+
const allMatching = allMatchingSelected ?? false;
|
|
727
|
+
const matching = matchingCount ?? NO_MATCHES;
|
|
728
|
+
const pageHeaderState = useMemo(
|
|
729
|
+
() => resolveHeaderCheckboxState(selected, pageKeys),
|
|
730
|
+
[selected, pageKeys]
|
|
731
|
+
);
|
|
732
|
+
const headerState = allMatching ? "all" /* All */ : pageHeaderState;
|
|
733
|
+
const bannerMode = useMemo(
|
|
734
|
+
() => onSelectAllMatchingChange === void 0 ? "hidden" /* Hidden */ : resolveSelectAllBannerMode(pageHeaderState, allMatching, pageKeys.length, matching),
|
|
735
|
+
[onSelectAllMatchingChange, pageHeaderState, allMatching, pageKeys.length, matching]
|
|
736
|
+
);
|
|
737
|
+
const isSelected = useCallback(
|
|
738
|
+
(key) => isRowSelected(selected, key, allMatching),
|
|
739
|
+
[selected, allMatching]
|
|
740
|
+
);
|
|
741
|
+
const toggleRow = useCallback(
|
|
742
|
+
(key) => {
|
|
743
|
+
if (allMatching) {
|
|
744
|
+
onSelectAllMatchingChange?.(false);
|
|
745
|
+
onSelectionChange?.(toggleSelectedKey(pageKeys, key));
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
onSelectionChange?.(toggleSelectedKey(selected, key));
|
|
749
|
+
},
|
|
750
|
+
[allMatching, onSelectAllMatchingChange, onSelectionChange, pageKeys, selected]
|
|
751
|
+
);
|
|
752
|
+
const toggleAll = useCallback(() => {
|
|
753
|
+
if (allMatching) {
|
|
754
|
+
onSelectAllMatchingChange?.(false);
|
|
755
|
+
onSelectionChange?.(NO_KEYS);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
onSelectionChange?.(toggleAllOnPage(selected, pageKeys));
|
|
759
|
+
}, [allMatching, onSelectAllMatchingChange, onSelectionChange, selected, pageKeys]);
|
|
760
|
+
const toggleAllMatching = useCallback(() => {
|
|
761
|
+
const next = !allMatching;
|
|
762
|
+
onSelectAllMatchingChange?.(next);
|
|
763
|
+
if (!next) onSelectionChange?.(NO_KEYS);
|
|
764
|
+
}, [allMatching, onSelectAllMatchingChange, onSelectionChange]);
|
|
765
|
+
return { selectable, headerState, bannerMode, isSelected, toggleRow, toggleAll, toggleAllMatching, matchingCount: matching };
|
|
766
|
+
}
|
|
208
767
|
var FIRST_ROW_INDEX = 0;
|
|
768
|
+
var EVEN = 0;
|
|
769
|
+
var ZEBRA_MODULUS = 2;
|
|
209
770
|
function DataTable(props) {
|
|
210
771
|
const {
|
|
211
772
|
columns,
|
|
@@ -222,6 +783,12 @@ function DataTable(props) {
|
|
|
222
783
|
renderRowDetail,
|
|
223
784
|
expandedRowKeys,
|
|
224
785
|
styleOverrides: o,
|
|
786
|
+
selectedRowKeys,
|
|
787
|
+
onSelectionChange,
|
|
788
|
+
matchingCount,
|
|
789
|
+
allMatchingSelected,
|
|
790
|
+
onSelectAllMatchingChange,
|
|
791
|
+
keyboardNavigation = false,
|
|
225
792
|
stackBreakpoint = CARD_STACK_BREAKPOINT,
|
|
226
793
|
testID = TABLE_TEST_IDS.root
|
|
227
794
|
} = props;
|
|
@@ -233,115 +800,118 @@ function DataTable(props) {
|
|
|
233
800
|
const interactive = onRowPress !== void 0;
|
|
234
801
|
const [hoveredKey, setHoveredKey] = useState(void 0);
|
|
235
802
|
const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
|
|
803
|
+
const rowKeys = useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
|
|
804
|
+
const selection = useTableSelection({
|
|
805
|
+
pageKeys: rowKeys,
|
|
806
|
+
selectedRowKeys,
|
|
807
|
+
onSelectionChange,
|
|
808
|
+
matchingCount,
|
|
809
|
+
allMatchingSelected,
|
|
810
|
+
onSelectAllMatchingChange
|
|
811
|
+
});
|
|
812
|
+
const activateKey = useCallback(
|
|
813
|
+
(key) => {
|
|
814
|
+
const row = rows[rowKeys.indexOf(key)];
|
|
815
|
+
if (row !== void 0) onRowPress?.(row);
|
|
816
|
+
},
|
|
817
|
+
[rowKeys, rows, onRowPress]
|
|
818
|
+
);
|
|
819
|
+
const roving = useRovingFocus({
|
|
820
|
+
rowKeys,
|
|
821
|
+
enabled: keyboardNavigation,
|
|
822
|
+
onToggleKey: selection.selectable ? selection.toggleRow : void 0,
|
|
823
|
+
onActivateKey: interactive ? activateKey : void 0
|
|
824
|
+
});
|
|
236
825
|
const rowBackground = useCallback(
|
|
237
826
|
(row, index) => {
|
|
238
827
|
const tint = rowTint?.(row);
|
|
239
828
|
if (tint) return tint;
|
|
240
|
-
return zebra && index %
|
|
829
|
+
return zebra && index % ZEBRA_MODULUS !== EVEN ? colors.background : void 0;
|
|
241
830
|
},
|
|
242
831
|
[rowTint, zebra, colors.background]
|
|
243
832
|
);
|
|
244
833
|
const rowBg = (row, index, key) => interactive && hoveredKey === key ? hoverTint : rowBackground(row, index);
|
|
245
|
-
const hoverHandlers = (key) => interactive ? {
|
|
246
|
-
onHoverIn: () => setHoveredKey(key),
|
|
247
|
-
onHoverOut: () => setHoveredKey((current) => current === key ? void 0 : current)
|
|
248
|
-
} : void 0;
|
|
249
834
|
const stateView = (label) => /* @__PURE__ */ jsx(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, children: /* @__PURE__ */ jsx(View, { style: [tableStyles.state, o?.state], children: /* @__PURE__ */ jsx(Text, { style: [tableStyles.stateText, { color: colors.textSecondary }, o?.stateText], children: label }) }) });
|
|
250
835
|
if (loading) return stateView(loadingLabel ?? t(TABLE_I18N.loading));
|
|
251
836
|
if (rows.length === 0) return stateView(emptyLabel ?? t(TABLE_I18N.empty));
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
const isExpanded = (key) => isExpandable && (expandedRowKeys?.includes(key) ?? false);
|
|
255
|
-
const rowA11y = (row, key) => ({
|
|
256
|
-
accessibilityLabel: getRowAccessibilityLabel?.(row) ?? t(TABLE_I18N.rowLabel),
|
|
257
|
-
accessibilityHint: t(TABLE_I18N.rowHint),
|
|
258
|
-
accessibilityRole: onRowPress ? "button" : "text",
|
|
259
|
-
// Only an expandable table announces expanded/collapsed — a plain table's rows
|
|
260
|
-
// keep exactly the props they had before this feature existed.
|
|
261
|
-
...isExpandable ? { accessibilityState: { expanded: isExpanded(key) }, "aria-expanded": isExpanded(key) } : null
|
|
262
|
-
});
|
|
263
|
-
const rowContainer = (row, rowKey, style, children) => interactive ? /* @__PURE__ */ jsx(
|
|
264
|
-
Pressable,
|
|
837
|
+
const renderRow = (row, key, style) => /* @__PURE__ */ jsx(
|
|
838
|
+
DataTableRow,
|
|
265
839
|
{
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
840
|
+
columns,
|
|
841
|
+
expanded: expandedRowKeys?.includes(key) ?? false,
|
|
842
|
+
getRowAccessibilityLabel,
|
|
843
|
+
keyboardNavigation,
|
|
844
|
+
renderRowDetail,
|
|
845
|
+
roving,
|
|
846
|
+
row,
|
|
847
|
+
rowKey: key,
|
|
848
|
+
selection,
|
|
849
|
+
stacked,
|
|
270
850
|
style,
|
|
271
|
-
|
|
851
|
+
styleOverrides: o,
|
|
852
|
+
tableTestID: testID,
|
|
853
|
+
onHoverIn: () => setHoveredKey(key),
|
|
854
|
+
onHoverOut: () => setHoveredKey((current) => current === key ? void 0 : current),
|
|
855
|
+
onRowPress
|
|
272
856
|
},
|
|
273
|
-
|
|
274
|
-
)
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
)
|
|
289
|
-
] }, key);
|
|
290
|
-
};
|
|
857
|
+
key
|
|
858
|
+
);
|
|
859
|
+
const banner = /* @__PURE__ */ jsx(
|
|
860
|
+
SelectAllBanner,
|
|
861
|
+
{
|
|
862
|
+
actionTestID: `${testID}-${TABLE_TEST_IDS.selectBannerActionSuffix}`,
|
|
863
|
+
matchingCount: selection.matchingCount,
|
|
864
|
+
mode: selection.bannerMode,
|
|
865
|
+
pageCount: rows.length,
|
|
866
|
+
styleOverride: o?.selectBanner,
|
|
867
|
+
testID: `${testID}-${TABLE_TEST_IDS.selectBannerSuffix}`,
|
|
868
|
+
onAction: selection.toggleAllMatching
|
|
869
|
+
}
|
|
870
|
+
);
|
|
291
871
|
if (stacked) {
|
|
292
|
-
return /* @__PURE__ */
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
key
|
|
309
|
-
);
|
|
310
|
-
}) });
|
|
872
|
+
return /* @__PURE__ */ jsxs(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, children: [
|
|
873
|
+
banner,
|
|
874
|
+
rows.map((row, i) => {
|
|
875
|
+
const key = rowKeys[i] ?? keyExtractor(row);
|
|
876
|
+
const bg = rowBg(row, i, key);
|
|
877
|
+
return renderRow(row, key, [
|
|
878
|
+
tableStyles.card,
|
|
879
|
+
{ borderTopColor: colors.border },
|
|
880
|
+
i === FIRST_ROW_INDEX ? { borderTopWidth: 0 } : null,
|
|
881
|
+
// A selectable card puts the checkbox beside its lines, so the card becomes a row.
|
|
882
|
+
selection.selectable ? selectionStyles.rowContent : null,
|
|
883
|
+
bg ? { backgroundColor: bg } : null,
|
|
884
|
+
o?.card
|
|
885
|
+
]);
|
|
886
|
+
})
|
|
887
|
+
] });
|
|
311
888
|
}
|
|
312
|
-
return /* @__PURE__ */ jsxs(
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
889
|
+
return /* @__PURE__ */ jsxs(
|
|
890
|
+
View,
|
|
891
|
+
{
|
|
892
|
+
style: [tableStyles.wrap, frame, o?.wrap],
|
|
893
|
+
testID,
|
|
894
|
+
...keyboardNavigation ? { role: "grid" } : null,
|
|
895
|
+
children: [
|
|
896
|
+
banner,
|
|
897
|
+
/* @__PURE__ */ jsx(
|
|
898
|
+
TableHeader,
|
|
320
899
|
{
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
),
|
|
328
|
-
rows.map((row, i) => {
|
|
329
|
-
const key = keyExtractor(row);
|
|
330
|
-
const bg = rowBg(row, i, key);
|
|
331
|
-
return withRowDetail(
|
|
332
|
-
// Pressable only for interactive tables; a static row is a plain View so its in-cell
|
|
333
|
-
// Edit/Delete/Stop controls receive the full pointer gesture — see rowContainer.
|
|
334
|
-
rowContainer(
|
|
335
|
-
row,
|
|
336
|
-
key,
|
|
337
|
-
[tableStyles.row, { borderTopColor: colors.border }, bg ? { backgroundColor: bg } : null, o?.row],
|
|
338
|
-
columns.map((col) => /* @__PURE__ */ jsx(DesktopCell, { column: col, row, textColor: colors.text, testID: `${rowID(key)}-${col.key}`, styleOverrides: o }, col.key))
|
|
900
|
+
columns,
|
|
901
|
+
inGrid: keyboardNavigation,
|
|
902
|
+
selection: selection.selectable ? { state: selection.headerState, onToggleAll: selection.toggleAll, testID: selectAllTestID(testID) } : void 0,
|
|
903
|
+
stickyHeader,
|
|
904
|
+
styleOverrides: o
|
|
905
|
+
}
|
|
339
906
|
),
|
|
340
|
-
row,
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
907
|
+
rows.map((row, i) => {
|
|
908
|
+
const key = rowKeys[i] ?? keyExtractor(row);
|
|
909
|
+
const bg = rowBg(row, i, key);
|
|
910
|
+
return renderRow(row, key, [tableStyles.row, { borderTopColor: colors.border }, bg ? { backgroundColor: bg } : null, o?.row]);
|
|
911
|
+
})
|
|
912
|
+
]
|
|
913
|
+
}
|
|
914
|
+
);
|
|
345
915
|
}
|
|
346
916
|
var RESULTS_COUNT_WEIGHT = "700";
|
|
347
917
|
function FilterBar({
|
|
@@ -377,11 +947,11 @@ function FilterBar({
|
|
|
377
947
|
}
|
|
378
948
|
var CHEVRON_DOWN = "\u25BE";
|
|
379
949
|
var CHEVRON_UP = "\u25B4";
|
|
380
|
-
var
|
|
950
|
+
var IS_WEB2 = Platform.OS === "web";
|
|
381
951
|
var MENU_TOP_GAP2 = 4;
|
|
382
952
|
var VIEWPORT_EDGE = 0;
|
|
383
953
|
function readTriggerRect(anchorRef) {
|
|
384
|
-
if (!
|
|
954
|
+
if (!IS_WEB2) return null;
|
|
385
955
|
const node = anchorRef.current;
|
|
386
956
|
if (node === null || typeof node.getBoundingClientRect !== "function") return null;
|
|
387
957
|
const r = node.getBoundingClientRect();
|
|
@@ -399,7 +969,7 @@ function buildWebFixedStyle(rect, viewportWidth) {
|
|
|
399
969
|
function useTriggerRect(anchorRef, isOpen) {
|
|
400
970
|
const [rect, setRect] = useState(null);
|
|
401
971
|
useLayoutEffect(() => {
|
|
402
|
-
if (!
|
|
972
|
+
if (!IS_WEB2 || !isOpen) return void 0;
|
|
403
973
|
const measure = () => {
|
|
404
974
|
setRect(readTriggerRect(anchorRef));
|
|
405
975
|
};
|
|
@@ -415,7 +985,7 @@ function useTriggerRect(anchorRef, isOpen) {
|
|
|
415
985
|
}
|
|
416
986
|
function useDismissOnOutside(anchorRef, menuRef, isOpen, onClose) {
|
|
417
987
|
useEffect(() => {
|
|
418
|
-
if (!
|
|
988
|
+
if (!IS_WEB2 || !isOpen) return void 0;
|
|
419
989
|
const onMouseDown = (event) => {
|
|
420
990
|
const anchorNode = anchorRef.current;
|
|
421
991
|
const menuNode = menuRef.current;
|
|
@@ -468,7 +1038,7 @@ function SizeDropdown({
|
|
|
468
1038
|
);
|
|
469
1039
|
const rect = useTriggerRect(anchorRef, isOpen);
|
|
470
1040
|
useDismissOnOutside(anchorRef, menuRef, isOpen, close);
|
|
471
|
-
const webFixedStyle =
|
|
1041
|
+
const webFixedStyle = IS_WEB2 && rect !== null ? buildWebFixedStyle(rect, window.innerWidth) : null;
|
|
472
1042
|
const menu = /* @__PURE__ */ jsx(
|
|
473
1043
|
View,
|
|
474
1044
|
{
|
|
@@ -513,14 +1083,14 @@ function SizeDropdown({
|
|
|
513
1083
|
]
|
|
514
1084
|
}
|
|
515
1085
|
),
|
|
516
|
-
isOpen ?
|
|
1086
|
+
isOpen ? IS_WEB2 ? createPortal(menu, document.body) : menu : null
|
|
517
1087
|
] });
|
|
518
1088
|
}
|
|
519
1089
|
var FIRST_PAGE = 1;
|
|
520
1090
|
var EN_DASH = "\u2013";
|
|
521
1091
|
var DISABLED_OPACITY = 0.4;
|
|
522
1092
|
var FULL_OPACITY = 1;
|
|
523
|
-
var
|
|
1093
|
+
var TRANSPARENT2 = "transparent";
|
|
524
1094
|
var BOLD = "700";
|
|
525
1095
|
var PAGER_HIT_SLOP = { top: 10, bottom: 10 };
|
|
526
1096
|
function NavButton({ label, hint, disabled, onPress, color, border, testID, styleOverrides: o }) {
|
|
@@ -617,7 +1187,7 @@ function Pager({
|
|
|
617
1187
|
accessibilityState: { selected: active },
|
|
618
1188
|
hitSlop: PAGER_HIT_SLOP,
|
|
619
1189
|
onPress: () => onPageSizeChange(size),
|
|
620
|
-
style: [chromeStyles.sizePill, { borderColor: active ? brand : colors.border, backgroundColor: active ? brand :
|
|
1190
|
+
style: [chromeStyles.sizePill, { borderColor: active ? brand : colors.border, backgroundColor: active ? brand : TRANSPARENT2 }, o?.sizePill],
|
|
621
1191
|
children: /* @__PURE__ */ jsx(Text, { style: [chromeStyles.sizePillText, { color: active ? colors.surface : colors.textSecondary }, o?.sizePillText], children: size })
|
|
622
1192
|
},
|
|
623
1193
|
size
|
|
@@ -653,6 +1223,6 @@ function Pager({
|
|
|
653
1223
|
] });
|
|
654
1224
|
}
|
|
655
1225
|
|
|
656
|
-
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FilterBar, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, rowDetailTestID, rowTestID };
|
|
1226
|
+
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FilterBar, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID };
|
|
657
1227
|
//# sourceMappingURL=index.mjs.map
|
|
658
1228
|
//# sourceMappingURL=index.mjs.map
|