@dloizides/ui-tables 1.9.2 → 1.11.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/ADOPTION.md +163 -0
- package/CHANGELOG.md +74 -0
- package/README.md +136 -1
- package/dist/index.d.mts +388 -8
- package/dist/index.d.ts +388 -8
- package/dist/index.js +1567 -218
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1542 -207
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { StyleSheet, View, Text, Platform, useWindowDimensions, Pressable } from 'react-native';
|
|
1
|
+
import React4, { memo, useState, useMemo, useCallback, useRef, useLayoutEffect, useEffect } from 'react';
|
|
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
5
|
import { createPortal } from 'react-dom';
|
|
@@ -47,6 +47,76 @@ 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
|
+
pagerFirst: "ui-pager-first",
|
|
74
|
+
pagerPrev: "ui-pager-prev",
|
|
75
|
+
pagerNext: "ui-pager-next",
|
|
76
|
+
pagerLast: "ui-pager-last"
|
|
77
|
+
};
|
|
78
|
+
var rowTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowInfix}-${key}`;
|
|
79
|
+
var rowDetailTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowDetailInfix}-${key}`;
|
|
80
|
+
var rowSelectTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowSelectInfix}-${key}`;
|
|
81
|
+
var selectAllTestID = (tableTestID) => `${tableTestID}-${TABLE_TEST_IDS.selectAllSuffix}`;
|
|
82
|
+
var TABLE_I18N = {
|
|
83
|
+
loading: "uiTables.loading",
|
|
84
|
+
empty: "uiTables.empty",
|
|
85
|
+
rowLabel: "uiTables.rowLabel",
|
|
86
|
+
rowHint: "uiTables.rowHint",
|
|
87
|
+
/** Accessible name of the full-width detail panel under an expanded row. */
|
|
88
|
+
rowDetail: "uiTables.rowDetail",
|
|
89
|
+
/** Accessible name of a row's select checkbox. */
|
|
90
|
+
selectRow: "uiTables.select.row",
|
|
91
|
+
selectRowHint: "uiTables.select.rowHint",
|
|
92
|
+
/** Accessible name of the header (select-all-on-page) checkbox. */
|
|
93
|
+
selectAll: "uiTables.select.all",
|
|
94
|
+
selectAllHint: "uiTables.select.allHint",
|
|
95
|
+
/** Banner, offer state: "All {{p1}} rows on this page are selected." */
|
|
96
|
+
selectPageSelected: "uiTables.select.pageSelected",
|
|
97
|
+
/** Banner, offer action: "Select all {{p1}} matching this filter". */
|
|
98
|
+
selectAllMatching: "uiTables.select.allMatching",
|
|
99
|
+
selectAllMatchingHint: "uiTables.select.allMatchingHint",
|
|
100
|
+
/** Banner, active state: "All {{p1}} rows matching this filter are selected." */
|
|
101
|
+
selectMatchingSelected: "uiTables.select.matchingSelected",
|
|
102
|
+
/** Banner, active action: "Clear selection". */
|
|
103
|
+
selectClear: "uiTables.select.clear",
|
|
104
|
+
selectClearHint: "uiTables.select.clearHint",
|
|
105
|
+
results: "uiTables.results",
|
|
106
|
+
pagerInfo: "uiTables.pager.info",
|
|
107
|
+
pagerFirst: "uiTables.pager.first",
|
|
108
|
+
pagerPrev: "uiTables.pager.prev",
|
|
109
|
+
pagerNext: "uiTables.pager.next",
|
|
110
|
+
pagerLast: "uiTables.pager.last",
|
|
111
|
+
pagerFirstHint: "uiTables.pager.firstHint",
|
|
112
|
+
pagerPrevHint: "uiTables.pager.prevHint",
|
|
113
|
+
pagerNextHint: "uiTables.pager.nextHint",
|
|
114
|
+
pagerLastHint: "uiTables.pager.lastHint",
|
|
115
|
+
pagerRows: "uiTables.pager.rows",
|
|
116
|
+
pagerRowsOptionHint: "uiTables.pager.rowsOptionHint",
|
|
117
|
+
/** Accessible hint for the dropdown-variant rows-per-page trigger button. */
|
|
118
|
+
pagerRowsTriggerHint: "uiTables.pager.rowsTriggerHint"
|
|
119
|
+
};
|
|
50
120
|
var BORDER_WIDTH = 1;
|
|
51
121
|
var BORDER_RADIUS = 12;
|
|
52
122
|
var COLUMN_GAP = 16;
|
|
@@ -78,6 +148,14 @@ var HEAD_LETTER_SPACING = 0.4;
|
|
|
78
148
|
var LABEL_LETTER_SPACING = 0.3;
|
|
79
149
|
var STICKY_Z = 2;
|
|
80
150
|
var FULL_WIDTH = "100%";
|
|
151
|
+
var SELECT_COL_WIDTH = 20;
|
|
152
|
+
var CHECKBOX_SIZE = 18;
|
|
153
|
+
var CHECKBOX_RADIUS = 4;
|
|
154
|
+
var CHECKBOX_GLYPH_FONT = 11;
|
|
155
|
+
var CHECKBOX_GLYPH_LINE = 13;
|
|
156
|
+
var BANNER_PAD_V = 8;
|
|
157
|
+
var BANNER_FONT = 13;
|
|
158
|
+
var BANNER_GAP = 6;
|
|
81
159
|
var STICKY_WEB_STYLE = {
|
|
82
160
|
position: "sticky",
|
|
83
161
|
top: 0,
|
|
@@ -108,6 +186,40 @@ var tableStyles = StyleSheet.create({
|
|
|
108
186
|
cardLabel: { fontSize: HEAD_FONT, fontWeight: "600", textTransform: "uppercase", letterSpacing: LABEL_LETTER_SPACING },
|
|
109
187
|
cardValue: { flexShrink: 1, alignItems: "flex-end" }
|
|
110
188
|
});
|
|
189
|
+
var selectionStyles = StyleSheet.create({
|
|
190
|
+
/** The fixed-width gutter holding the checkbox, in both the header and every row. */
|
|
191
|
+
selectCell: { width: SELECT_COL_WIDTH, alignItems: "flex-start", justifyContent: "center" },
|
|
192
|
+
/** The checkbox's pressable area (the hit target is grown further with `hitSlop`). */
|
|
193
|
+
checkboxHit: { alignItems: "center", justifyContent: "center" },
|
|
194
|
+
checkbox: {
|
|
195
|
+
width: CHECKBOX_SIZE,
|
|
196
|
+
height: CHECKBOX_SIZE,
|
|
197
|
+
borderRadius: CHECKBOX_RADIUS,
|
|
198
|
+
borderWidth: BORDER_WIDTH,
|
|
199
|
+
alignItems: "center",
|
|
200
|
+
justifyContent: "center"
|
|
201
|
+
},
|
|
202
|
+
checkboxGlyph: { fontSize: CHECKBOX_GLYPH_FONT, lineHeight: CHECKBOX_GLYPH_LINE, fontWeight: "700" },
|
|
203
|
+
/**
|
|
204
|
+
* The cells of a SELECTABLE row, wrapped so the checkbox can sit OUTSIDE the pressable
|
|
205
|
+
* area. `flex: 1` so the cells still claim the row minus the checkbox gutter.
|
|
206
|
+
*/
|
|
207
|
+
rowContent: { flex: 1, flexDirection: "row", columnGap: COLUMN_GAP, alignItems: "center" },
|
|
208
|
+
/** The same, for the card-stack: a card's lines are a column, not a row. */
|
|
209
|
+
cardContent: { flex: 1 },
|
|
210
|
+
/** The select-all-matching banner, spanning the table above the header. */
|
|
211
|
+
banner: {
|
|
212
|
+
flexDirection: "row",
|
|
213
|
+
flexWrap: "wrap",
|
|
214
|
+
alignItems: "center",
|
|
215
|
+
justifyContent: "center",
|
|
216
|
+
gap: BANNER_GAP,
|
|
217
|
+
paddingHorizontal: ROW_PAD_H,
|
|
218
|
+
paddingVertical: BANNER_PAD_V
|
|
219
|
+
},
|
|
220
|
+
bannerText: { fontSize: BANNER_FONT },
|
|
221
|
+
bannerAction: { fontSize: BANNER_FONT, fontWeight: "700", textDecorationLine: "underline" }
|
|
222
|
+
});
|
|
111
223
|
var chromeStyles = StyleSheet.create({
|
|
112
224
|
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
225
|
filtersSpacer: { flexGrow: 1 },
|
|
@@ -154,7 +266,7 @@ function cellContent(column, row, textColor, overrides) {
|
|
|
154
266
|
}
|
|
155
267
|
return content;
|
|
156
268
|
}
|
|
157
|
-
function DesktopCell({ column, row, textColor, testID, styleOverrides }) {
|
|
269
|
+
function DesktopCell({ column, row, textColor, testID, styleOverrides, inGrid }) {
|
|
158
270
|
return /* @__PURE__ */ jsx(
|
|
159
271
|
View,
|
|
160
272
|
{
|
|
@@ -163,49 +275,504 @@ function DesktopCell({ column, row, textColor, testID, styleOverrides }) {
|
|
|
163
275
|
styleOverrides?.cellWrap
|
|
164
276
|
],
|
|
165
277
|
testID,
|
|
278
|
+
...inGrid === true ? { role: "cell" } : null,
|
|
166
279
|
children: cellContent(column, row, textColor, styleOverrides)
|
|
167
280
|
}
|
|
168
281
|
);
|
|
169
282
|
}
|
|
283
|
+
function RowCells({
|
|
284
|
+
columns,
|
|
285
|
+
row,
|
|
286
|
+
stacked,
|
|
287
|
+
inGrid,
|
|
288
|
+
rowTestID: rowTestID2,
|
|
289
|
+
textColor,
|
|
290
|
+
labelColor,
|
|
291
|
+
styleOverrides: o
|
|
292
|
+
}) {
|
|
293
|
+
if (stacked) {
|
|
294
|
+
return /* @__PURE__ */ jsx(Fragment, { children: columns.map((col) => /* @__PURE__ */ jsxs(View, { style: [tableStyles.cardLine, o?.cardLine], children: [
|
|
295
|
+
/* @__PURE__ */ jsx(Text, { style: [tableStyles.cardLabel, { color: labelColor }, o?.cardLabel], children: col.header }),
|
|
296
|
+
/* @__PURE__ */ jsx(View, { style: [tableStyles.cardValue, o?.cardValue], children: cellContent(col, row, textColor, o) })
|
|
297
|
+
] }, col.key)) });
|
|
298
|
+
}
|
|
299
|
+
return /* @__PURE__ */ jsx(Fragment, { children: columns.map((col) => /* @__PURE__ */ jsx(
|
|
300
|
+
DesktopCell,
|
|
301
|
+
{
|
|
302
|
+
column: col,
|
|
303
|
+
inGrid,
|
|
304
|
+
row,
|
|
305
|
+
styleOverrides: o,
|
|
306
|
+
testID: `${rowTestID2}-${col.key}`,
|
|
307
|
+
textColor
|
|
308
|
+
},
|
|
309
|
+
col.key
|
|
310
|
+
)) });
|
|
311
|
+
}
|
|
312
|
+
var CHECK_GLYPH = "\u2713";
|
|
313
|
+
var MIXED_GLYPH = "\u2013";
|
|
314
|
+
var CHECKBOX_HIT_SLOP = { top: 12, bottom: 12, left: 12, right: 12 };
|
|
315
|
+
var TRANSPARENT = "transparent";
|
|
316
|
+
function toCheckedValue(state) {
|
|
317
|
+
if (state === "all" /* All */) return true;
|
|
318
|
+
return state === "some" /* Some */ ? "mixed" : false;
|
|
319
|
+
}
|
|
320
|
+
function toGlyph(state) {
|
|
321
|
+
if (state === "all" /* All */) return CHECK_GLYPH;
|
|
322
|
+
return state === "some" /* Some */ ? MIXED_GLYPH : void 0;
|
|
323
|
+
}
|
|
324
|
+
function SelectionCheckbox({
|
|
325
|
+
state,
|
|
326
|
+
label,
|
|
327
|
+
hint,
|
|
328
|
+
onToggle,
|
|
329
|
+
brandColor,
|
|
330
|
+
borderColor,
|
|
331
|
+
surfaceColor,
|
|
332
|
+
testID
|
|
333
|
+
}) {
|
|
334
|
+
const checked = toCheckedValue(state);
|
|
335
|
+
const glyph = toGlyph(state);
|
|
336
|
+
const filled = state !== "none" /* None */;
|
|
337
|
+
return /* @__PURE__ */ jsx(
|
|
338
|
+
Pressable,
|
|
339
|
+
{
|
|
340
|
+
accessibilityHint: hint,
|
|
341
|
+
accessibilityLabel: label,
|
|
342
|
+
accessibilityRole: "checkbox",
|
|
343
|
+
accessibilityState: { checked },
|
|
344
|
+
"aria-checked": checked,
|
|
345
|
+
hitSlop: CHECKBOX_HIT_SLOP,
|
|
346
|
+
style: selectionStyles.checkboxHit,
|
|
347
|
+
testID,
|
|
348
|
+
onPress: onToggle,
|
|
349
|
+
children: /* @__PURE__ */ jsx(
|
|
350
|
+
View,
|
|
351
|
+
{
|
|
352
|
+
style: [
|
|
353
|
+
selectionStyles.checkbox,
|
|
354
|
+
{ borderColor: filled ? brandColor : borderColor, backgroundColor: filled ? brandColor : TRANSPARENT }
|
|
355
|
+
],
|
|
356
|
+
children: glyph === void 0 ? null : /* @__PURE__ */ jsx(Text, { style: [selectionStyles.checkboxGlyph, { color: surfaceColor }], children: glyph })
|
|
357
|
+
}
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
var TAB_INDEX_INACTIVE = -1;
|
|
363
|
+
function webKeyProps(onKeyDown) {
|
|
364
|
+
return onKeyDown === void 0 ? {} : { onKeyDown };
|
|
365
|
+
}
|
|
366
|
+
function focusProps(keyboard) {
|
|
367
|
+
if (keyboard === void 0) return {};
|
|
368
|
+
return {
|
|
369
|
+
tabIndex: keyboard.tabIndex,
|
|
370
|
+
onFocus: keyboard.onFocus,
|
|
371
|
+
ref: (node) => keyboard.registerNode(node),
|
|
372
|
+
...webKeyProps(keyboard.onKeyDown)
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function TableRow({
|
|
376
|
+
testID,
|
|
377
|
+
style,
|
|
378
|
+
children,
|
|
379
|
+
a11y,
|
|
380
|
+
onPress,
|
|
381
|
+
onHoverIn,
|
|
382
|
+
onHoverOut,
|
|
383
|
+
selectionSlot,
|
|
384
|
+
stacked,
|
|
385
|
+
keyboard
|
|
386
|
+
}) {
|
|
387
|
+
const interactive = onPress !== void 0;
|
|
388
|
+
const hover = interactive ? { onHoverIn, onHoverOut } : null;
|
|
389
|
+
if (selectionSlot === void 0) {
|
|
390
|
+
return interactive ? /* @__PURE__ */ jsx(Pressable, { style, testID, onPress, ...hover, ...a11y, ...focusProps(keyboard), children }) : /* @__PURE__ */ jsx(View, { style, testID, ...a11y, ...focusProps(keyboard), children });
|
|
391
|
+
}
|
|
392
|
+
const contentStyle = stacked ? selectionStyles.cardContent : selectionStyles.rowContent;
|
|
393
|
+
const content = interactive ? /* @__PURE__ */ jsx(
|
|
394
|
+
Pressable,
|
|
395
|
+
{
|
|
396
|
+
style: contentStyle,
|
|
397
|
+
tabIndex: keyboard === void 0 ? void 0 : TAB_INDEX_INACTIVE,
|
|
398
|
+
onPress,
|
|
399
|
+
...hover,
|
|
400
|
+
children
|
|
401
|
+
}
|
|
402
|
+
) : /* @__PURE__ */ jsx(View, { style: contentStyle, children });
|
|
403
|
+
return /* @__PURE__ */ jsxs(View, { style, testID, ...a11y, ...focusProps(keyboard), children: [
|
|
404
|
+
/* @__PURE__ */ jsx(View, { style: selectionStyles.selectCell, children: selectionSlot }),
|
|
405
|
+
content
|
|
406
|
+
] });
|
|
407
|
+
}
|
|
408
|
+
function DataTableRow({
|
|
409
|
+
row,
|
|
410
|
+
rowKey,
|
|
411
|
+
style,
|
|
412
|
+
columns,
|
|
413
|
+
stacked,
|
|
414
|
+
tableTestID,
|
|
415
|
+
selection,
|
|
416
|
+
keyboardNavigation,
|
|
417
|
+
roving,
|
|
418
|
+
onRowPress,
|
|
419
|
+
getRowAccessibilityLabel,
|
|
420
|
+
renderRowDetail,
|
|
421
|
+
expanded,
|
|
422
|
+
onHoverIn,
|
|
423
|
+
onHoverOut,
|
|
424
|
+
styleOverrides: o
|
|
425
|
+
}) {
|
|
426
|
+
const { theme, t } = useUi();
|
|
427
|
+
const { colors } = theme;
|
|
428
|
+
const rowID = rowTestID(tableTestID, rowKey);
|
|
429
|
+
const isExpandable = renderRowDetail !== void 0;
|
|
430
|
+
const { selectable } = selection;
|
|
431
|
+
const isSelected = selectable && selection.isSelected(rowKey);
|
|
432
|
+
const a11y = {
|
|
433
|
+
accessibilityLabel: getRowAccessibilityLabel?.(row) ?? t(TABLE_I18N.rowLabel),
|
|
434
|
+
accessibilityHint: t(TABLE_I18N.rowHint),
|
|
435
|
+
accessibilityRole: onRowPress ? "button" : "text",
|
|
436
|
+
...isExpandable || selectable ? { accessibilityState: { ...isExpandable ? { expanded } : null, ...selectable ? { selected: isSelected } : null } } : null,
|
|
437
|
+
...isExpandable ? { "aria-expanded": expanded } : null,
|
|
438
|
+
...selectable ? { "aria-selected": isSelected } : null,
|
|
439
|
+
// A navigable table is a real grid, so its rows are grid rows — selectable or not.
|
|
440
|
+
// `role` wins over `accessibilityRole` on RNW.
|
|
441
|
+
...keyboardNavigation ? { role: "row" } : null
|
|
442
|
+
};
|
|
443
|
+
const rowNode = /* @__PURE__ */ jsx(
|
|
444
|
+
TableRow,
|
|
445
|
+
{
|
|
446
|
+
a11y,
|
|
447
|
+
keyboard: keyboardNavigation ? {
|
|
448
|
+
tabIndex: roving.tabIndexFor(rowKey),
|
|
449
|
+
onKeyDown: roving.keyDownFor(rowKey),
|
|
450
|
+
onFocus: () => roving.onRowFocus(rowKey),
|
|
451
|
+
registerNode: (node) => roving.registerRow(rowKey, node)
|
|
452
|
+
} : void 0,
|
|
453
|
+
selectionSlot: selectable ? /* @__PURE__ */ jsx(
|
|
454
|
+
SelectionCheckbox,
|
|
455
|
+
{
|
|
456
|
+
borderColor: colors.border,
|
|
457
|
+
brandColor: theme.palette.primary["500"],
|
|
458
|
+
hint: t(TABLE_I18N.selectRowHint),
|
|
459
|
+
label: getRowAccessibilityLabel?.(row) ?? t(TABLE_I18N.selectRow),
|
|
460
|
+
state: isSelected ? "all" /* All */ : "none" /* None */,
|
|
461
|
+
surfaceColor: colors.surface,
|
|
462
|
+
testID: rowSelectTestID(tableTestID, rowKey),
|
|
463
|
+
onToggle: () => selection.toggleRow(rowKey)
|
|
464
|
+
}
|
|
465
|
+
) : void 0,
|
|
466
|
+
stacked,
|
|
467
|
+
style,
|
|
468
|
+
testID: rowID,
|
|
469
|
+
onHoverIn,
|
|
470
|
+
onHoverOut,
|
|
471
|
+
onPress: onRowPress === void 0 ? void 0 : () => onRowPress(row),
|
|
472
|
+
children: /* @__PURE__ */ jsx(
|
|
473
|
+
RowCells,
|
|
474
|
+
{
|
|
475
|
+
columns,
|
|
476
|
+
inGrid: keyboardNavigation,
|
|
477
|
+
labelColor: colors.textSecondary,
|
|
478
|
+
row,
|
|
479
|
+
rowTestID: rowID,
|
|
480
|
+
stacked,
|
|
481
|
+
styleOverrides: o,
|
|
482
|
+
textColor: colors.text
|
|
483
|
+
}
|
|
484
|
+
)
|
|
485
|
+
}
|
|
486
|
+
);
|
|
487
|
+
if (!isExpandable || !expanded) return rowNode;
|
|
488
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
489
|
+
rowNode,
|
|
490
|
+
/* @__PURE__ */ jsx(
|
|
491
|
+
View,
|
|
492
|
+
{
|
|
493
|
+
accessibilityLabel: t(TABLE_I18N.rowDetail),
|
|
494
|
+
accessibilityRole: "summary",
|
|
495
|
+
style: [tableStyles.rowDetail, { borderTopColor: colors.border, backgroundColor: colors.background }, o?.rowDetail],
|
|
496
|
+
testID: rowDetailTestID(tableTestID, rowKey),
|
|
497
|
+
children: renderRowDetail(row)
|
|
498
|
+
}
|
|
499
|
+
)
|
|
500
|
+
] });
|
|
501
|
+
}
|
|
502
|
+
function SelectAllBanner({
|
|
503
|
+
mode,
|
|
504
|
+
pageCount,
|
|
505
|
+
matchingCount,
|
|
506
|
+
onAction,
|
|
507
|
+
testID,
|
|
508
|
+
actionTestID,
|
|
509
|
+
styleOverride
|
|
510
|
+
}) {
|
|
511
|
+
const { theme, t } = useUi();
|
|
512
|
+
const { colors, palette } = theme;
|
|
513
|
+
if (mode === "hidden" /* Hidden */) return null;
|
|
514
|
+
const active = mode === "active" /* Active */;
|
|
515
|
+
const message = active ? t(TABLE_I18N.selectMatchingSelected, matchingCount.toLocaleString()) : t(TABLE_I18N.selectPageSelected, pageCount.toLocaleString());
|
|
516
|
+
const actionLabel = active ? t(TABLE_I18N.selectClear) : t(TABLE_I18N.selectAllMatching, matchingCount.toLocaleString());
|
|
517
|
+
const actionHint = active ? t(TABLE_I18N.selectClearHint) : t(TABLE_I18N.selectAllMatchingHint);
|
|
518
|
+
return /* @__PURE__ */ jsxs(
|
|
519
|
+
View,
|
|
520
|
+
{
|
|
521
|
+
accessibilityLiveRegion: "polite",
|
|
522
|
+
style: [selectionStyles.banner, { backgroundColor: colors.background }, styleOverride],
|
|
523
|
+
testID,
|
|
524
|
+
children: [
|
|
525
|
+
/* @__PURE__ */ jsx(Text, { style: [selectionStyles.bannerText, { color: colors.textSecondary }], children: message }),
|
|
526
|
+
/* @__PURE__ */ jsx(
|
|
527
|
+
Pressable,
|
|
528
|
+
{
|
|
529
|
+
accessibilityHint: actionHint,
|
|
530
|
+
accessibilityLabel: actionLabel,
|
|
531
|
+
accessibilityRole: "button",
|
|
532
|
+
testID: actionTestID,
|
|
533
|
+
onPress: onAction,
|
|
534
|
+
children: /* @__PURE__ */ jsx(Text, { style: [selectionStyles.bannerAction, { color: palette.primary["500"] }], children: actionLabel })
|
|
535
|
+
}
|
|
536
|
+
)
|
|
537
|
+
]
|
|
538
|
+
}
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
function TableHeader({ columns, stickyHeader, selection, inGrid, styleOverrides: o }) {
|
|
542
|
+
const { theme, t } = useUi();
|
|
543
|
+
const { colors } = theme;
|
|
544
|
+
return /* @__PURE__ */ jsxs(
|
|
545
|
+
View,
|
|
546
|
+
{
|
|
547
|
+
style: [tableStyles.headRow, { backgroundColor: colors.background }, stickyHeader ? STICKY_HEADER_STYLE : null, o?.headRow],
|
|
548
|
+
testID: TABLE_TEST_IDS.head,
|
|
549
|
+
...inGrid ? { role: "row" } : null,
|
|
550
|
+
children: [
|
|
551
|
+
selection === void 0 ? null : /* @__PURE__ */ jsx(View, { style: [selectionStyles.selectCell, o?.selectCell], children: /* @__PURE__ */ jsx(
|
|
552
|
+
SelectionCheckbox,
|
|
553
|
+
{
|
|
554
|
+
borderColor: colors.border,
|
|
555
|
+
brandColor: theme.palette.primary["500"],
|
|
556
|
+
hint: t(TABLE_I18N.selectAllHint),
|
|
557
|
+
label: t(TABLE_I18N.selectAll),
|
|
558
|
+
state: selection.state,
|
|
559
|
+
surfaceColor: colors.surface,
|
|
560
|
+
testID: selection.testID,
|
|
561
|
+
onToggle: selection.onToggleAll
|
|
562
|
+
}
|
|
563
|
+
) }),
|
|
564
|
+
columns.map((col) => /* @__PURE__ */ jsx(
|
|
565
|
+
Text,
|
|
566
|
+
{
|
|
567
|
+
style: [tableStyles.headCell, { color: colors.textSecondary, flex: col.weight ?? 1, textAlign: col.numeric ? "right" : "left" }, o?.headCell],
|
|
568
|
+
...inGrid ? { role: "columnheader" } : null,
|
|
569
|
+
children: col.header
|
|
570
|
+
},
|
|
571
|
+
col.key
|
|
572
|
+
))
|
|
573
|
+
]
|
|
574
|
+
}
|
|
575
|
+
);
|
|
576
|
+
}
|
|
170
577
|
|
|
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
|
-
|
|
578
|
+
// src/DataTable/rowNav.ts
|
|
579
|
+
var FIRST_INDEX = 0;
|
|
580
|
+
var ONE_ROW = 1;
|
|
581
|
+
var NOT_FOUND = -1;
|
|
582
|
+
function toRowNavAction(key) {
|
|
583
|
+
switch (key) {
|
|
584
|
+
case "ArrowDown":
|
|
585
|
+
return "next" /* Next */;
|
|
586
|
+
case "ArrowUp":
|
|
587
|
+
return "prev" /* Prev */;
|
|
588
|
+
case "Home":
|
|
589
|
+
return "first" /* First */;
|
|
590
|
+
case "End":
|
|
591
|
+
return "last" /* Last */;
|
|
592
|
+
case " ":
|
|
593
|
+
case "Spacebar":
|
|
594
|
+
return "toggle" /* Toggle */;
|
|
595
|
+
case "Enter":
|
|
596
|
+
return "activate" /* Activate */;
|
|
597
|
+
default:
|
|
598
|
+
return void 0;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function nextRowIndex(currentIndex, action, rowCount) {
|
|
602
|
+
if (rowCount === FIRST_INDEX) return void 0;
|
|
603
|
+
const lastIndex = rowCount - ONE_ROW;
|
|
604
|
+
switch (action) {
|
|
605
|
+
case "next" /* Next */:
|
|
606
|
+
return Math.min(currentIndex + ONE_ROW, lastIndex);
|
|
607
|
+
case "prev" /* Prev */:
|
|
608
|
+
return Math.max(currentIndex - ONE_ROW, FIRST_INDEX);
|
|
609
|
+
case "first" /* First */:
|
|
610
|
+
return FIRST_INDEX;
|
|
611
|
+
case "last" /* Last */:
|
|
612
|
+
return lastIndex;
|
|
613
|
+
default:
|
|
614
|
+
return void 0;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function resolveTabbableKey(rowKeys, focusedKey) {
|
|
618
|
+
if (rowKeys.length === FIRST_INDEX) return void 0;
|
|
619
|
+
if (focusedKey !== void 0 && rowKeys.includes(focusedKey)) return focusedKey;
|
|
620
|
+
return rowKeys[FIRST_INDEX];
|
|
621
|
+
}
|
|
622
|
+
function focusedRowIndex(rowKeys, focusedKey) {
|
|
623
|
+
const index = focusedKey === void 0 ? NOT_FOUND : rowKeys.indexOf(focusedKey);
|
|
624
|
+
return index === NOT_FOUND ? FIRST_INDEX : index;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// src/DataTable/useRovingFocus.ts
|
|
628
|
+
var TAB_INDEX_ACTIVE = 0;
|
|
629
|
+
var TAB_INDEX_INACTIVE2 = -1;
|
|
630
|
+
var IS_WEB = Platform.OS === "web";
|
|
631
|
+
function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
|
|
632
|
+
const [focusedKey, setFocusedKey] = useState(void 0);
|
|
633
|
+
const nodes = useRef(/* @__PURE__ */ new Map());
|
|
634
|
+
const tabbableKey = enabled ? resolveTabbableKey(rowKeys, focusedKey) : void 0;
|
|
635
|
+
const registerRow = useCallback((key, node) => {
|
|
636
|
+
if (node === null || node === void 0) {
|
|
637
|
+
nodes.current.delete(key);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
nodes.current.set(key, node);
|
|
641
|
+
}, []);
|
|
642
|
+
const focusRow = useCallback((key) => {
|
|
643
|
+
setFocusedKey(key);
|
|
644
|
+
nodes.current.get(key)?.focus?.();
|
|
645
|
+
}, []);
|
|
646
|
+
const handleKey = useCallback(
|
|
647
|
+
(event, key) => {
|
|
648
|
+
const action = toRowNavAction(event.key);
|
|
649
|
+
if (action === void 0) return;
|
|
650
|
+
if (action === "toggle" /* Toggle */) {
|
|
651
|
+
if (onToggleKey === void 0) return;
|
|
652
|
+
event.preventDefault();
|
|
653
|
+
onToggleKey(key);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (action === "activate" /* Activate */) {
|
|
657
|
+
if (onActivateKey === void 0) return;
|
|
658
|
+
event.preventDefault();
|
|
659
|
+
onActivateKey(key);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const target = nextRowIndex(focusedRowIndex(rowKeys, key), action, rowKeys.length);
|
|
663
|
+
if (target === void 0) return;
|
|
664
|
+
const targetKey = rowKeys[target];
|
|
665
|
+
if (targetKey === void 0) return;
|
|
666
|
+
event.preventDefault();
|
|
667
|
+
focusRow(targetKey);
|
|
668
|
+
},
|
|
669
|
+
[rowKeys, onToggleKey, onActivateKey, focusRow]
|
|
670
|
+
);
|
|
671
|
+
const keyDownFor = useCallback(
|
|
672
|
+
(key) => {
|
|
673
|
+
if (!enabled || !IS_WEB) return void 0;
|
|
674
|
+
return (event) => handleKey(event, key);
|
|
675
|
+
},
|
|
676
|
+
[enabled, handleKey]
|
|
677
|
+
);
|
|
678
|
+
const tabIndexFor = useCallback(
|
|
679
|
+
(key) => key === tabbableKey ? TAB_INDEX_ACTIVE : TAB_INDEX_INACTIVE2,
|
|
680
|
+
[tabbableKey]
|
|
681
|
+
);
|
|
682
|
+
const onRowFocus = useCallback((key) => setFocusedKey(key), []);
|
|
683
|
+
return { tabIndexFor, registerRow, onRowFocus, keyDownFor };
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/DataTable/selection.ts
|
|
687
|
+
var NONE = 0;
|
|
688
|
+
function toggleSelectedKey(selectedKeys, key) {
|
|
689
|
+
return selectedKeys.includes(key) ? selectedKeys.filter((selected) => selected !== key) : [...selectedKeys, key];
|
|
690
|
+
}
|
|
691
|
+
function countSelectedOnPage(selectedKeys, pageKeys) {
|
|
692
|
+
return pageKeys.filter((key) => selectedKeys.includes(key)).length;
|
|
693
|
+
}
|
|
694
|
+
function resolveHeaderCheckboxState(selectedKeys, pageKeys) {
|
|
695
|
+
if (pageKeys.length === NONE) return "none" /* None */;
|
|
696
|
+
const selectedOnPage = countSelectedOnPage(selectedKeys, pageKeys);
|
|
697
|
+
if (selectedOnPage === NONE) return "none" /* None */;
|
|
698
|
+
return selectedOnPage === pageKeys.length ? "all" /* All */ : "some" /* Some */;
|
|
699
|
+
}
|
|
700
|
+
function toggleAllOnPage(selectedKeys, pageKeys) {
|
|
701
|
+
const state = resolveHeaderCheckboxState(selectedKeys, pageKeys);
|
|
702
|
+
if (state === "all" /* All */) return selectedKeys.filter((key) => !pageKeys.includes(key));
|
|
703
|
+
const merged = [...selectedKeys];
|
|
704
|
+
pageKeys.forEach((key) => {
|
|
705
|
+
if (!merged.includes(key)) merged.push(key);
|
|
706
|
+
});
|
|
707
|
+
return merged;
|
|
708
|
+
}
|
|
709
|
+
function resolveSelectAllBannerMode(headerState, allMatchingSelected, pageCount, matchingCount) {
|
|
710
|
+
if (allMatchingSelected) return "active" /* Active */;
|
|
711
|
+
const pageFullySelected = headerState === "all" /* All */ && pageCount > NONE;
|
|
712
|
+
const moreBeyondThisPage = matchingCount > pageCount;
|
|
713
|
+
return pageFullySelected && moreBeyondThisPage ? "offer" /* Offer */ : "hidden" /* Hidden */;
|
|
714
|
+
}
|
|
715
|
+
function isRowSelected(selectedKeys, key, allMatchingSelected) {
|
|
716
|
+
return allMatchingSelected || selectedKeys.includes(key);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// src/DataTable/useTableSelection.ts
|
|
720
|
+
var NO_KEYS = [];
|
|
721
|
+
var NO_MATCHES = 0;
|
|
722
|
+
function useTableSelection({
|
|
723
|
+
pageKeys,
|
|
724
|
+
selectedRowKeys,
|
|
725
|
+
onSelectionChange,
|
|
726
|
+
matchingCount,
|
|
727
|
+
allMatchingSelected,
|
|
728
|
+
onSelectAllMatchingChange
|
|
729
|
+
}) {
|
|
730
|
+
const selectable = onSelectionChange !== void 0;
|
|
731
|
+
const selected = selectedRowKeys ?? NO_KEYS;
|
|
732
|
+
const allMatching = allMatchingSelected ?? false;
|
|
733
|
+
const matching = matchingCount ?? NO_MATCHES;
|
|
734
|
+
const pageHeaderState = useMemo(
|
|
735
|
+
() => resolveHeaderCheckboxState(selected, pageKeys),
|
|
736
|
+
[selected, pageKeys]
|
|
737
|
+
);
|
|
738
|
+
const headerState = allMatching ? "all" /* All */ : pageHeaderState;
|
|
739
|
+
const bannerMode = useMemo(
|
|
740
|
+
() => onSelectAllMatchingChange === void 0 ? "hidden" /* Hidden */ : resolveSelectAllBannerMode(pageHeaderState, allMatching, pageKeys.length, matching),
|
|
741
|
+
[onSelectAllMatchingChange, pageHeaderState, allMatching, pageKeys.length, matching]
|
|
742
|
+
);
|
|
743
|
+
const isSelected = useCallback(
|
|
744
|
+
(key) => isRowSelected(selected, key, allMatching),
|
|
745
|
+
[selected, allMatching]
|
|
746
|
+
);
|
|
747
|
+
const toggleRow = useCallback(
|
|
748
|
+
(key) => {
|
|
749
|
+
if (allMatching) {
|
|
750
|
+
onSelectAllMatchingChange?.(false);
|
|
751
|
+
onSelectionChange?.(toggleSelectedKey(pageKeys, key));
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
onSelectionChange?.(toggleSelectedKey(selected, key));
|
|
755
|
+
},
|
|
756
|
+
[allMatching, onSelectAllMatchingChange, onSelectionChange, pageKeys, selected]
|
|
757
|
+
);
|
|
758
|
+
const toggleAll = useCallback(() => {
|
|
759
|
+
if (allMatching) {
|
|
760
|
+
onSelectAllMatchingChange?.(false);
|
|
761
|
+
onSelectionChange?.(NO_KEYS);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
onSelectionChange?.(toggleAllOnPage(selected, pageKeys));
|
|
765
|
+
}, [allMatching, onSelectAllMatchingChange, onSelectionChange, selected, pageKeys]);
|
|
766
|
+
const toggleAllMatching = useCallback(() => {
|
|
767
|
+
const next = !allMatching;
|
|
768
|
+
onSelectAllMatchingChange?.(next);
|
|
769
|
+
if (!next) onSelectionChange?.(NO_KEYS);
|
|
770
|
+
}, [allMatching, onSelectAllMatchingChange, onSelectionChange]);
|
|
771
|
+
return { selectable, headerState, bannerMode, isSelected, toggleRow, toggleAll, toggleAllMatching, matchingCount: matching };
|
|
772
|
+
}
|
|
208
773
|
var FIRST_ROW_INDEX = 0;
|
|
774
|
+
var EVEN = 0;
|
|
775
|
+
var ZEBRA_MODULUS = 2;
|
|
209
776
|
function DataTable(props) {
|
|
210
777
|
const {
|
|
211
778
|
columns,
|
|
@@ -222,6 +789,12 @@ function DataTable(props) {
|
|
|
222
789
|
renderRowDetail,
|
|
223
790
|
expandedRowKeys,
|
|
224
791
|
styleOverrides: o,
|
|
792
|
+
selectedRowKeys,
|
|
793
|
+
onSelectionChange,
|
|
794
|
+
matchingCount,
|
|
795
|
+
allMatchingSelected,
|
|
796
|
+
onSelectAllMatchingChange,
|
|
797
|
+
keyboardNavigation = false,
|
|
225
798
|
stackBreakpoint = CARD_STACK_BREAKPOINT,
|
|
226
799
|
testID = TABLE_TEST_IDS.root
|
|
227
800
|
} = props;
|
|
@@ -233,115 +806,118 @@ function DataTable(props) {
|
|
|
233
806
|
const interactive = onRowPress !== void 0;
|
|
234
807
|
const [hoveredKey, setHoveredKey] = useState(void 0);
|
|
235
808
|
const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
|
|
809
|
+
const rowKeys = useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
|
|
810
|
+
const selection = useTableSelection({
|
|
811
|
+
pageKeys: rowKeys,
|
|
812
|
+
selectedRowKeys,
|
|
813
|
+
onSelectionChange,
|
|
814
|
+
matchingCount,
|
|
815
|
+
allMatchingSelected,
|
|
816
|
+
onSelectAllMatchingChange
|
|
817
|
+
});
|
|
818
|
+
const activateKey = useCallback(
|
|
819
|
+
(key) => {
|
|
820
|
+
const row = rows[rowKeys.indexOf(key)];
|
|
821
|
+
if (row !== void 0) onRowPress?.(row);
|
|
822
|
+
},
|
|
823
|
+
[rowKeys, rows, onRowPress]
|
|
824
|
+
);
|
|
825
|
+
const roving = useRovingFocus({
|
|
826
|
+
rowKeys,
|
|
827
|
+
enabled: keyboardNavigation,
|
|
828
|
+
onToggleKey: selection.selectable ? selection.toggleRow : void 0,
|
|
829
|
+
onActivateKey: interactive ? activateKey : void 0
|
|
830
|
+
});
|
|
236
831
|
const rowBackground = useCallback(
|
|
237
832
|
(row, index) => {
|
|
238
833
|
const tint = rowTint?.(row);
|
|
239
834
|
if (tint) return tint;
|
|
240
|
-
return zebra && index %
|
|
835
|
+
return zebra && index % ZEBRA_MODULUS !== EVEN ? colors.background : void 0;
|
|
241
836
|
},
|
|
242
837
|
[rowTint, zebra, colors.background]
|
|
243
838
|
);
|
|
244
839
|
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
840
|
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
841
|
if (loading) return stateView(loadingLabel ?? t(TABLE_I18N.loading));
|
|
251
842
|
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,
|
|
843
|
+
const renderRow = (row, key, style) => /* @__PURE__ */ jsx(
|
|
844
|
+
DataTableRow,
|
|
265
845
|
{
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
846
|
+
columns,
|
|
847
|
+
expanded: expandedRowKeys?.includes(key) ?? false,
|
|
848
|
+
getRowAccessibilityLabel,
|
|
849
|
+
keyboardNavigation,
|
|
850
|
+
renderRowDetail,
|
|
851
|
+
roving,
|
|
852
|
+
row,
|
|
853
|
+
rowKey: key,
|
|
854
|
+
selection,
|
|
855
|
+
stacked,
|
|
270
856
|
style,
|
|
271
|
-
|
|
857
|
+
styleOverrides: o,
|
|
858
|
+
tableTestID: testID,
|
|
859
|
+
onHoverIn: () => setHoveredKey(key),
|
|
860
|
+
onHoverOut: () => setHoveredKey((current) => current === key ? void 0 : current),
|
|
861
|
+
onRowPress
|
|
272
862
|
},
|
|
273
|
-
|
|
274
|
-
)
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
)
|
|
289
|
-
] }, key);
|
|
290
|
-
};
|
|
863
|
+
key
|
|
864
|
+
);
|
|
865
|
+
const banner = /* @__PURE__ */ jsx(
|
|
866
|
+
SelectAllBanner,
|
|
867
|
+
{
|
|
868
|
+
actionTestID: `${testID}-${TABLE_TEST_IDS.selectBannerActionSuffix}`,
|
|
869
|
+
matchingCount: selection.matchingCount,
|
|
870
|
+
mode: selection.bannerMode,
|
|
871
|
+
pageCount: rows.length,
|
|
872
|
+
styleOverride: o?.selectBanner,
|
|
873
|
+
testID: `${testID}-${TABLE_TEST_IDS.selectBannerSuffix}`,
|
|
874
|
+
onAction: selection.toggleAllMatching
|
|
875
|
+
}
|
|
876
|
+
);
|
|
291
877
|
if (stacked) {
|
|
292
|
-
return /* @__PURE__ */
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
key
|
|
309
|
-
);
|
|
310
|
-
}) });
|
|
878
|
+
return /* @__PURE__ */ jsxs(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, children: [
|
|
879
|
+
banner,
|
|
880
|
+
rows.map((row, i) => {
|
|
881
|
+
const key = rowKeys[i] ?? keyExtractor(row);
|
|
882
|
+
const bg = rowBg(row, i, key);
|
|
883
|
+
return renderRow(row, key, [
|
|
884
|
+
tableStyles.card,
|
|
885
|
+
{ borderTopColor: colors.border },
|
|
886
|
+
i === FIRST_ROW_INDEX ? { borderTopWidth: 0 } : null,
|
|
887
|
+
// A selectable card puts the checkbox beside its lines, so the card becomes a row.
|
|
888
|
+
selection.selectable ? selectionStyles.rowContent : null,
|
|
889
|
+
bg ? { backgroundColor: bg } : null,
|
|
890
|
+
o?.card
|
|
891
|
+
]);
|
|
892
|
+
})
|
|
893
|
+
] });
|
|
311
894
|
}
|
|
312
|
-
return /* @__PURE__ */ jsxs(
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
895
|
+
return /* @__PURE__ */ jsxs(
|
|
896
|
+
View,
|
|
897
|
+
{
|
|
898
|
+
style: [tableStyles.wrap, frame, o?.wrap],
|
|
899
|
+
testID,
|
|
900
|
+
...keyboardNavigation ? { role: "grid" } : null,
|
|
901
|
+
children: [
|
|
902
|
+
banner,
|
|
903
|
+
/* @__PURE__ */ jsx(
|
|
904
|
+
TableHeader,
|
|
320
905
|
{
|
|
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))
|
|
906
|
+
columns,
|
|
907
|
+
inGrid: keyboardNavigation,
|
|
908
|
+
selection: selection.selectable ? { state: selection.headerState, onToggleAll: selection.toggleAll, testID: selectAllTestID(testID) } : void 0,
|
|
909
|
+
stickyHeader,
|
|
910
|
+
styleOverrides: o
|
|
911
|
+
}
|
|
339
912
|
),
|
|
340
|
-
row,
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
913
|
+
rows.map((row, i) => {
|
|
914
|
+
const key = rowKeys[i] ?? keyExtractor(row);
|
|
915
|
+
const bg = rowBg(row, i, key);
|
|
916
|
+
return renderRow(row, key, [tableStyles.row, { borderTopColor: colors.border }, bg ? { backgroundColor: bg } : null, o?.row]);
|
|
917
|
+
})
|
|
918
|
+
]
|
|
919
|
+
}
|
|
920
|
+
);
|
|
345
921
|
}
|
|
346
922
|
var RESULTS_COUNT_WEIGHT = "700";
|
|
347
923
|
function FilterBar({
|
|
@@ -377,11 +953,11 @@ function FilterBar({
|
|
|
377
953
|
}
|
|
378
954
|
var CHEVRON_DOWN = "\u25BE";
|
|
379
955
|
var CHEVRON_UP = "\u25B4";
|
|
380
|
-
var
|
|
956
|
+
var IS_WEB2 = Platform.OS === "web";
|
|
381
957
|
var MENU_TOP_GAP2 = 4;
|
|
382
958
|
var VIEWPORT_EDGE = 0;
|
|
383
959
|
function readTriggerRect(anchorRef) {
|
|
384
|
-
if (!
|
|
960
|
+
if (!IS_WEB2) return null;
|
|
385
961
|
const node = anchorRef.current;
|
|
386
962
|
if (node === null || typeof node.getBoundingClientRect !== "function") return null;
|
|
387
963
|
const r = node.getBoundingClientRect();
|
|
@@ -399,7 +975,7 @@ function buildWebFixedStyle(rect, viewportWidth) {
|
|
|
399
975
|
function useTriggerRect(anchorRef, isOpen) {
|
|
400
976
|
const [rect, setRect] = useState(null);
|
|
401
977
|
useLayoutEffect(() => {
|
|
402
|
-
if (!
|
|
978
|
+
if (!IS_WEB2 || !isOpen) return void 0;
|
|
403
979
|
const measure = () => {
|
|
404
980
|
setRect(readTriggerRect(anchorRef));
|
|
405
981
|
};
|
|
@@ -415,7 +991,7 @@ function useTriggerRect(anchorRef, isOpen) {
|
|
|
415
991
|
}
|
|
416
992
|
function useDismissOnOutside(anchorRef, menuRef, isOpen, onClose) {
|
|
417
993
|
useEffect(() => {
|
|
418
|
-
if (!
|
|
994
|
+
if (!IS_WEB2 || !isOpen) return void 0;
|
|
419
995
|
const onMouseDown = (event) => {
|
|
420
996
|
const anchorNode = anchorRef.current;
|
|
421
997
|
const menuNode = menuRef.current;
|
|
@@ -468,7 +1044,7 @@ function SizeDropdown({
|
|
|
468
1044
|
);
|
|
469
1045
|
const rect = useTriggerRect(anchorRef, isOpen);
|
|
470
1046
|
useDismissOnOutside(anchorRef, menuRef, isOpen, close);
|
|
471
|
-
const webFixedStyle =
|
|
1047
|
+
const webFixedStyle = IS_WEB2 && rect !== null ? buildWebFixedStyle(rect, window.innerWidth) : null;
|
|
472
1048
|
const menu = /* @__PURE__ */ jsx(
|
|
473
1049
|
View,
|
|
474
1050
|
{
|
|
@@ -513,15 +1089,13 @@ function SizeDropdown({
|
|
|
513
1089
|
]
|
|
514
1090
|
}
|
|
515
1091
|
),
|
|
516
|
-
isOpen ?
|
|
1092
|
+
isOpen ? IS_WEB2 ? createPortal(menu, document.body) : menu : null
|
|
517
1093
|
] });
|
|
518
1094
|
}
|
|
519
1095
|
var FIRST_PAGE = 1;
|
|
520
|
-
var EN_DASH = "\u2013";
|
|
521
1096
|
var DISABLED_OPACITY = 0.4;
|
|
522
1097
|
var FULL_OPACITY = 1;
|
|
523
|
-
var
|
|
524
|
-
var BOLD = "700";
|
|
1098
|
+
var TRANSPARENT2 = "transparent";
|
|
525
1099
|
var PAGER_HIT_SLOP = { top: 10, bottom: 10 };
|
|
526
1100
|
function NavButton({ label, hint, disabled, onPress, color, border, testID, styleOverrides: o }) {
|
|
527
1101
|
return /* @__PURE__ */ jsx(
|
|
@@ -540,6 +1114,136 @@ function NavButton({ label, hint, disabled, onPress, color, border, testID, styl
|
|
|
540
1114
|
}
|
|
541
1115
|
);
|
|
542
1116
|
}
|
|
1117
|
+
function RowsControl({ pageSize, pageSizeOptions, onPageSizeChange, isDropdown, testID, styleOverrides: o }) {
|
|
1118
|
+
const { theme, t } = useUi();
|
|
1119
|
+
const { colors, palette } = theme;
|
|
1120
|
+
const brand = palette.primary["500"];
|
|
1121
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1122
|
+
/* @__PURE__ */ jsx(Text, { style: [isDropdown ? chromeStyles.pagerRowsLabelPlain : chromeStyles.pagerRowsLabel, { color: colors.textSecondary }, o?.pagerRowsLabel], children: t(TABLE_I18N.pagerRows) }),
|
|
1123
|
+
isDropdown ? /* @__PURE__ */ jsx(
|
|
1124
|
+
SizeDropdown,
|
|
1125
|
+
{
|
|
1126
|
+
pageSize,
|
|
1127
|
+
pageSizeOptions,
|
|
1128
|
+
onPageSizeChange,
|
|
1129
|
+
testID,
|
|
1130
|
+
triggerHint: t(TABLE_I18N.pagerRowsTriggerHint),
|
|
1131
|
+
optionHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1132
|
+
textColor: colors.text,
|
|
1133
|
+
mutedColor: colors.textSecondary,
|
|
1134
|
+
borderColor: colors.border,
|
|
1135
|
+
surfaceColor: colors.surface,
|
|
1136
|
+
brandColor: brand,
|
|
1137
|
+
triggerStyle: o?.sizePill,
|
|
1138
|
+
triggerTextStyle: o?.sizePillText
|
|
1139
|
+
}
|
|
1140
|
+
) : /* @__PURE__ */ jsx(View, { style: [chromeStyles.sizeGroup, o?.sizeGroup], children: pageSizeOptions.map((size) => {
|
|
1141
|
+
const active = size === pageSize;
|
|
1142
|
+
return /* @__PURE__ */ jsx(
|
|
1143
|
+
Pressable,
|
|
1144
|
+
{
|
|
1145
|
+
testID: `${testID}-size-${size}`,
|
|
1146
|
+
accessibilityRole: "button",
|
|
1147
|
+
accessibilityLabel: String(size),
|
|
1148
|
+
accessibilityHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1149
|
+
accessibilityState: { selected: active },
|
|
1150
|
+
hitSlop: PAGER_HIT_SLOP,
|
|
1151
|
+
onPress: () => onPageSizeChange(size),
|
|
1152
|
+
style: [chromeStyles.sizePill, { borderColor: active ? brand : colors.border, backgroundColor: active ? brand : TRANSPARENT2 }, o?.sizePill],
|
|
1153
|
+
children: /* @__PURE__ */ jsx(Text, { style: [chromeStyles.sizePillText, { color: active ? colors.surface : colors.textSecondary }, o?.sizePillText], children: size })
|
|
1154
|
+
},
|
|
1155
|
+
size
|
|
1156
|
+
);
|
|
1157
|
+
}) })
|
|
1158
|
+
] });
|
|
1159
|
+
}
|
|
1160
|
+
function PagerNav({
|
|
1161
|
+
pageSize,
|
|
1162
|
+
pageSizeOptions,
|
|
1163
|
+
onPageSizeChange,
|
|
1164
|
+
onPageChange,
|
|
1165
|
+
safePage,
|
|
1166
|
+
lastPage,
|
|
1167
|
+
isCompact,
|
|
1168
|
+
isDropdown,
|
|
1169
|
+
showFirstLast,
|
|
1170
|
+
testID,
|
|
1171
|
+
styleOverrides: o
|
|
1172
|
+
}) {
|
|
1173
|
+
const { theme, t } = useUi();
|
|
1174
|
+
const { colors } = theme;
|
|
1175
|
+
const atFirst = safePage <= FIRST_PAGE;
|
|
1176
|
+
const atLast = safePage >= lastPage;
|
|
1177
|
+
const showJumps = showFirstLast && !isCompact;
|
|
1178
|
+
return /* @__PURE__ */ jsxs(View, { style: [chromeStyles.pagerNav, o?.pagerNav], children: [
|
|
1179
|
+
!isCompact && /* @__PURE__ */ jsx(
|
|
1180
|
+
RowsControl,
|
|
1181
|
+
{
|
|
1182
|
+
pageSize,
|
|
1183
|
+
pageSizeOptions,
|
|
1184
|
+
onPageSizeChange,
|
|
1185
|
+
isDropdown,
|
|
1186
|
+
testID,
|
|
1187
|
+
styleOverrides: o
|
|
1188
|
+
}
|
|
1189
|
+
),
|
|
1190
|
+
showJumps && /* @__PURE__ */ jsx(
|
|
1191
|
+
NavButton,
|
|
1192
|
+
{
|
|
1193
|
+
label: t(TABLE_I18N.pagerFirst),
|
|
1194
|
+
hint: t(TABLE_I18N.pagerFirstHint),
|
|
1195
|
+
disabled: atFirst,
|
|
1196
|
+
onPress: () => onPageChange(FIRST_PAGE),
|
|
1197
|
+
color: colors.text,
|
|
1198
|
+
border: colors.border,
|
|
1199
|
+
styleOverrides: o,
|
|
1200
|
+
testID: TABLE_TEST_IDS.pagerFirst
|
|
1201
|
+
}
|
|
1202
|
+
),
|
|
1203
|
+
/* @__PURE__ */ jsx(
|
|
1204
|
+
NavButton,
|
|
1205
|
+
{
|
|
1206
|
+
label: t(TABLE_I18N.pagerPrev),
|
|
1207
|
+
hint: t(TABLE_I18N.pagerPrevHint),
|
|
1208
|
+
disabled: atFirst,
|
|
1209
|
+
onPress: () => onPageChange(safePage - 1),
|
|
1210
|
+
color: colors.text,
|
|
1211
|
+
border: colors.border,
|
|
1212
|
+
styleOverrides: o,
|
|
1213
|
+
testID: TABLE_TEST_IDS.pagerPrev
|
|
1214
|
+
}
|
|
1215
|
+
),
|
|
1216
|
+
/* @__PURE__ */ jsx(
|
|
1217
|
+
NavButton,
|
|
1218
|
+
{
|
|
1219
|
+
label: t(TABLE_I18N.pagerNext),
|
|
1220
|
+
hint: t(TABLE_I18N.pagerNextHint),
|
|
1221
|
+
disabled: atLast,
|
|
1222
|
+
onPress: () => onPageChange(safePage + 1),
|
|
1223
|
+
color: colors.text,
|
|
1224
|
+
border: colors.border,
|
|
1225
|
+
styleOverrides: o,
|
|
1226
|
+
testID: TABLE_TEST_IDS.pagerNext
|
|
1227
|
+
}
|
|
1228
|
+
),
|
|
1229
|
+
showJumps && /* @__PURE__ */ jsx(
|
|
1230
|
+
NavButton,
|
|
1231
|
+
{
|
|
1232
|
+
label: t(TABLE_I18N.pagerLast),
|
|
1233
|
+
hint: t(TABLE_I18N.pagerLastHint),
|
|
1234
|
+
disabled: atLast,
|
|
1235
|
+
onPress: () => onPageChange(lastPage),
|
|
1236
|
+
color: colors.text,
|
|
1237
|
+
border: colors.border,
|
|
1238
|
+
styleOverrides: o,
|
|
1239
|
+
testID: TABLE_TEST_IDS.pagerLast
|
|
1240
|
+
}
|
|
1241
|
+
)
|
|
1242
|
+
] });
|
|
1243
|
+
}
|
|
1244
|
+
var FIRST_PAGE2 = 1;
|
|
1245
|
+
var EN_DASH = "\u2013";
|
|
1246
|
+
var BOLD = "700";
|
|
543
1247
|
function Pager({
|
|
544
1248
|
page,
|
|
545
1249
|
pageSize,
|
|
@@ -549,24 +1253,30 @@ function Pager({
|
|
|
549
1253
|
pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS,
|
|
550
1254
|
rowsVariant = "pills",
|
|
551
1255
|
unitLabel,
|
|
1256
|
+
unitLabelSingular,
|
|
1257
|
+
showFirstLast = false,
|
|
1258
|
+
responsive = false,
|
|
1259
|
+
stackBreakpoint = CARD_STACK_BREAKPOINT,
|
|
552
1260
|
infoPrefix,
|
|
553
1261
|
boldNumbers = false,
|
|
554
1262
|
styleOverrides: o,
|
|
555
1263
|
testID = TABLE_TEST_IDS.pager
|
|
556
1264
|
}) {
|
|
557
1265
|
const { theme, t } = useUi();
|
|
558
|
-
const { colors
|
|
559
|
-
const
|
|
1266
|
+
const { colors } = theme;
|
|
1267
|
+
const { width } = useWindowDimensions();
|
|
560
1268
|
const isDropdown = rowsVariant === "dropdown";
|
|
561
|
-
const
|
|
562
|
-
const
|
|
1269
|
+
const isCompact = responsive && width < stackBreakpoint;
|
|
1270
|
+
const lastPage = Math.max(FIRST_PAGE2, Math.ceil(total / pageSize));
|
|
1271
|
+
const safePage = Math.min(Math.max(page, FIRST_PAGE2), lastPage);
|
|
563
1272
|
const from = total === 0 ? 0 : (safePage - 1) * pageSize + 1;
|
|
564
1273
|
const to = Math.min(safePage * pageSize, total);
|
|
565
1274
|
const hasUnit = unitLabel !== void 0 && unitLabel !== "";
|
|
1275
|
+
const resolvedUnit = total === 1 && unitLabelSingular !== void 0 && unitLabelSingular !== "" ? unitLabelSingular : unitLabel;
|
|
566
1276
|
const hasPrefix = infoPrefix !== void 0 && infoPrefix !== "";
|
|
567
1277
|
const prefix = hasPrefix ? `${infoPrefix} ` : "";
|
|
568
1278
|
const ofWord = t(TABLE_I18N.pagerInfo);
|
|
569
|
-
const unitSuffix = hasUnit ? ` ${
|
|
1279
|
+
const unitSuffix = hasUnit ? ` ${resolvedUnit}` : "";
|
|
570
1280
|
const count = `${from.toLocaleString()}${EN_DASH}${to.toLocaleString()} ${ofWord} ${total.toLocaleString()}`;
|
|
571
1281
|
const info = `${prefix}${count}${unitSuffix}`;
|
|
572
1282
|
const boldStyle = { color: colors.text, fontWeight: BOLD };
|
|
@@ -580,79 +1290,704 @@ function Pager({
|
|
|
580
1290
|
/* @__PURE__ */ jsx(Text, { style: boldStyle, children: total.toLocaleString() }),
|
|
581
1291
|
unitSuffix
|
|
582
1292
|
] }) : info }),
|
|
583
|
-
/* @__PURE__ */
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
1293
|
+
/* @__PURE__ */ jsx(
|
|
1294
|
+
PagerNav,
|
|
1295
|
+
{
|
|
1296
|
+
pageSize,
|
|
1297
|
+
pageSizeOptions,
|
|
1298
|
+
onPageSizeChange,
|
|
1299
|
+
onPageChange,
|
|
1300
|
+
safePage,
|
|
1301
|
+
lastPage,
|
|
1302
|
+
isCompact,
|
|
1303
|
+
isDropdown,
|
|
1304
|
+
showFirstLast,
|
|
1305
|
+
testID,
|
|
1306
|
+
styleOverrides: o
|
|
1307
|
+
}
|
|
1308
|
+
)
|
|
1309
|
+
] });
|
|
1310
|
+
}
|
|
1311
|
+
var FIELD_GAP = 4;
|
|
1312
|
+
var LABEL_FONT = 11;
|
|
1313
|
+
var LABEL_LETTER_SPACING2 = 0.4;
|
|
1314
|
+
var INPUT_RADIUS = 8;
|
|
1315
|
+
var INPUT_PAD_H = 12;
|
|
1316
|
+
var INPUT_PAD_V = 10;
|
|
1317
|
+
var INPUT_FONT = 14;
|
|
1318
|
+
var INPUT_BORDER = 1;
|
|
1319
|
+
var DATE_ROW_GAP = 8;
|
|
1320
|
+
var CHEVRON_FONT2 = 10;
|
|
1321
|
+
var MENU_TOP_GAP3 = 4;
|
|
1322
|
+
var MENU_RADIUS = 8;
|
|
1323
|
+
var MENU_PAD_V2 = 4;
|
|
1324
|
+
var MENU_OPT_PAD_H = 12;
|
|
1325
|
+
var MENU_OPT_PAD_V2 = 8;
|
|
1326
|
+
var MENU_MIN_WIDTH2 = 160;
|
|
1327
|
+
var MENU_MAX_HEIGHT = 260;
|
|
1328
|
+
var MENU_Z = 1e3;
|
|
1329
|
+
var MENU_ELEVATION2 = 8;
|
|
1330
|
+
var MENU_BOX_SHADOW2 = "0px 2px 8px rgba(0, 0, 0, 0.15)";
|
|
1331
|
+
var OPTION_FONT = 14;
|
|
1332
|
+
var ERROR_FONT = 12;
|
|
1333
|
+
var ERROR_GAP = 3;
|
|
1334
|
+
var SWITCH_ROW_GAP = 8;
|
|
1335
|
+
var ACTION_PAD_H = 14;
|
|
1336
|
+
var ACTION_PAD_V = 8;
|
|
1337
|
+
var ACTION_RADIUS = 8;
|
|
1338
|
+
var ACTION_FONT = 13;
|
|
1339
|
+
var filterStyles = StyleSheet.create({
|
|
1340
|
+
field: { gap: FIELD_GAP },
|
|
1341
|
+
label: { fontSize: LABEL_FONT, fontWeight: "700", letterSpacing: LABEL_LETTER_SPACING2, textTransform: "uppercase" },
|
|
1342
|
+
input: {
|
|
1343
|
+
borderWidth: INPUT_BORDER,
|
|
1344
|
+
borderRadius: INPUT_RADIUS,
|
|
1345
|
+
paddingHorizontal: INPUT_PAD_H,
|
|
1346
|
+
paddingVertical: INPUT_PAD_V,
|
|
1347
|
+
fontSize: INPUT_FONT
|
|
1348
|
+
},
|
|
1349
|
+
/** The select trigger: a bordered field box matching the text inputs + a chevron. */
|
|
1350
|
+
selectTrigger: {
|
|
1351
|
+
flexDirection: "row",
|
|
1352
|
+
alignItems: "center",
|
|
1353
|
+
justifyContent: "space-between",
|
|
1354
|
+
gap: DATE_ROW_GAP,
|
|
1355
|
+
borderWidth: INPUT_BORDER,
|
|
1356
|
+
borderRadius: INPUT_RADIUS,
|
|
1357
|
+
paddingHorizontal: INPUT_PAD_H,
|
|
1358
|
+
paddingVertical: INPUT_PAD_V
|
|
1359
|
+
},
|
|
1360
|
+
selectTriggerText: { fontSize: INPUT_FONT, flexShrink: 1 },
|
|
1361
|
+
chevron: { fontSize: CHEVRON_FONT2 },
|
|
1362
|
+
dateRow: { flexDirection: "row", gap: DATE_ROW_GAP },
|
|
1363
|
+
dateCol: { gap: FIELD_GAP, flex: 1 },
|
|
1364
|
+
subLabel: { fontSize: LABEL_FONT, letterSpacing: LABEL_LETTER_SPACING2 },
|
|
1365
|
+
anchor: { position: "relative" },
|
|
1366
|
+
menu: {
|
|
1367
|
+
position: "absolute",
|
|
1368
|
+
top: "100%",
|
|
1369
|
+
left: 0,
|
|
1370
|
+
marginTop: MENU_TOP_GAP3,
|
|
1371
|
+
minWidth: MENU_MIN_WIDTH2,
|
|
1372
|
+
maxHeight: MENU_MAX_HEIGHT,
|
|
1373
|
+
borderWidth: INPUT_BORDER,
|
|
1374
|
+
borderRadius: MENU_RADIUS,
|
|
1375
|
+
paddingVertical: MENU_PAD_V2,
|
|
1376
|
+
zIndex: MENU_Z,
|
|
1377
|
+
boxShadow: MENU_BOX_SHADOW2,
|
|
1378
|
+
elevation: MENU_ELEVATION2,
|
|
1379
|
+
overflow: "hidden"
|
|
1380
|
+
},
|
|
1381
|
+
option: { paddingHorizontal: MENU_OPT_PAD_H, paddingVertical: MENU_OPT_PAD_V2 },
|
|
1382
|
+
optionText: { fontSize: OPTION_FONT },
|
|
1383
|
+
error: { fontSize: ERROR_FONT, marginTop: ERROR_GAP },
|
|
1384
|
+
switchRow: { flexDirection: "row", alignItems: "center", gap: SWITCH_ROW_GAP, paddingVertical: FIELD_GAP },
|
|
1385
|
+
action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth: INPUT_BORDER },
|
|
1386
|
+
actionText: { fontSize: ACTION_FONT, fontWeight: "600" }
|
|
1387
|
+
});
|
|
1388
|
+
var FILTER_HIT_SLOP = { top: 8, bottom: 8 };
|
|
1389
|
+
var DISABLED_OPACITY2 = 0.4;
|
|
1390
|
+
var FULL_OPACITY2 = 1;
|
|
1391
|
+
var TRANSPARENT3 = "transparent";
|
|
1392
|
+
function ActionButton({ label, hint, tone, disabled = false, onPress, testID }) {
|
|
1393
|
+
const { theme } = useUi();
|
|
1394
|
+
const { colors, palette } = theme;
|
|
1395
|
+
const isPrimary = tone === "primary";
|
|
1396
|
+
const brand = palette.primary["500"];
|
|
1397
|
+
return /* @__PURE__ */ jsx(
|
|
1398
|
+
Pressable,
|
|
1399
|
+
{
|
|
1400
|
+
accessibilityRole: "button",
|
|
1401
|
+
accessibilityLabel: label,
|
|
1402
|
+
accessibilityHint: hint,
|
|
1403
|
+
accessibilityState: { disabled },
|
|
1404
|
+
disabled,
|
|
1405
|
+
hitSlop: FILTER_HIT_SLOP,
|
|
1406
|
+
onPress,
|
|
1407
|
+
style: [
|
|
1408
|
+
filterStyles.action,
|
|
593
1409
|
{
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
testID,
|
|
598
|
-
triggerHint: t(TABLE_I18N.pagerRowsTriggerHint),
|
|
599
|
-
optionHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
600
|
-
textColor: colors.text,
|
|
601
|
-
mutedColor: colors.textSecondary,
|
|
602
|
-
borderColor: colors.border,
|
|
603
|
-
surfaceColor: colors.surface,
|
|
604
|
-
brandColor: brand,
|
|
605
|
-
triggerStyle: o?.sizePill,
|
|
606
|
-
triggerTextStyle: o?.sizePillText
|
|
1410
|
+
borderColor: isPrimary ? brand : colors.border,
|
|
1411
|
+
backgroundColor: isPrimary ? brand : TRANSPARENT3,
|
|
1412
|
+
opacity: disabled ? DISABLED_OPACITY2 : FULL_OPACITY2
|
|
607
1413
|
}
|
|
608
|
-
|
|
609
|
-
|
|
1414
|
+
],
|
|
1415
|
+
testID,
|
|
1416
|
+
children: /* @__PURE__ */ jsx(Text, { style: [filterStyles.actionText, { color: isPrimary ? colors.surface : colors.text }], children: label })
|
|
1417
|
+
}
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// src/Filters/constants.ts
|
|
1422
|
+
var FILTERS_TEST_ID = "ui-filters-declarative";
|
|
1423
|
+
var FIELD_MIN_WIDTH = {
|
|
1424
|
+
select: 150,
|
|
1425
|
+
text: 200,
|
|
1426
|
+
number: 130,
|
|
1427
|
+
dateRange: 260,
|
|
1428
|
+
typeahead: 200,
|
|
1429
|
+
boolean: 150
|
|
1430
|
+
};
|
|
1431
|
+
var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
|
|
1432
|
+
var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
|
|
1433
|
+
var fieldTestID = (barTestID, key) => `${barTestID}-field-${key}`;
|
|
1434
|
+
var applyTestID = (barTestID) => `${barTestID}-apply`;
|
|
1435
|
+
var clearTestID = (barTestID) => `${barTestID}-clear`;
|
|
1436
|
+
var FILTERS_I18N = {
|
|
1437
|
+
apply: "uiTables.filters.apply",
|
|
1438
|
+
applyHint: "uiTables.filters.applyHint",
|
|
1439
|
+
clear: "uiTables.filters.clear",
|
|
1440
|
+
clearHint: "uiTables.filters.clearHint",
|
|
1441
|
+
selectPlaceholder: "uiTables.filters.selectPlaceholder",
|
|
1442
|
+
dropdownHint: "uiTables.filters.dropdownHint",
|
|
1443
|
+
optionHint: "uiTables.filters.optionHint",
|
|
1444
|
+
from: "uiTables.filters.from",
|
|
1445
|
+
to: "uiTables.filters.to"
|
|
1446
|
+
};
|
|
1447
|
+
var GROW_FLEX = 1;
|
|
1448
|
+
function FieldShell({ field, barTestID, children }) {
|
|
1449
|
+
const { theme } = useUi();
|
|
1450
|
+
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1451
|
+
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1452
|
+
return /* @__PURE__ */ jsxs(
|
|
1453
|
+
View,
|
|
1454
|
+
{
|
|
1455
|
+
style: [filterStyles.field, { minWidth }, grow, field.style],
|
|
1456
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1457
|
+
children: [
|
|
1458
|
+
/* @__PURE__ */ jsx(Text, { style: [filterStyles.label, { color: theme.colors.textSecondary }], children: field.label }),
|
|
1459
|
+
children
|
|
1460
|
+
]
|
|
1461
|
+
}
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
function BooleanField({ field, barTestID, value, onChange }) {
|
|
1465
|
+
const { theme } = useUi();
|
|
1466
|
+
const { colors, palette } = theme;
|
|
1467
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1468
|
+
return /* @__PURE__ */ jsxs(View, { style: filterStyles.switchRow, testID, children: [
|
|
1469
|
+
/* @__PURE__ */ jsx(Text, { style: [filterStyles.subLabel, { color: colors.text }], children: field.label }),
|
|
1470
|
+
/* @__PURE__ */ jsx(
|
|
1471
|
+
Switch,
|
|
1472
|
+
{
|
|
1473
|
+
accessibilityLabel: field.label,
|
|
1474
|
+
accessibilityHint: field.accessibilityHint,
|
|
1475
|
+
accessibilityRole: "switch",
|
|
1476
|
+
accessibilityState: { checked: value },
|
|
1477
|
+
trackColor: { false: colors.border, true: palette.primary["500"] },
|
|
1478
|
+
thumbColor: colors.surface,
|
|
1479
|
+
value,
|
|
1480
|
+
onValueChange: onChange,
|
|
1481
|
+
testID: `${testID}-switch`
|
|
1482
|
+
}
|
|
1483
|
+
)
|
|
1484
|
+
] });
|
|
1485
|
+
}
|
|
1486
|
+
var WEB_DATE_PROPS = typeof document !== "undefined" ? { type: "date" } : {};
|
|
1487
|
+
function DateInput(p) {
|
|
1488
|
+
return /* @__PURE__ */ jsxs(View, { style: filterStyles.dateCol, children: [
|
|
1489
|
+
/* @__PURE__ */ jsx(Text, { style: [filterStyles.subLabel, { color: p.muted }], children: p.label }),
|
|
1490
|
+
/* @__PURE__ */ jsx(
|
|
1491
|
+
TextInput,
|
|
1492
|
+
{
|
|
1493
|
+
accessibilityLabel: p.label,
|
|
1494
|
+
accessibilityHint: p.hint,
|
|
1495
|
+
placeholder: p.placeholder,
|
|
1496
|
+
placeholderTextColor: p.muted,
|
|
1497
|
+
value: p.value,
|
|
1498
|
+
onChangeText: p.onChangeText,
|
|
1499
|
+
onSubmitEditing: p.onSubmit,
|
|
1500
|
+
style: [filterStyles.input, { borderColor: p.border, backgroundColor: p.surface, color: p.color }],
|
|
1501
|
+
testID: `${p.testID}-${p.side}`,
|
|
1502
|
+
...WEB_DATE_PROPS
|
|
1503
|
+
}
|
|
1504
|
+
)
|
|
1505
|
+
] });
|
|
1506
|
+
}
|
|
1507
|
+
function DateRangeField({ field, barTestID, value, onChange, onSubmit, fromLabel, toLabel }) {
|
|
1508
|
+
const { theme } = useUi();
|
|
1509
|
+
const { colors } = theme;
|
|
1510
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1511
|
+
return /* @__PURE__ */ jsxs(View, { style: filterStyles.dateRow, testID: `${testID}-range`, children: [
|
|
1512
|
+
/* @__PURE__ */ jsx(
|
|
1513
|
+
DateInput,
|
|
1514
|
+
{
|
|
1515
|
+
side: "from",
|
|
1516
|
+
label: field.fromLabel ?? fromLabel,
|
|
1517
|
+
placeholder: field.fromPlaceholder,
|
|
1518
|
+
value: value.from,
|
|
1519
|
+
color: colors.text,
|
|
1520
|
+
border: colors.border,
|
|
1521
|
+
surface: colors.surface,
|
|
1522
|
+
muted: colors.textSecondary,
|
|
1523
|
+
hint: field.accessibilityHint,
|
|
1524
|
+
testID,
|
|
1525
|
+
onChangeText: (from) => onChange({ from, to: value.to }),
|
|
1526
|
+
onSubmit
|
|
1527
|
+
}
|
|
1528
|
+
),
|
|
1529
|
+
/* @__PURE__ */ jsx(
|
|
1530
|
+
DateInput,
|
|
1531
|
+
{
|
|
1532
|
+
side: "to",
|
|
1533
|
+
label: field.toLabel ?? toLabel,
|
|
1534
|
+
placeholder: field.toPlaceholder,
|
|
1535
|
+
value: value.to,
|
|
1536
|
+
color: colors.text,
|
|
1537
|
+
border: colors.border,
|
|
1538
|
+
surface: colors.surface,
|
|
1539
|
+
muted: colors.textSecondary,
|
|
1540
|
+
hint: field.accessibilityHint,
|
|
1541
|
+
testID,
|
|
1542
|
+
onChangeText: (to) => onChange({ from: value.from, to }),
|
|
1543
|
+
onSubmit
|
|
1544
|
+
}
|
|
1545
|
+
)
|
|
1546
|
+
] });
|
|
1547
|
+
}
|
|
1548
|
+
var IS_WEB3 = typeof document !== "undefined";
|
|
1549
|
+
var ESCAPE_KEY = "Escape";
|
|
1550
|
+
var ACTIVE_WEIGHT = "700";
|
|
1551
|
+
var IDLE_WEIGHT = "400";
|
|
1552
|
+
function useDismiss(anchorRef, menuRef, onDismiss) {
|
|
1553
|
+
useEffect(() => {
|
|
1554
|
+
if (!IS_WEB3) return void 0;
|
|
1555
|
+
const onMouseDown = (event) => {
|
|
1556
|
+
const anchorNode = anchorRef.current;
|
|
1557
|
+
const menuNode = menuRef.current;
|
|
1558
|
+
const target = event.target instanceof Node ? event.target : null;
|
|
1559
|
+
const insideAnchor = anchorNode !== null && target !== null && anchorNode.contains(target);
|
|
1560
|
+
const insideMenu = menuNode !== null && target !== null && menuNode.contains(target);
|
|
1561
|
+
if (!insideAnchor && !insideMenu) onDismiss();
|
|
1562
|
+
};
|
|
1563
|
+
const onKeyDown = (event) => {
|
|
1564
|
+
if (event.key === ESCAPE_KEY) onDismiss();
|
|
1565
|
+
};
|
|
1566
|
+
document.addEventListener("mousedown", onMouseDown);
|
|
1567
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1568
|
+
return () => {
|
|
1569
|
+
document.removeEventListener("mousedown", onMouseDown);
|
|
1570
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1571
|
+
};
|
|
1572
|
+
}, [anchorRef, menuRef, onDismiss]);
|
|
1573
|
+
}
|
|
1574
|
+
function AnchoredMenu({
|
|
1575
|
+
options,
|
|
1576
|
+
selectedValue,
|
|
1577
|
+
onSelect,
|
|
1578
|
+
onDismiss,
|
|
1579
|
+
colors,
|
|
1580
|
+
optionHint,
|
|
1581
|
+
testID,
|
|
1582
|
+
anchorRef
|
|
1583
|
+
}) {
|
|
1584
|
+
const menuRef = React4.useRef(null);
|
|
1585
|
+
useDismiss(anchorRef, menuRef, onDismiss);
|
|
1586
|
+
return /* @__PURE__ */ jsx(
|
|
1587
|
+
View,
|
|
1588
|
+
{
|
|
1589
|
+
ref: menuRef,
|
|
1590
|
+
accessibilityRole: "menu",
|
|
1591
|
+
style: [filterStyles.menu, { borderColor: colors.border, backgroundColor: colors.surface }],
|
|
1592
|
+
testID: `${testID}-menu`,
|
|
1593
|
+
children: options.map((opt) => {
|
|
1594
|
+
const active = opt.value === selectedValue;
|
|
610
1595
|
return /* @__PURE__ */ jsx(
|
|
611
1596
|
Pressable,
|
|
612
1597
|
{
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
accessibilityHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1598
|
+
accessibilityRole: "menuitem",
|
|
1599
|
+
accessibilityLabel: opt.label,
|
|
1600
|
+
accessibilityHint: optionHint,
|
|
617
1601
|
accessibilityState: { selected: active },
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
children: /* @__PURE__ */ jsx(Text, { style: [
|
|
1602
|
+
onPress: () => onSelect(opt.value),
|
|
1603
|
+
style: filterStyles.option,
|
|
1604
|
+
testID: `${testID}-option-${opt.value}`,
|
|
1605
|
+
children: /* @__PURE__ */ jsx(Text, { style: [filterStyles.optionText, { color: active ? colors.brand : colors.text, fontWeight: active ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: opt.label })
|
|
622
1606
|
},
|
|
623
|
-
|
|
1607
|
+
opt.value
|
|
624
1608
|
);
|
|
625
|
-
})
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
1609
|
+
})
|
|
1610
|
+
}
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1613
|
+
var CHEVRON_DOWN2 = "\u25BE";
|
|
1614
|
+
var CHEVRON_UP2 = "\u25B4";
|
|
1615
|
+
function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
|
|
1616
|
+
const { theme } = useUi();
|
|
1617
|
+
const { colors, palette } = theme;
|
|
1618
|
+
const anchorRef = useRef(null);
|
|
1619
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
1620
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1621
|
+
const selectedLabel = useMemo(() => {
|
|
1622
|
+
const found = field.options.find((o) => o.value === value);
|
|
1623
|
+
return found?.label ?? field.placeholder ?? placeholder;
|
|
1624
|
+
}, [field.options, field.placeholder, placeholder, value]);
|
|
1625
|
+
const close = useCallback(() => {
|
|
1626
|
+
setIsOpen(false);
|
|
1627
|
+
}, []);
|
|
1628
|
+
const toggle = useCallback(() => {
|
|
1629
|
+
setIsOpen((prev) => !prev);
|
|
1630
|
+
}, []);
|
|
1631
|
+
const select = useCallback(
|
|
1632
|
+
(next) => {
|
|
1633
|
+
onChange(next);
|
|
1634
|
+
setIsOpen(false);
|
|
1635
|
+
},
|
|
1636
|
+
[onChange]
|
|
1637
|
+
);
|
|
1638
|
+
return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: filterStyles.anchor, children: [
|
|
1639
|
+
/* @__PURE__ */ jsxs(
|
|
1640
|
+
Pressable,
|
|
1641
|
+
{
|
|
1642
|
+
accessibilityRole: "button",
|
|
1643
|
+
accessibilityLabel: field.label,
|
|
1644
|
+
accessibilityHint: field.accessibilityHint ?? dropdownHint,
|
|
1645
|
+
accessibilityState: { expanded: isOpen },
|
|
1646
|
+
"aria-expanded": isOpen,
|
|
1647
|
+
onPress: toggle,
|
|
1648
|
+
style: [filterStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surface }],
|
|
1649
|
+
testID: `${testID}-trigger`,
|
|
1650
|
+
children: [
|
|
1651
|
+
/* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [filterStyles.selectTriggerText, { color: value === "" ? colors.textSecondary : colors.text }], children: selectedLabel }),
|
|
1652
|
+
/* @__PURE__ */ jsx(Text, { "aria-hidden": true, style: [filterStyles.chevron, { color: colors.textSecondary }], children: isOpen ? CHEVRON_UP2 : CHEVRON_DOWN2 })
|
|
1653
|
+
]
|
|
1654
|
+
}
|
|
1655
|
+
),
|
|
1656
|
+
isOpen ? /* @__PURE__ */ jsx(
|
|
1657
|
+
AnchoredMenu,
|
|
1658
|
+
{
|
|
1659
|
+
options: field.options,
|
|
1660
|
+
selectedValue: value,
|
|
1661
|
+
onSelect: select,
|
|
1662
|
+
onDismiss: close,
|
|
1663
|
+
colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1664
|
+
optionHint,
|
|
1665
|
+
testID,
|
|
1666
|
+
anchorRef
|
|
1667
|
+
}
|
|
1668
|
+
) : null
|
|
1669
|
+
] });
|
|
1670
|
+
}
|
|
1671
|
+
function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
1672
|
+
const { theme } = useUi();
|
|
1673
|
+
const { colors } = theme;
|
|
1674
|
+
const isNumber = field.kind === "number";
|
|
1675
|
+
return /* @__PURE__ */ jsx(
|
|
1676
|
+
TextInput,
|
|
1677
|
+
{
|
|
1678
|
+
accessibilityLabel: field.label,
|
|
1679
|
+
accessibilityHint: field.accessibilityHint,
|
|
1680
|
+
keyboardType: isNumber ? "numeric" : "default",
|
|
1681
|
+
placeholder: field.placeholder,
|
|
1682
|
+
placeholderTextColor: colors.textSecondary,
|
|
1683
|
+
value,
|
|
1684
|
+
onChangeText: onChange,
|
|
1685
|
+
onSubmitEditing: onSubmit,
|
|
1686
|
+
style: [filterStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }],
|
|
1687
|
+
testID: `${field.testID ?? fieldTestID(barTestID, field.key)}-input`
|
|
1688
|
+
}
|
|
1689
|
+
);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// src/Filters/utils/suggest.ts
|
|
1693
|
+
var RANK_VALUE_EXACT = 0;
|
|
1694
|
+
var RANK_VALUE_PREFIX = 1;
|
|
1695
|
+
var RANK_LABEL_PREFIX = 2;
|
|
1696
|
+
var RANK_LABEL_CONTAINS = 3;
|
|
1697
|
+
var NO_MATCH = -1;
|
|
1698
|
+
function rankOf(option, needle) {
|
|
1699
|
+
const value = option.value.toLowerCase();
|
|
1700
|
+
const label = option.label.toLowerCase();
|
|
1701
|
+
if (value === needle) return RANK_VALUE_EXACT;
|
|
1702
|
+
if (value.startsWith(needle)) return RANK_VALUE_PREFIX;
|
|
1703
|
+
if (label.startsWith(needle)) return RANK_LABEL_PREFIX;
|
|
1704
|
+
if (label.includes(needle)) return RANK_LABEL_CONTAINS;
|
|
1705
|
+
return NO_MATCH;
|
|
1706
|
+
}
|
|
1707
|
+
function suggestOptions(options, query, minChars, limit) {
|
|
1708
|
+
const needle = query.trim().toLowerCase();
|
|
1709
|
+
if (needle.length < minChars) return [];
|
|
1710
|
+
const scored = [];
|
|
1711
|
+
for (const option of options) {
|
|
1712
|
+
const rank = rankOf(option, needle);
|
|
1713
|
+
if (rank !== NO_MATCH) scored.push({ option, rank });
|
|
1714
|
+
}
|
|
1715
|
+
scored.sort((a, b) => a.rank !== b.rank ? a.rank - b.rank : a.option.label.localeCompare(b.option.label));
|
|
1716
|
+
return scored.slice(0, limit).map((entry) => entry.option);
|
|
1717
|
+
}
|
|
1718
|
+
function isUnmatched(options, text) {
|
|
1719
|
+
const needle = text.trim().toLowerCase();
|
|
1720
|
+
if (needle === "") return false;
|
|
1721
|
+
return !options.some((o) => o.value.toLowerCase() === needle || o.label.toLowerCase() === needle);
|
|
1722
|
+
}
|
|
1723
|
+
var CLOSE_DELAY_MS = 140;
|
|
1724
|
+
function TypeaheadField({ field, barTestID, value, onChange, onSubmit, optionHint }) {
|
|
1725
|
+
const { theme } = useUi();
|
|
1726
|
+
const { colors, palette, semantic } = theme;
|
|
1727
|
+
const anchorRef = useRef(null);
|
|
1728
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
1729
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1730
|
+
const minChars = field.minChars ?? DEFAULT_TYPEAHEAD_MIN_CHARS;
|
|
1731
|
+
const maxSuggestions = field.maxSuggestions ?? DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
1732
|
+
const exactPick = useMemo(
|
|
1733
|
+
() => field.options.some((o) => o.label === value),
|
|
1734
|
+
[field.options, value]
|
|
1735
|
+
);
|
|
1736
|
+
const suggestions = useMemo(
|
|
1737
|
+
() => exactPick ? [] : suggestOptions(field.options, value, minChars, maxSuggestions),
|
|
1738
|
+
[exactPick, field.options, value, minChars, maxSuggestions]
|
|
1739
|
+
);
|
|
1740
|
+
const showMenu = isOpen && suggestions.length > 0;
|
|
1741
|
+
const handleChange = useCallback(
|
|
1742
|
+
(next) => {
|
|
1743
|
+
onChange(next);
|
|
1744
|
+
setIsOpen(true);
|
|
1745
|
+
},
|
|
1746
|
+
[onChange]
|
|
1747
|
+
);
|
|
1748
|
+
const pick = useCallback(
|
|
1749
|
+
(optionValue) => {
|
|
1750
|
+
const opt = field.options.find((o) => o.value === optionValue);
|
|
1751
|
+
onChange(opt?.label ?? optionValue);
|
|
1752
|
+
setIsOpen(false);
|
|
1753
|
+
},
|
|
1754
|
+
[field.options, onChange]
|
|
1755
|
+
);
|
|
1756
|
+
const handleBlur = useCallback(() => {
|
|
1757
|
+
setTimeout(() => setIsOpen(false), CLOSE_DELAY_MS);
|
|
1758
|
+
}, []);
|
|
1759
|
+
const handleSubmit = useCallback(() => {
|
|
1760
|
+
setIsOpen(false);
|
|
1761
|
+
onSubmit();
|
|
1762
|
+
}, [onSubmit]);
|
|
1763
|
+
const hasError = field.error !== void 0 && field.error !== "";
|
|
1764
|
+
return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: filterStyles.anchor, children: [
|
|
1765
|
+
/* @__PURE__ */ jsx(
|
|
1766
|
+
TextInput,
|
|
1767
|
+
{
|
|
1768
|
+
accessibilityLabel: field.label,
|
|
1769
|
+
accessibilityHint: field.accessibilityHint,
|
|
1770
|
+
autoCapitalize: "none",
|
|
1771
|
+
autoCorrect: false,
|
|
1772
|
+
placeholder: field.placeholder,
|
|
1773
|
+
placeholderTextColor: colors.textSecondary,
|
|
1774
|
+
spellCheck: false,
|
|
1775
|
+
value,
|
|
1776
|
+
onChangeText: handleChange,
|
|
1777
|
+
onFocus: () => setIsOpen(true),
|
|
1778
|
+
onBlur: handleBlur,
|
|
1779
|
+
onSubmitEditing: handleSubmit,
|
|
1780
|
+
style: [filterStyles.input, { borderColor: hasError ? semantic.error["500"] : colors.border, backgroundColor: colors.surface, color: colors.text }],
|
|
1781
|
+
testID: `${testID}-input`
|
|
1782
|
+
}
|
|
1783
|
+
),
|
|
1784
|
+
showMenu ? /* @__PURE__ */ jsx(
|
|
1785
|
+
AnchoredMenu,
|
|
1786
|
+
{
|
|
1787
|
+
options: suggestions,
|
|
1788
|
+
selectedValue: value,
|
|
1789
|
+
onSelect: pick,
|
|
1790
|
+
onDismiss: () => setIsOpen(false),
|
|
1791
|
+
colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1792
|
+
optionHint,
|
|
1793
|
+
testID,
|
|
1794
|
+
anchorRef
|
|
1795
|
+
}
|
|
1796
|
+
) : null,
|
|
1797
|
+
hasError ? /* @__PURE__ */ jsx(Text, { role: "alert", style: [filterStyles.error, { color: semantic.error["500"] }], testID: `${testID}-error`, children: field.error }) : null
|
|
1798
|
+
] });
|
|
1799
|
+
}
|
|
1800
|
+
var EMPTY_RANGE = { from: "", to: "" };
|
|
1801
|
+
function asString(value) {
|
|
1802
|
+
return typeof value === "string" ? value : "";
|
|
1803
|
+
}
|
|
1804
|
+
function asBool(value) {
|
|
1805
|
+
return value === true;
|
|
1806
|
+
}
|
|
1807
|
+
function asRange(value) {
|
|
1808
|
+
if (typeof value === "object" && value !== null && "from" in value && "to" in value) return value;
|
|
1809
|
+
return EMPTY_RANGE;
|
|
1810
|
+
}
|
|
1811
|
+
function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings, renderSelect }) {
|
|
1812
|
+
const raw = values[field.key];
|
|
1813
|
+
if (field.kind === "boolean") {
|
|
1814
|
+
return /* @__PURE__ */ jsx(BooleanField, { field, barTestID, value: asBool(raw), onChange: (v) => setField(field.key, v) });
|
|
1815
|
+
}
|
|
1816
|
+
const body = (() => {
|
|
1817
|
+
switch (field.kind) {
|
|
1818
|
+
case "select":
|
|
1819
|
+
if (renderSelect !== void 0) {
|
|
1820
|
+
return renderSelect({
|
|
1821
|
+
field,
|
|
1822
|
+
value: asString(raw),
|
|
1823
|
+
onChange: (v) => setField(field.key, v),
|
|
1824
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key)
|
|
1825
|
+
});
|
|
650
1826
|
}
|
|
651
|
-
|
|
652
|
-
|
|
1827
|
+
return /* @__PURE__ */ jsx(
|
|
1828
|
+
SelectField,
|
|
1829
|
+
{
|
|
1830
|
+
field,
|
|
1831
|
+
barTestID,
|
|
1832
|
+
value: asString(raw),
|
|
1833
|
+
onChange: (v) => setField(field.key, v),
|
|
1834
|
+
placeholder: strings.selectPlaceholder,
|
|
1835
|
+
dropdownHint: strings.dropdownHint,
|
|
1836
|
+
optionHint: strings.optionHint
|
|
1837
|
+
}
|
|
1838
|
+
);
|
|
1839
|
+
case "typeahead":
|
|
1840
|
+
return /* @__PURE__ */ jsx(
|
|
1841
|
+
TypeaheadField,
|
|
1842
|
+
{
|
|
1843
|
+
field,
|
|
1844
|
+
barTestID,
|
|
1845
|
+
value: asString(raw),
|
|
1846
|
+
onChange: (v) => setField(field.key, v),
|
|
1847
|
+
onSubmit,
|
|
1848
|
+
optionHint: strings.optionHint
|
|
1849
|
+
}
|
|
1850
|
+
);
|
|
1851
|
+
case "dateRange":
|
|
1852
|
+
return /* @__PURE__ */ jsx(
|
|
1853
|
+
DateRangeField,
|
|
1854
|
+
{
|
|
1855
|
+
field,
|
|
1856
|
+
barTestID,
|
|
1857
|
+
value: asRange(raw),
|
|
1858
|
+
onChange: (v) => setField(field.key, v),
|
|
1859
|
+
onSubmit,
|
|
1860
|
+
fromLabel: strings.fromLabel,
|
|
1861
|
+
toLabel: strings.toLabel
|
|
1862
|
+
}
|
|
1863
|
+
);
|
|
1864
|
+
default:
|
|
1865
|
+
return /* @__PURE__ */ jsx(
|
|
1866
|
+
TextField,
|
|
1867
|
+
{
|
|
1868
|
+
field,
|
|
1869
|
+
barTestID,
|
|
1870
|
+
value: asString(raw),
|
|
1871
|
+
onChange: (v) => setField(field.key, v),
|
|
1872
|
+
onSubmit
|
|
1873
|
+
}
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
})();
|
|
1877
|
+
return /* @__PURE__ */ jsx(FieldShell, { field, barTestID, children: body });
|
|
1878
|
+
}
|
|
1879
|
+
function Filters({
|
|
1880
|
+
fields,
|
|
1881
|
+
values,
|
|
1882
|
+
onChange,
|
|
1883
|
+
resultsCount,
|
|
1884
|
+
resultsLabel,
|
|
1885
|
+
onApply,
|
|
1886
|
+
applyLabel,
|
|
1887
|
+
applyHint,
|
|
1888
|
+
applyDisabled = false,
|
|
1889
|
+
onClear,
|
|
1890
|
+
clearLabel,
|
|
1891
|
+
clearHint,
|
|
1892
|
+
actions,
|
|
1893
|
+
selectPlaceholder,
|
|
1894
|
+
fromLabel,
|
|
1895
|
+
toLabel,
|
|
1896
|
+
renderSelect,
|
|
1897
|
+
styleOverrides,
|
|
1898
|
+
testID = FILTERS_TEST_ID
|
|
1899
|
+
}) {
|
|
1900
|
+
const { t } = useUi();
|
|
1901
|
+
const setField = useCallback(
|
|
1902
|
+
(key, value) => {
|
|
1903
|
+
onChange({ ...values, [key]: value });
|
|
1904
|
+
},
|
|
1905
|
+
[onChange, values]
|
|
1906
|
+
);
|
|
1907
|
+
const onSubmit = useCallback(() => {
|
|
1908
|
+
if (onApply !== void 0 && !applyDisabled) onApply();
|
|
1909
|
+
}, [onApply, applyDisabled]);
|
|
1910
|
+
const strings = useMemo(
|
|
1911
|
+
() => ({
|
|
1912
|
+
selectPlaceholder: selectPlaceholder ?? t(FILTERS_I18N.selectPlaceholder),
|
|
1913
|
+
dropdownHint: t(FILTERS_I18N.dropdownHint),
|
|
1914
|
+
optionHint: t(FILTERS_I18N.optionHint),
|
|
1915
|
+
fromLabel: fromLabel ?? t(FILTERS_I18N.from),
|
|
1916
|
+
toLabel: toLabel ?? t(FILTERS_I18N.to)
|
|
1917
|
+
}),
|
|
1918
|
+
[selectPlaceholder, fromLabel, toLabel, t]
|
|
1919
|
+
);
|
|
1920
|
+
const barActions = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1921
|
+
actions,
|
|
1922
|
+
onClear !== void 0 && /* @__PURE__ */ jsx(
|
|
1923
|
+
ActionButton,
|
|
1924
|
+
{
|
|
1925
|
+
label: clearLabel ?? t(FILTERS_I18N.clear),
|
|
1926
|
+
hint: clearHint ?? t(FILTERS_I18N.clearHint),
|
|
1927
|
+
tone: "ghost",
|
|
1928
|
+
onPress: onClear,
|
|
1929
|
+
testID: clearTestID(testID)
|
|
1930
|
+
}
|
|
1931
|
+
),
|
|
1932
|
+
onApply !== void 0 && /* @__PURE__ */ jsx(
|
|
1933
|
+
ActionButton,
|
|
1934
|
+
{
|
|
1935
|
+
label: applyLabel ?? t(FILTERS_I18N.apply),
|
|
1936
|
+
hint: applyHint ?? t(FILTERS_I18N.applyHint),
|
|
1937
|
+
tone: "primary",
|
|
1938
|
+
disabled: applyDisabled,
|
|
1939
|
+
onPress: onApply,
|
|
1940
|
+
testID: applyTestID(testID)
|
|
1941
|
+
}
|
|
1942
|
+
)
|
|
653
1943
|
] });
|
|
1944
|
+
const hasActions = actions !== void 0 || onClear !== void 0 || onApply !== void 0;
|
|
1945
|
+
return /* @__PURE__ */ jsx(
|
|
1946
|
+
FilterBar,
|
|
1947
|
+
{
|
|
1948
|
+
resultsCount,
|
|
1949
|
+
resultsLabel,
|
|
1950
|
+
actions: hasActions ? barActions : void 0,
|
|
1951
|
+
styleOverrides,
|
|
1952
|
+
testID,
|
|
1953
|
+
children: fields.map((field) => /* @__PURE__ */ jsx(
|
|
1954
|
+
FilterFieldView,
|
|
1955
|
+
{
|
|
1956
|
+
field,
|
|
1957
|
+
barTestID: testID,
|
|
1958
|
+
values,
|
|
1959
|
+
setField,
|
|
1960
|
+
onSubmit,
|
|
1961
|
+
strings,
|
|
1962
|
+
renderSelect
|
|
1963
|
+
},
|
|
1964
|
+
field.key
|
|
1965
|
+
))
|
|
1966
|
+
}
|
|
1967
|
+
);
|
|
1968
|
+
}
|
|
1969
|
+
function shallowEqual(a, b) {
|
|
1970
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
1971
|
+
}
|
|
1972
|
+
function useFilterDraft({ initial, onApply, onReset }) {
|
|
1973
|
+
const [draft, setDraft] = useState(initial);
|
|
1974
|
+
const [committed, setCommitted] = useState(initial);
|
|
1975
|
+
const setField = useCallback((key, value) => {
|
|
1976
|
+
setDraft((prev) => ({ ...prev, [key]: value }));
|
|
1977
|
+
}, []);
|
|
1978
|
+
const apply = useCallback(() => {
|
|
1979
|
+
setCommitted(draft);
|
|
1980
|
+
onApply?.(draft);
|
|
1981
|
+
}, [draft, onApply]);
|
|
1982
|
+
const reset = useCallback(() => {
|
|
1983
|
+
setDraft(initial);
|
|
1984
|
+
setCommitted(initial);
|
|
1985
|
+
onReset?.();
|
|
1986
|
+
}, [initial, onReset]);
|
|
1987
|
+
const dirty = useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
|
|
1988
|
+
return { draft, committed, setField, setDraft, apply, reset, dirty };
|
|
654
1989
|
}
|
|
655
1990
|
|
|
656
|
-
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FilterBar, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, rowDetailTestID, rowTestID };
|
|
1991
|
+
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, fieldTestID, isUnmatched, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, suggestOptions, useFilterDraft };
|
|
657
1992
|
//# sourceMappingURL=index.mjs.map
|
|
658
1993
|
//# sourceMappingURL=index.mjs.map
|