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