@dloizides/ui-tables 1.10.0 → 1.12.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 +84 -0
- package/README.md +102 -3
- package/dist/index.d.mts +308 -2
- package/dist/index.d.ts +308 -2
- package/dist/index.js +973 -142
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +932 -117
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,54 +1,16 @@
|
|
|
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');
|
|
7
7
|
var reactDom = require('react-dom');
|
|
8
8
|
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var React4__default = /*#__PURE__*/_interopDefault(React4);
|
|
12
|
+
|
|
9
13
|
// src/StatCard/StatCard.tsx
|
|
10
|
-
var CARD_PADDING = 16;
|
|
11
|
-
var CARD_BORDER_RADIUS = 12;
|
|
12
|
-
var CARD_BORDER_WIDTH = 1;
|
|
13
|
-
var LABEL_FONT_SIZE = 14;
|
|
14
|
-
var VALUE_FONT_SIZE = 28;
|
|
15
|
-
var VALUE_LINE_HEIGHT = 36;
|
|
16
|
-
var styles = reactNative.StyleSheet.create({
|
|
17
|
-
card: {
|
|
18
|
-
padding: CARD_PADDING,
|
|
19
|
-
borderRadius: CARD_BORDER_RADIUS,
|
|
20
|
-
borderWidth: CARD_BORDER_WIDTH
|
|
21
|
-
},
|
|
22
|
-
label: {
|
|
23
|
-
fontSize: LABEL_FONT_SIZE,
|
|
24
|
-
fontWeight: "500"
|
|
25
|
-
},
|
|
26
|
-
value: {
|
|
27
|
-
fontSize: VALUE_FONT_SIZE,
|
|
28
|
-
fontWeight: "700",
|
|
29
|
-
lineHeight: VALUE_LINE_HEIGHT
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
var StatCard = react.memo(({ label, value, testID }) => {
|
|
33
|
-
const { theme, t } = uiFeedback.useUi();
|
|
34
|
-
const { colors } = theme;
|
|
35
|
-
const formattedValue = value.toLocaleString();
|
|
36
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
37
|
-
reactNative.View,
|
|
38
|
-
{
|
|
39
|
-
accessibilityHint: t("analytics.statHint", label),
|
|
40
|
-
accessibilityLabel: t("analytics.statCardLabel", label, formattedValue),
|
|
41
|
-
accessibilityRole: "text",
|
|
42
|
-
style: [styles.card, { backgroundColor: colors.surface, borderColor: colors.border }],
|
|
43
|
-
testID,
|
|
44
|
-
children: [
|
|
45
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles.label, { color: colors.textSecondary }], children: label }),
|
|
46
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles.value, { color: colors.text }], children: formattedValue })
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
StatCard.displayName = "StatCard";
|
|
52
14
|
|
|
53
15
|
// src/DataTable/constants.ts
|
|
54
16
|
var CARD_STACK_BREAKPOINT = 640;
|
|
@@ -72,8 +34,10 @@ var TABLE_TEST_IDS = {
|
|
|
72
34
|
results: "ui-results",
|
|
73
35
|
pager: "ui-pager",
|
|
74
36
|
pagerInfo: "ui-pager-info",
|
|
37
|
+
pagerFirst: "ui-pager-first",
|
|
75
38
|
pagerPrev: "ui-pager-prev",
|
|
76
|
-
pagerNext: "ui-pager-next"
|
|
39
|
+
pagerNext: "ui-pager-next",
|
|
40
|
+
pagerLast: "ui-pager-last"
|
|
77
41
|
};
|
|
78
42
|
var rowTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowInfix}-${key}`;
|
|
79
43
|
var rowDetailTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowDetailInfix}-${key}`;
|
|
@@ -104,15 +68,81 @@ var TABLE_I18N = {
|
|
|
104
68
|
selectClearHint: "uiTables.select.clearHint",
|
|
105
69
|
results: "uiTables.results",
|
|
106
70
|
pagerInfo: "uiTables.pager.info",
|
|
71
|
+
pagerFirst: "uiTables.pager.first",
|
|
107
72
|
pagerPrev: "uiTables.pager.prev",
|
|
108
73
|
pagerNext: "uiTables.pager.next",
|
|
74
|
+
pagerLast: "uiTables.pager.last",
|
|
75
|
+
pagerFirstHint: "uiTables.pager.firstHint",
|
|
109
76
|
pagerPrevHint: "uiTables.pager.prevHint",
|
|
110
77
|
pagerNextHint: "uiTables.pager.nextHint",
|
|
78
|
+
pagerLastHint: "uiTables.pager.lastHint",
|
|
111
79
|
pagerRows: "uiTables.pager.rows",
|
|
112
80
|
pagerRowsOptionHint: "uiTables.pager.rowsOptionHint",
|
|
113
81
|
/** Accessible hint for the dropdown-variant rows-per-page trigger button. */
|
|
114
|
-
pagerRowsTriggerHint: "uiTables.pager.rowsTriggerHint"
|
|
82
|
+
pagerRowsTriggerHint: "uiTables.pager.rowsTriggerHint",
|
|
83
|
+
/**
|
|
84
|
+
* Accessible NAME of the rows-per-page control, e.g. "Rows per page, currently {{p1}}".
|
|
85
|
+
* Without it the control is announced as the bare number ("50"), which says nothing about
|
|
86
|
+
* what it does. Untranslated it degrades to that bare number — never to the raw key.
|
|
87
|
+
*/
|
|
88
|
+
pagerRowsTriggerLabel: "uiTables.pager.rowsTriggerLabel",
|
|
89
|
+
/**
|
|
90
|
+
* Accessible NAME of ONE rows-per-page choice, e.g. "Show {{p1}} rows per page". Used by
|
|
91
|
+
* BOTH the `dropdown` options and the default `pills`. Untranslated it degrades to the
|
|
92
|
+
* bare number — never to the raw key.
|
|
93
|
+
*/
|
|
94
|
+
pagerRowsOptionLabel: "uiTables.pager.rowsOptionLabel",
|
|
95
|
+
/**
|
|
96
|
+
* StatCard's accessible name, e.g. "{{p1}}: {{p2}}". Note the `analytics.` prefix: these
|
|
97
|
+
* two keys predate this map and were only ever inlined in StatCard.tsx, so apps deriving
|
|
98
|
+
* their required-key list from TABLE_I18N could not see them. Registered here UNCHANGED
|
|
99
|
+
* (renaming them would break every app that already defines them).
|
|
100
|
+
*/
|
|
101
|
+
statCardLabel: "analytics.statCardLabel",
|
|
102
|
+
statHint: "analytics.statHint"
|
|
115
103
|
};
|
|
104
|
+
var CARD_PADDING = 16;
|
|
105
|
+
var CARD_BORDER_RADIUS = 12;
|
|
106
|
+
var CARD_BORDER_WIDTH = 1;
|
|
107
|
+
var LABEL_FONT_SIZE = 14;
|
|
108
|
+
var VALUE_FONT_SIZE = 28;
|
|
109
|
+
var VALUE_LINE_HEIGHT = 36;
|
|
110
|
+
var styles = reactNative.StyleSheet.create({
|
|
111
|
+
card: {
|
|
112
|
+
padding: CARD_PADDING,
|
|
113
|
+
borderRadius: CARD_BORDER_RADIUS,
|
|
114
|
+
borderWidth: CARD_BORDER_WIDTH
|
|
115
|
+
},
|
|
116
|
+
label: {
|
|
117
|
+
fontSize: LABEL_FONT_SIZE,
|
|
118
|
+
fontWeight: "500"
|
|
119
|
+
},
|
|
120
|
+
value: {
|
|
121
|
+
fontSize: VALUE_FONT_SIZE,
|
|
122
|
+
fontWeight: "700",
|
|
123
|
+
lineHeight: VALUE_LINE_HEIGHT
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
var StatCard = React4.memo(({ label, value, testID }) => {
|
|
127
|
+
const { theme, t } = uiFeedback.useUi();
|
|
128
|
+
const { colors } = theme;
|
|
129
|
+
const formattedValue = value.toLocaleString();
|
|
130
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
131
|
+
reactNative.View,
|
|
132
|
+
{
|
|
133
|
+
accessibilityHint: t(TABLE_I18N.statHint, label),
|
|
134
|
+
accessibilityLabel: t(TABLE_I18N.statCardLabel, label, formattedValue),
|
|
135
|
+
accessibilityRole: "text",
|
|
136
|
+
style: [styles.card, { backgroundColor: colors.surface, borderColor: colors.border }],
|
|
137
|
+
testID,
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles.label, { color: colors.textSecondary }], children: label }),
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles.value, { color: colors.text }], children: formattedValue })
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
StatCard.displayName = "StatCard";
|
|
116
146
|
var BORDER_WIDTH = 1;
|
|
117
147
|
var BORDER_RADIUS = 12;
|
|
118
148
|
var COLUMN_GAP = 16;
|
|
@@ -625,21 +655,21 @@ var TAB_INDEX_ACTIVE = 0;
|
|
|
625
655
|
var TAB_INDEX_INACTIVE2 = -1;
|
|
626
656
|
var IS_WEB = reactNative.Platform.OS === "web";
|
|
627
657
|
function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
|
|
628
|
-
const [focusedKey, setFocusedKey] =
|
|
629
|
-
const nodes =
|
|
658
|
+
const [focusedKey, setFocusedKey] = React4.useState(void 0);
|
|
659
|
+
const nodes = React4.useRef(/* @__PURE__ */ new Map());
|
|
630
660
|
const tabbableKey = enabled ? resolveTabbableKey(rowKeys, focusedKey) : void 0;
|
|
631
|
-
const registerRow =
|
|
661
|
+
const registerRow = React4.useCallback((key, node) => {
|
|
632
662
|
if (node === null || node === void 0) {
|
|
633
663
|
nodes.current.delete(key);
|
|
634
664
|
return;
|
|
635
665
|
}
|
|
636
666
|
nodes.current.set(key, node);
|
|
637
667
|
}, []);
|
|
638
|
-
const focusRow =
|
|
668
|
+
const focusRow = React4.useCallback((key) => {
|
|
639
669
|
setFocusedKey(key);
|
|
640
670
|
nodes.current.get(key)?.focus?.();
|
|
641
671
|
}, []);
|
|
642
|
-
const handleKey =
|
|
672
|
+
const handleKey = React4.useCallback(
|
|
643
673
|
(event, key) => {
|
|
644
674
|
const action = toRowNavAction(event.key);
|
|
645
675
|
if (action === void 0) return;
|
|
@@ -664,18 +694,18 @@ function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
|
|
|
664
694
|
},
|
|
665
695
|
[rowKeys, onToggleKey, onActivateKey, focusRow]
|
|
666
696
|
);
|
|
667
|
-
const keyDownFor =
|
|
697
|
+
const keyDownFor = React4.useCallback(
|
|
668
698
|
(key) => {
|
|
669
699
|
if (!enabled || !IS_WEB) return void 0;
|
|
670
700
|
return (event) => handleKey(event, key);
|
|
671
701
|
},
|
|
672
702
|
[enabled, handleKey]
|
|
673
703
|
);
|
|
674
|
-
const tabIndexFor =
|
|
704
|
+
const tabIndexFor = React4.useCallback(
|
|
675
705
|
(key) => key === tabbableKey ? TAB_INDEX_ACTIVE : TAB_INDEX_INACTIVE2,
|
|
676
706
|
[tabbableKey]
|
|
677
707
|
);
|
|
678
|
-
const onRowFocus =
|
|
708
|
+
const onRowFocus = React4.useCallback((key) => setFocusedKey(key), []);
|
|
679
709
|
return { tabIndexFor, registerRow, onRowFocus, keyDownFor };
|
|
680
710
|
}
|
|
681
711
|
|
|
@@ -727,20 +757,20 @@ function useTableSelection({
|
|
|
727
757
|
const selected = selectedRowKeys ?? NO_KEYS;
|
|
728
758
|
const allMatching = allMatchingSelected ?? false;
|
|
729
759
|
const matching = matchingCount ?? NO_MATCHES;
|
|
730
|
-
const pageHeaderState =
|
|
760
|
+
const pageHeaderState = React4.useMemo(
|
|
731
761
|
() => resolveHeaderCheckboxState(selected, pageKeys),
|
|
732
762
|
[selected, pageKeys]
|
|
733
763
|
);
|
|
734
764
|
const headerState = allMatching ? "all" /* All */ : pageHeaderState;
|
|
735
|
-
const bannerMode =
|
|
765
|
+
const bannerMode = React4.useMemo(
|
|
736
766
|
() => onSelectAllMatchingChange === void 0 ? "hidden" /* Hidden */ : resolveSelectAllBannerMode(pageHeaderState, allMatching, pageKeys.length, matching),
|
|
737
767
|
[onSelectAllMatchingChange, pageHeaderState, allMatching, pageKeys.length, matching]
|
|
738
768
|
);
|
|
739
|
-
const isSelected =
|
|
769
|
+
const isSelected = React4.useCallback(
|
|
740
770
|
(key) => isRowSelected(selected, key, allMatching),
|
|
741
771
|
[selected, allMatching]
|
|
742
772
|
);
|
|
743
|
-
const toggleRow =
|
|
773
|
+
const toggleRow = React4.useCallback(
|
|
744
774
|
(key) => {
|
|
745
775
|
if (allMatching) {
|
|
746
776
|
onSelectAllMatchingChange?.(false);
|
|
@@ -751,7 +781,7 @@ function useTableSelection({
|
|
|
751
781
|
},
|
|
752
782
|
[allMatching, onSelectAllMatchingChange, onSelectionChange, pageKeys, selected]
|
|
753
783
|
);
|
|
754
|
-
const toggleAll =
|
|
784
|
+
const toggleAll = React4.useCallback(() => {
|
|
755
785
|
if (allMatching) {
|
|
756
786
|
onSelectAllMatchingChange?.(false);
|
|
757
787
|
onSelectionChange?.(NO_KEYS);
|
|
@@ -759,7 +789,7 @@ function useTableSelection({
|
|
|
759
789
|
}
|
|
760
790
|
onSelectionChange?.(toggleAllOnPage(selected, pageKeys));
|
|
761
791
|
}, [allMatching, onSelectAllMatchingChange, onSelectionChange, selected, pageKeys]);
|
|
762
|
-
const toggleAllMatching =
|
|
792
|
+
const toggleAllMatching = React4.useCallback(() => {
|
|
763
793
|
const next = !allMatching;
|
|
764
794
|
onSelectAllMatchingChange?.(next);
|
|
765
795
|
if (!next) onSelectionChange?.(NO_KEYS);
|
|
@@ -800,9 +830,9 @@ function DataTable(props) {
|
|
|
800
830
|
const stacked = width < stackBreakpoint;
|
|
801
831
|
const frame = { backgroundColor: colors.surface, borderColor: colors.border };
|
|
802
832
|
const interactive = onRowPress !== void 0;
|
|
803
|
-
const [hoveredKey, setHoveredKey] =
|
|
833
|
+
const [hoveredKey, setHoveredKey] = React4.useState(void 0);
|
|
804
834
|
const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
|
|
805
|
-
const rowKeys =
|
|
835
|
+
const rowKeys = React4.useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
|
|
806
836
|
const selection = useTableSelection({
|
|
807
837
|
pageKeys: rowKeys,
|
|
808
838
|
selectedRowKeys,
|
|
@@ -811,7 +841,7 @@ function DataTable(props) {
|
|
|
811
841
|
allMatchingSelected,
|
|
812
842
|
onSelectAllMatchingChange
|
|
813
843
|
});
|
|
814
|
-
const activateKey =
|
|
844
|
+
const activateKey = React4.useCallback(
|
|
815
845
|
(key) => {
|
|
816
846
|
const row = rows[rowKeys.indexOf(key)];
|
|
817
847
|
if (row !== void 0) onRowPress?.(row);
|
|
@@ -824,7 +854,7 @@ function DataTable(props) {
|
|
|
824
854
|
onToggleKey: selection.selectable ? selection.toggleRow : void 0,
|
|
825
855
|
onActivateKey: interactive ? activateKey : void 0
|
|
826
856
|
});
|
|
827
|
-
const rowBackground =
|
|
857
|
+
const rowBackground = React4.useCallback(
|
|
828
858
|
(row, index) => {
|
|
829
859
|
const tint = rowTint?.(row);
|
|
830
860
|
if (tint) return tint;
|
|
@@ -947,6 +977,12 @@ function FilterBar({
|
|
|
947
977
|
!!actions && /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [chromeStyles.filtersActions, o?.filtersActions], children: actions })
|
|
948
978
|
] });
|
|
949
979
|
}
|
|
980
|
+
|
|
981
|
+
// src/accessibleName.ts
|
|
982
|
+
function accessibleName(translated, key, fallback) {
|
|
983
|
+
const isUntranslated = translated === key || translated === "";
|
|
984
|
+
return isUntranslated ? fallback : translated;
|
|
985
|
+
}
|
|
950
986
|
var CHEVRON_DOWN = "\u25BE";
|
|
951
987
|
var CHEVRON_UP = "\u25B4";
|
|
952
988
|
var IS_WEB2 = reactNative.Platform.OS === "web";
|
|
@@ -969,8 +1005,8 @@ function buildWebFixedStyle(rect, viewportWidth) {
|
|
|
969
1005
|
};
|
|
970
1006
|
}
|
|
971
1007
|
function useTriggerRect(anchorRef, isOpen) {
|
|
972
|
-
const [rect, setRect] =
|
|
973
|
-
|
|
1008
|
+
const [rect, setRect] = React4.useState(null);
|
|
1009
|
+
React4.useLayoutEffect(() => {
|
|
974
1010
|
if (!IS_WEB2 || !isOpen) return void 0;
|
|
975
1011
|
const measure = () => {
|
|
976
1012
|
setRect(readTriggerRect(anchorRef));
|
|
@@ -986,7 +1022,7 @@ function useTriggerRect(anchorRef, isOpen) {
|
|
|
986
1022
|
return rect;
|
|
987
1023
|
}
|
|
988
1024
|
function useDismissOnOutside(anchorRef, menuRef, isOpen, onClose) {
|
|
989
|
-
|
|
1025
|
+
React4.useEffect(() => {
|
|
990
1026
|
if (!IS_WEB2 || !isOpen) return void 0;
|
|
991
1027
|
const onMouseDown = (event) => {
|
|
992
1028
|
const anchorNode = anchorRef.current;
|
|
@@ -1012,6 +1048,8 @@ function SizeDropdown({
|
|
|
1012
1048
|
pageSizeOptions,
|
|
1013
1049
|
onPageSizeChange,
|
|
1014
1050
|
testID,
|
|
1051
|
+
triggerLabel,
|
|
1052
|
+
getOptionLabel,
|
|
1015
1053
|
triggerHint,
|
|
1016
1054
|
optionHint,
|
|
1017
1055
|
textColor,
|
|
@@ -1022,16 +1060,16 @@ function SizeDropdown({
|
|
|
1022
1060
|
triggerStyle,
|
|
1023
1061
|
triggerTextStyle
|
|
1024
1062
|
}) {
|
|
1025
|
-
const anchorRef =
|
|
1026
|
-
const menuRef =
|
|
1027
|
-
const [isOpen, setIsOpen] =
|
|
1028
|
-
const close =
|
|
1063
|
+
const anchorRef = React4.useRef(null);
|
|
1064
|
+
const menuRef = React4.useRef(null);
|
|
1065
|
+
const [isOpen, setIsOpen] = React4.useState(false);
|
|
1066
|
+
const close = React4.useCallback(() => {
|
|
1029
1067
|
setIsOpen(false);
|
|
1030
1068
|
}, []);
|
|
1031
|
-
const toggle =
|
|
1069
|
+
const toggle = React4.useCallback(() => {
|
|
1032
1070
|
setIsOpen((prev) => !prev);
|
|
1033
1071
|
}, []);
|
|
1034
|
-
const select =
|
|
1072
|
+
const select = React4.useCallback(
|
|
1035
1073
|
(size) => {
|
|
1036
1074
|
onPageSizeChange(size);
|
|
1037
1075
|
setIsOpen(false);
|
|
@@ -1055,7 +1093,7 @@ function SizeDropdown({
|
|
|
1055
1093
|
{
|
|
1056
1094
|
testID: `${testID}-size-${size}`,
|
|
1057
1095
|
accessibilityRole: "menuitem",
|
|
1058
|
-
accessibilityLabel:
|
|
1096
|
+
accessibilityLabel: getOptionLabel(size),
|
|
1059
1097
|
accessibilityHint: optionHint,
|
|
1060
1098
|
accessibilityState: { selected: active },
|
|
1061
1099
|
onPress: () => select(size),
|
|
@@ -1073,7 +1111,7 @@ function SizeDropdown({
|
|
|
1073
1111
|
{
|
|
1074
1112
|
testID: `${testID}-size-trigger`,
|
|
1075
1113
|
accessibilityRole: "button",
|
|
1076
|
-
accessibilityLabel:
|
|
1114
|
+
accessibilityLabel: triggerLabel,
|
|
1077
1115
|
accessibilityHint: triggerHint,
|
|
1078
1116
|
accessibilityState: { expanded: isOpen },
|
|
1079
1117
|
"aria-expanded": isOpen,
|
|
@@ -1089,11 +1127,9 @@ function SizeDropdown({
|
|
|
1089
1127
|
] });
|
|
1090
1128
|
}
|
|
1091
1129
|
var FIRST_PAGE = 1;
|
|
1092
|
-
var EN_DASH = "\u2013";
|
|
1093
1130
|
var DISABLED_OPACITY = 0.4;
|
|
1094
1131
|
var FULL_OPACITY = 1;
|
|
1095
1132
|
var TRANSPARENT2 = "transparent";
|
|
1096
|
-
var BOLD = "700";
|
|
1097
1133
|
var PAGER_HIT_SLOP = { top: 10, bottom: 10 };
|
|
1098
1134
|
function NavButton({ label, hint, disabled, onPress, color, border, testID, styleOverrides: o }) {
|
|
1099
1135
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1112,6 +1148,146 @@ function NavButton({ label, hint, disabled, onPress, color, border, testID, styl
|
|
|
1112
1148
|
}
|
|
1113
1149
|
);
|
|
1114
1150
|
}
|
|
1151
|
+
function rowsTriggerLabel(t, pageSize) {
|
|
1152
|
+
const size = String(pageSize);
|
|
1153
|
+
return accessibleName(t(TABLE_I18N.pagerRowsTriggerLabel, size), TABLE_I18N.pagerRowsTriggerLabel, size);
|
|
1154
|
+
}
|
|
1155
|
+
function rowsOptionLabel(t, optionSize) {
|
|
1156
|
+
const size = String(optionSize);
|
|
1157
|
+
return accessibleName(t(TABLE_I18N.pagerRowsOptionLabel, size), TABLE_I18N.pagerRowsOptionLabel, size);
|
|
1158
|
+
}
|
|
1159
|
+
function RowsControl({ pageSize, pageSizeOptions, onPageSizeChange, isDropdown, testID, styleOverrides: o }) {
|
|
1160
|
+
const { theme, t } = uiFeedback.useUi();
|
|
1161
|
+
const { colors, palette } = theme;
|
|
1162
|
+
const brand = palette.primary["500"];
|
|
1163
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1164
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [isDropdown ? chromeStyles.pagerRowsLabelPlain : chromeStyles.pagerRowsLabel, { color: colors.textSecondary }, o?.pagerRowsLabel], children: t(TABLE_I18N.pagerRows) }),
|
|
1165
|
+
isDropdown ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1166
|
+
SizeDropdown,
|
|
1167
|
+
{
|
|
1168
|
+
pageSize,
|
|
1169
|
+
pageSizeOptions,
|
|
1170
|
+
onPageSizeChange,
|
|
1171
|
+
testID,
|
|
1172
|
+
triggerLabel: rowsTriggerLabel(t, pageSize),
|
|
1173
|
+
getOptionLabel: (size) => rowsOptionLabel(t, size),
|
|
1174
|
+
triggerHint: t(TABLE_I18N.pagerRowsTriggerHint),
|
|
1175
|
+
optionHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1176
|
+
textColor: colors.text,
|
|
1177
|
+
mutedColor: colors.textSecondary,
|
|
1178
|
+
borderColor: colors.border,
|
|
1179
|
+
surfaceColor: colors.surface,
|
|
1180
|
+
brandColor: brand,
|
|
1181
|
+
triggerStyle: o?.sizePill,
|
|
1182
|
+
triggerTextStyle: o?.sizePillText
|
|
1183
|
+
}
|
|
1184
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [chromeStyles.sizeGroup, o?.sizeGroup], children: pageSizeOptions.map((size) => {
|
|
1185
|
+
const active = size === pageSize;
|
|
1186
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1187
|
+
reactNative.Pressable,
|
|
1188
|
+
{
|
|
1189
|
+
testID: `${testID}-size-${size}`,
|
|
1190
|
+
accessibilityRole: "button",
|
|
1191
|
+
accessibilityLabel: rowsOptionLabel(t, size),
|
|
1192
|
+
accessibilityHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1193
|
+
accessibilityState: { selected: active },
|
|
1194
|
+
hitSlop: PAGER_HIT_SLOP,
|
|
1195
|
+
onPress: () => onPageSizeChange(size),
|
|
1196
|
+
style: [chromeStyles.sizePill, { borderColor: active ? brand : colors.border, backgroundColor: active ? brand : TRANSPARENT2 }, o?.sizePill],
|
|
1197
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [chromeStyles.sizePillText, { color: active ? colors.surface : colors.textSecondary }, o?.sizePillText], children: size })
|
|
1198
|
+
},
|
|
1199
|
+
size
|
|
1200
|
+
);
|
|
1201
|
+
}) })
|
|
1202
|
+
] });
|
|
1203
|
+
}
|
|
1204
|
+
function PagerNav({
|
|
1205
|
+
pageSize,
|
|
1206
|
+
pageSizeOptions,
|
|
1207
|
+
onPageSizeChange,
|
|
1208
|
+
onPageChange,
|
|
1209
|
+
safePage,
|
|
1210
|
+
lastPage,
|
|
1211
|
+
isCompact,
|
|
1212
|
+
isDropdown,
|
|
1213
|
+
showFirstLast,
|
|
1214
|
+
testID,
|
|
1215
|
+
styleOverrides: o
|
|
1216
|
+
}) {
|
|
1217
|
+
const { theme, t } = uiFeedback.useUi();
|
|
1218
|
+
const { colors } = theme;
|
|
1219
|
+
const atFirst = safePage <= FIRST_PAGE;
|
|
1220
|
+
const atLast = safePage >= lastPage;
|
|
1221
|
+
const showJumps = showFirstLast && !isCompact;
|
|
1222
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [chromeStyles.pagerNav, o?.pagerNav], children: [
|
|
1223
|
+
!isCompact && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1224
|
+
RowsControl,
|
|
1225
|
+
{
|
|
1226
|
+
pageSize,
|
|
1227
|
+
pageSizeOptions,
|
|
1228
|
+
onPageSizeChange,
|
|
1229
|
+
isDropdown,
|
|
1230
|
+
testID,
|
|
1231
|
+
styleOverrides: o
|
|
1232
|
+
}
|
|
1233
|
+
),
|
|
1234
|
+
showJumps && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1235
|
+
NavButton,
|
|
1236
|
+
{
|
|
1237
|
+
label: t(TABLE_I18N.pagerFirst),
|
|
1238
|
+
hint: t(TABLE_I18N.pagerFirstHint),
|
|
1239
|
+
disabled: atFirst,
|
|
1240
|
+
onPress: () => onPageChange(FIRST_PAGE),
|
|
1241
|
+
color: colors.text,
|
|
1242
|
+
border: colors.border,
|
|
1243
|
+
styleOverrides: o,
|
|
1244
|
+
testID: TABLE_TEST_IDS.pagerFirst
|
|
1245
|
+
}
|
|
1246
|
+
),
|
|
1247
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1248
|
+
NavButton,
|
|
1249
|
+
{
|
|
1250
|
+
label: t(TABLE_I18N.pagerPrev),
|
|
1251
|
+
hint: t(TABLE_I18N.pagerPrevHint),
|
|
1252
|
+
disabled: atFirst,
|
|
1253
|
+
onPress: () => onPageChange(safePage - 1),
|
|
1254
|
+
color: colors.text,
|
|
1255
|
+
border: colors.border,
|
|
1256
|
+
styleOverrides: o,
|
|
1257
|
+
testID: TABLE_TEST_IDS.pagerPrev
|
|
1258
|
+
}
|
|
1259
|
+
),
|
|
1260
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1261
|
+
NavButton,
|
|
1262
|
+
{
|
|
1263
|
+
label: t(TABLE_I18N.pagerNext),
|
|
1264
|
+
hint: t(TABLE_I18N.pagerNextHint),
|
|
1265
|
+
disabled: atLast,
|
|
1266
|
+
onPress: () => onPageChange(safePage + 1),
|
|
1267
|
+
color: colors.text,
|
|
1268
|
+
border: colors.border,
|
|
1269
|
+
styleOverrides: o,
|
|
1270
|
+
testID: TABLE_TEST_IDS.pagerNext
|
|
1271
|
+
}
|
|
1272
|
+
),
|
|
1273
|
+
showJumps && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1274
|
+
NavButton,
|
|
1275
|
+
{
|
|
1276
|
+
label: t(TABLE_I18N.pagerLast),
|
|
1277
|
+
hint: t(TABLE_I18N.pagerLastHint),
|
|
1278
|
+
disabled: atLast,
|
|
1279
|
+
onPress: () => onPageChange(lastPage),
|
|
1280
|
+
color: colors.text,
|
|
1281
|
+
border: colors.border,
|
|
1282
|
+
styleOverrides: o,
|
|
1283
|
+
testID: TABLE_TEST_IDS.pagerLast
|
|
1284
|
+
}
|
|
1285
|
+
)
|
|
1286
|
+
] });
|
|
1287
|
+
}
|
|
1288
|
+
var FIRST_PAGE2 = 1;
|
|
1289
|
+
var EN_DASH = "\u2013";
|
|
1290
|
+
var BOLD = "700";
|
|
1115
1291
|
function Pager({
|
|
1116
1292
|
page,
|
|
1117
1293
|
pageSize,
|
|
@@ -1121,24 +1297,30 @@ function Pager({
|
|
|
1121
1297
|
pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS,
|
|
1122
1298
|
rowsVariant = "pills",
|
|
1123
1299
|
unitLabel,
|
|
1300
|
+
unitLabelSingular,
|
|
1301
|
+
showFirstLast = false,
|
|
1302
|
+
responsive = false,
|
|
1303
|
+
stackBreakpoint = CARD_STACK_BREAKPOINT,
|
|
1124
1304
|
infoPrefix,
|
|
1125
1305
|
boldNumbers = false,
|
|
1126
1306
|
styleOverrides: o,
|
|
1127
1307
|
testID = TABLE_TEST_IDS.pager
|
|
1128
1308
|
}) {
|
|
1129
1309
|
const { theme, t } = uiFeedback.useUi();
|
|
1130
|
-
const { colors
|
|
1131
|
-
const
|
|
1310
|
+
const { colors } = theme;
|
|
1311
|
+
const { width } = reactNative.useWindowDimensions();
|
|
1132
1312
|
const isDropdown = rowsVariant === "dropdown";
|
|
1133
|
-
const
|
|
1134
|
-
const
|
|
1313
|
+
const isCompact = responsive && width < stackBreakpoint;
|
|
1314
|
+
const lastPage = Math.max(FIRST_PAGE2, Math.ceil(total / pageSize));
|
|
1315
|
+
const safePage = Math.min(Math.max(page, FIRST_PAGE2), lastPage);
|
|
1135
1316
|
const from = total === 0 ? 0 : (safePage - 1) * pageSize + 1;
|
|
1136
1317
|
const to = Math.min(safePage * pageSize, total);
|
|
1137
1318
|
const hasUnit = unitLabel !== void 0 && unitLabel !== "";
|
|
1319
|
+
const resolvedUnit = total === 1 && unitLabelSingular !== void 0 && unitLabelSingular !== "" ? unitLabelSingular : unitLabel;
|
|
1138
1320
|
const hasPrefix = infoPrefix !== void 0 && infoPrefix !== "";
|
|
1139
1321
|
const prefix = hasPrefix ? `${infoPrefix} ` : "";
|
|
1140
1322
|
const ofWord = t(TABLE_I18N.pagerInfo);
|
|
1141
|
-
const unitSuffix = hasUnit ? ` ${
|
|
1323
|
+
const unitSuffix = hasUnit ? ` ${resolvedUnit}` : "";
|
|
1142
1324
|
const count = `${from.toLocaleString()}${EN_DASH}${to.toLocaleString()} ${ofWord} ${total.toLocaleString()}`;
|
|
1143
1325
|
const info = `${prefix}${count}${unitSuffix}`;
|
|
1144
1326
|
const boldStyle = { color: colors.text, fontWeight: BOLD };
|
|
@@ -1152,90 +1334,739 @@ function Pager({
|
|
|
1152
1334
|
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: boldStyle, children: total.toLocaleString() }),
|
|
1153
1335
|
unitSuffix
|
|
1154
1336
|
] }) : info }),
|
|
1155
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1337
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1338
|
+
PagerNav,
|
|
1339
|
+
{
|
|
1340
|
+
pageSize,
|
|
1341
|
+
pageSizeOptions,
|
|
1342
|
+
onPageSizeChange,
|
|
1343
|
+
onPageChange,
|
|
1344
|
+
safePage,
|
|
1345
|
+
lastPage,
|
|
1346
|
+
isCompact,
|
|
1347
|
+
isDropdown,
|
|
1348
|
+
showFirstLast,
|
|
1349
|
+
testID,
|
|
1350
|
+
styleOverrides: o
|
|
1351
|
+
}
|
|
1352
|
+
)
|
|
1353
|
+
] });
|
|
1354
|
+
}
|
|
1355
|
+
var FIELD_GAP = 4;
|
|
1356
|
+
var LABEL_FONT = 11;
|
|
1357
|
+
var LABEL_LETTER_SPACING2 = 0.4;
|
|
1358
|
+
var INPUT_RADIUS = 8;
|
|
1359
|
+
var INPUT_PAD_H = 12;
|
|
1360
|
+
var INPUT_PAD_V = 10;
|
|
1361
|
+
var INPUT_FONT = 14;
|
|
1362
|
+
var INPUT_BORDER = 1;
|
|
1363
|
+
var DATE_ROW_GAP = 8;
|
|
1364
|
+
var CHEVRON_FONT2 = 10;
|
|
1365
|
+
var MENU_TOP_GAP3 = 4;
|
|
1366
|
+
var MENU_RADIUS = 8;
|
|
1367
|
+
var MENU_PAD_V2 = 4;
|
|
1368
|
+
var MENU_OPT_PAD_H = 12;
|
|
1369
|
+
var MENU_OPT_PAD_V2 = 8;
|
|
1370
|
+
var MENU_MIN_WIDTH2 = 160;
|
|
1371
|
+
var MENU_MAX_HEIGHT = 260;
|
|
1372
|
+
var MENU_Z = 1e3;
|
|
1373
|
+
var MENU_ELEVATION2 = 8;
|
|
1374
|
+
var MENU_BOX_SHADOW2 = "0px 2px 8px rgba(0, 0, 0, 0.15)";
|
|
1375
|
+
var OPTION_FONT = 14;
|
|
1376
|
+
var ERROR_FONT = 12;
|
|
1377
|
+
var ERROR_GAP = 3;
|
|
1378
|
+
var SWITCH_ROW_GAP = 8;
|
|
1379
|
+
var ACTION_PAD_H = 14;
|
|
1380
|
+
var ACTION_PAD_V = 8;
|
|
1381
|
+
var ACTION_RADIUS = 8;
|
|
1382
|
+
var ACTION_FONT = 13;
|
|
1383
|
+
var filterStyles = reactNative.StyleSheet.create({
|
|
1384
|
+
field: { gap: FIELD_GAP },
|
|
1385
|
+
label: { fontSize: LABEL_FONT, fontWeight: "700", letterSpacing: LABEL_LETTER_SPACING2, textTransform: "uppercase" },
|
|
1386
|
+
input: {
|
|
1387
|
+
borderWidth: INPUT_BORDER,
|
|
1388
|
+
borderRadius: INPUT_RADIUS,
|
|
1389
|
+
paddingHorizontal: INPUT_PAD_H,
|
|
1390
|
+
paddingVertical: INPUT_PAD_V,
|
|
1391
|
+
fontSize: INPUT_FONT
|
|
1392
|
+
},
|
|
1393
|
+
/** The select trigger: a bordered field box matching the text inputs + a chevron. */
|
|
1394
|
+
selectTrigger: {
|
|
1395
|
+
flexDirection: "row",
|
|
1396
|
+
alignItems: "center",
|
|
1397
|
+
justifyContent: "space-between",
|
|
1398
|
+
gap: DATE_ROW_GAP,
|
|
1399
|
+
borderWidth: INPUT_BORDER,
|
|
1400
|
+
borderRadius: INPUT_RADIUS,
|
|
1401
|
+
paddingHorizontal: INPUT_PAD_H,
|
|
1402
|
+
paddingVertical: INPUT_PAD_V
|
|
1403
|
+
},
|
|
1404
|
+
selectTriggerText: { fontSize: INPUT_FONT, flexShrink: 1 },
|
|
1405
|
+
chevron: { fontSize: CHEVRON_FONT2 },
|
|
1406
|
+
dateRow: { flexDirection: "row", gap: DATE_ROW_GAP },
|
|
1407
|
+
dateCol: { gap: FIELD_GAP, flex: 1 },
|
|
1408
|
+
subLabel: { fontSize: LABEL_FONT, letterSpacing: LABEL_LETTER_SPACING2 },
|
|
1409
|
+
anchor: { position: "relative" },
|
|
1410
|
+
menu: {
|
|
1411
|
+
position: "absolute",
|
|
1412
|
+
top: "100%",
|
|
1413
|
+
left: 0,
|
|
1414
|
+
marginTop: MENU_TOP_GAP3,
|
|
1415
|
+
minWidth: MENU_MIN_WIDTH2,
|
|
1416
|
+
maxHeight: MENU_MAX_HEIGHT,
|
|
1417
|
+
borderWidth: INPUT_BORDER,
|
|
1418
|
+
borderRadius: MENU_RADIUS,
|
|
1419
|
+
paddingVertical: MENU_PAD_V2,
|
|
1420
|
+
zIndex: MENU_Z,
|
|
1421
|
+
boxShadow: MENU_BOX_SHADOW2,
|
|
1422
|
+
elevation: MENU_ELEVATION2,
|
|
1423
|
+
overflow: "hidden"
|
|
1424
|
+
},
|
|
1425
|
+
option: { paddingHorizontal: MENU_OPT_PAD_H, paddingVertical: MENU_OPT_PAD_V2 },
|
|
1426
|
+
optionText: { fontSize: OPTION_FONT },
|
|
1427
|
+
error: { fontSize: ERROR_FONT, marginTop: ERROR_GAP },
|
|
1428
|
+
switchRow: { flexDirection: "row", alignItems: "center", gap: SWITCH_ROW_GAP, paddingVertical: FIELD_GAP },
|
|
1429
|
+
action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth: INPUT_BORDER },
|
|
1430
|
+
actionText: { fontSize: ACTION_FONT, fontWeight: "600" }
|
|
1431
|
+
});
|
|
1432
|
+
var FILTER_HIT_SLOP = { top: 8, bottom: 8 };
|
|
1433
|
+
var DISABLED_OPACITY2 = 0.4;
|
|
1434
|
+
var FULL_OPACITY2 = 1;
|
|
1435
|
+
var TRANSPARENT3 = "transparent";
|
|
1436
|
+
function ActionButton({ label, hint, tone, disabled = false, onPress, testID }) {
|
|
1437
|
+
const { theme } = uiFeedback.useUi();
|
|
1438
|
+
const { colors, palette } = theme;
|
|
1439
|
+
const isPrimary = tone === "primary";
|
|
1440
|
+
const brand = palette.primary["500"];
|
|
1441
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1442
|
+
reactNative.Pressable,
|
|
1443
|
+
{
|
|
1444
|
+
accessibilityRole: "button",
|
|
1445
|
+
accessibilityLabel: label,
|
|
1446
|
+
accessibilityHint: hint,
|
|
1447
|
+
accessibilityState: { disabled },
|
|
1448
|
+
disabled,
|
|
1449
|
+
hitSlop: FILTER_HIT_SLOP,
|
|
1450
|
+
onPress,
|
|
1451
|
+
style: [
|
|
1452
|
+
filterStyles.action,
|
|
1165
1453
|
{
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
testID,
|
|
1170
|
-
triggerHint: t(TABLE_I18N.pagerRowsTriggerHint),
|
|
1171
|
-
optionHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1172
|
-
textColor: colors.text,
|
|
1173
|
-
mutedColor: colors.textSecondary,
|
|
1174
|
-
borderColor: colors.border,
|
|
1175
|
-
surfaceColor: colors.surface,
|
|
1176
|
-
brandColor: brand,
|
|
1177
|
-
triggerStyle: o?.sizePill,
|
|
1178
|
-
triggerTextStyle: o?.sizePillText
|
|
1454
|
+
borderColor: isPrimary ? brand : colors.border,
|
|
1455
|
+
backgroundColor: isPrimary ? brand : TRANSPARENT3,
|
|
1456
|
+
opacity: disabled ? DISABLED_OPACITY2 : FULL_OPACITY2
|
|
1179
1457
|
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1458
|
+
],
|
|
1459
|
+
testID,
|
|
1460
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.actionText, { color: isPrimary ? colors.surface : colors.text }], children: label })
|
|
1461
|
+
}
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/Filters/constants.ts
|
|
1466
|
+
var FILTERS_TEST_ID = "ui-filters-declarative";
|
|
1467
|
+
var FIELD_MIN_WIDTH = {
|
|
1468
|
+
select: 150,
|
|
1469
|
+
text: 200,
|
|
1470
|
+
number: 130,
|
|
1471
|
+
dateRange: 260,
|
|
1472
|
+
typeahead: 200,
|
|
1473
|
+
boolean: 150
|
|
1474
|
+
};
|
|
1475
|
+
var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
|
|
1476
|
+
var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
|
|
1477
|
+
var fieldTestID = (barTestID, key) => `${barTestID}-field-${key}`;
|
|
1478
|
+
var applyTestID = (barTestID) => `${barTestID}-apply`;
|
|
1479
|
+
var clearTestID = (barTestID) => `${barTestID}-clear`;
|
|
1480
|
+
var FILTERS_I18N = {
|
|
1481
|
+
apply: "uiTables.filters.apply",
|
|
1482
|
+
applyHint: "uiTables.filters.applyHint",
|
|
1483
|
+
clear: "uiTables.filters.clear",
|
|
1484
|
+
clearHint: "uiTables.filters.clearHint",
|
|
1485
|
+
selectPlaceholder: "uiTables.filters.selectPlaceholder",
|
|
1486
|
+
dropdownHint: "uiTables.filters.dropdownHint",
|
|
1487
|
+
optionHint: "uiTables.filters.optionHint",
|
|
1488
|
+
/**
|
|
1489
|
+
* Accessible NAME of a select trigger, e.g. "{{p1}}: {{p2}}" → "Status: Active". The
|
|
1490
|
+
* trigger's `accessibilityLabel` REPLACES its visible text for a screen reader, so labelling
|
|
1491
|
+
* it with the field name alone silently hides the current selection. Untranslated it
|
|
1492
|
+
* degrades to the field label alone (prior behaviour) — never to the raw key.
|
|
1493
|
+
*/
|
|
1494
|
+
selectTriggerLabel: "uiTables.filters.selectTriggerLabel",
|
|
1495
|
+
from: "uiTables.filters.from",
|
|
1496
|
+
to: "uiTables.filters.to"
|
|
1497
|
+
};
|
|
1498
|
+
var GROW_FLEX = 1;
|
|
1499
|
+
function FieldShell({ field, barTestID, children }) {
|
|
1500
|
+
const { theme } = uiFeedback.useUi();
|
|
1501
|
+
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1502
|
+
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1503
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1504
|
+
reactNative.View,
|
|
1505
|
+
{
|
|
1506
|
+
style: [filterStyles.field, { minWidth }, grow, field.style],
|
|
1507
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1508
|
+
children: [
|
|
1509
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.label, { color: theme.colors.textSecondary }], children: field.label }),
|
|
1510
|
+
children
|
|
1511
|
+
]
|
|
1512
|
+
}
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
function BooleanField({ field, barTestID, value, onChange }) {
|
|
1516
|
+
const { theme } = uiFeedback.useUi();
|
|
1517
|
+
const { colors, palette } = theme;
|
|
1518
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1519
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.switchRow, testID, children: [
|
|
1520
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.subLabel, { color: colors.text }], children: field.label }),
|
|
1521
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1522
|
+
reactNative.Switch,
|
|
1523
|
+
{
|
|
1524
|
+
accessibilityLabel: field.label,
|
|
1525
|
+
accessibilityHint: field.accessibilityHint,
|
|
1526
|
+
accessibilityRole: "switch",
|
|
1527
|
+
accessibilityState: { checked: value },
|
|
1528
|
+
trackColor: { false: colors.border, true: palette.primary["500"] },
|
|
1529
|
+
thumbColor: colors.surface,
|
|
1530
|
+
value,
|
|
1531
|
+
onValueChange: onChange,
|
|
1532
|
+
testID: `${testID}-switch`
|
|
1533
|
+
}
|
|
1534
|
+
)
|
|
1535
|
+
] });
|
|
1536
|
+
}
|
|
1537
|
+
var WEB_DATE_PROPS = typeof document !== "undefined" ? { type: "date" } : {};
|
|
1538
|
+
function DateInput(p) {
|
|
1539
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.dateCol, children: [
|
|
1540
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.subLabel, { color: p.muted }], children: p.label }),
|
|
1541
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1542
|
+
reactNative.TextInput,
|
|
1543
|
+
{
|
|
1544
|
+
accessibilityLabel: p.label,
|
|
1545
|
+
accessibilityHint: p.hint,
|
|
1546
|
+
placeholder: p.placeholder,
|
|
1547
|
+
placeholderTextColor: p.muted,
|
|
1548
|
+
value: p.value,
|
|
1549
|
+
onChangeText: p.onChangeText,
|
|
1550
|
+
onSubmitEditing: p.onSubmit,
|
|
1551
|
+
style: [filterStyles.input, { borderColor: p.border, backgroundColor: p.surface, color: p.color }],
|
|
1552
|
+
testID: `${p.testID}-${p.side}`,
|
|
1553
|
+
...WEB_DATE_PROPS
|
|
1554
|
+
}
|
|
1555
|
+
)
|
|
1556
|
+
] });
|
|
1557
|
+
}
|
|
1558
|
+
function DateRangeField({ field, barTestID, value, onChange, onSubmit, fromLabel, toLabel }) {
|
|
1559
|
+
const { theme } = uiFeedback.useUi();
|
|
1560
|
+
const { colors } = theme;
|
|
1561
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1562
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.dateRow, testID: `${testID}-range`, children: [
|
|
1563
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1564
|
+
DateInput,
|
|
1565
|
+
{
|
|
1566
|
+
side: "from",
|
|
1567
|
+
label: field.fromLabel ?? fromLabel,
|
|
1568
|
+
placeholder: field.fromPlaceholder,
|
|
1569
|
+
value: value.from,
|
|
1570
|
+
color: colors.text,
|
|
1571
|
+
border: colors.border,
|
|
1572
|
+
surface: colors.surface,
|
|
1573
|
+
muted: colors.textSecondary,
|
|
1574
|
+
hint: field.accessibilityHint,
|
|
1575
|
+
testID,
|
|
1576
|
+
onChangeText: (from) => onChange({ from, to: value.to }),
|
|
1577
|
+
onSubmit
|
|
1578
|
+
}
|
|
1579
|
+
),
|
|
1580
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1581
|
+
DateInput,
|
|
1582
|
+
{
|
|
1583
|
+
side: "to",
|
|
1584
|
+
label: field.toLabel ?? toLabel,
|
|
1585
|
+
placeholder: field.toPlaceholder,
|
|
1586
|
+
value: value.to,
|
|
1587
|
+
color: colors.text,
|
|
1588
|
+
border: colors.border,
|
|
1589
|
+
surface: colors.surface,
|
|
1590
|
+
muted: colors.textSecondary,
|
|
1591
|
+
hint: field.accessibilityHint,
|
|
1592
|
+
testID,
|
|
1593
|
+
onChangeText: (to) => onChange({ from: value.from, to }),
|
|
1594
|
+
onSubmit
|
|
1595
|
+
}
|
|
1596
|
+
)
|
|
1597
|
+
] });
|
|
1598
|
+
}
|
|
1599
|
+
var IS_WEB3 = typeof document !== "undefined";
|
|
1600
|
+
var ESCAPE_KEY = "Escape";
|
|
1601
|
+
var ACTIVE_WEIGHT = "700";
|
|
1602
|
+
var IDLE_WEIGHT = "400";
|
|
1603
|
+
function useDismiss(anchorRef, menuRef, onDismiss) {
|
|
1604
|
+
React4.useEffect(() => {
|
|
1605
|
+
if (!IS_WEB3) return void 0;
|
|
1606
|
+
const onMouseDown = (event) => {
|
|
1607
|
+
const anchorNode = anchorRef.current;
|
|
1608
|
+
const menuNode = menuRef.current;
|
|
1609
|
+
const target = event.target instanceof Node ? event.target : null;
|
|
1610
|
+
const insideAnchor = anchorNode !== null && target !== null && anchorNode.contains(target);
|
|
1611
|
+
const insideMenu = menuNode !== null && target !== null && menuNode.contains(target);
|
|
1612
|
+
if (!insideAnchor && !insideMenu) onDismiss();
|
|
1613
|
+
};
|
|
1614
|
+
const onKeyDown = (event) => {
|
|
1615
|
+
if (event.key === ESCAPE_KEY) onDismiss();
|
|
1616
|
+
};
|
|
1617
|
+
document.addEventListener("mousedown", onMouseDown);
|
|
1618
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1619
|
+
return () => {
|
|
1620
|
+
document.removeEventListener("mousedown", onMouseDown);
|
|
1621
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1622
|
+
};
|
|
1623
|
+
}, [anchorRef, menuRef, onDismiss]);
|
|
1624
|
+
}
|
|
1625
|
+
function AnchoredMenu({
|
|
1626
|
+
options,
|
|
1627
|
+
selectedValue,
|
|
1628
|
+
onSelect,
|
|
1629
|
+
onDismiss,
|
|
1630
|
+
colors,
|
|
1631
|
+
optionHint,
|
|
1632
|
+
testID,
|
|
1633
|
+
anchorRef
|
|
1634
|
+
}) {
|
|
1635
|
+
const menuRef = React4__default.default.useRef(null);
|
|
1636
|
+
useDismiss(anchorRef, menuRef, onDismiss);
|
|
1637
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1638
|
+
reactNative.View,
|
|
1639
|
+
{
|
|
1640
|
+
ref: menuRef,
|
|
1641
|
+
accessibilityRole: "menu",
|
|
1642
|
+
style: [filterStyles.menu, { borderColor: colors.border, backgroundColor: colors.surface }],
|
|
1643
|
+
testID: `${testID}-menu`,
|
|
1644
|
+
children: options.map((opt) => {
|
|
1645
|
+
const active = opt.value === selectedValue;
|
|
1182
1646
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1183
1647
|
reactNative.Pressable,
|
|
1184
1648
|
{
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
accessibilityHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1649
|
+
accessibilityRole: "menuitem",
|
|
1650
|
+
accessibilityLabel: opt.label,
|
|
1651
|
+
accessibilityHint: optionHint,
|
|
1189
1652
|
accessibilityState: { selected: active },
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
1653
|
+
onPress: () => onSelect(opt.value),
|
|
1654
|
+
style: filterStyles.option,
|
|
1655
|
+
testID: `${testID}-option-${opt.value}`,
|
|
1656
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.optionText, { color: active ? colors.brand : colors.text, fontWeight: active ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: opt.label })
|
|
1194
1657
|
},
|
|
1195
|
-
|
|
1658
|
+
opt.value
|
|
1196
1659
|
);
|
|
1197
|
-
})
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1660
|
+
})
|
|
1661
|
+
}
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
var CHEVRON_DOWN2 = "\u25BE";
|
|
1665
|
+
var CHEVRON_UP2 = "\u25B4";
|
|
1666
|
+
function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
|
|
1667
|
+
const { theme, t } = uiFeedback.useUi();
|
|
1668
|
+
const { colors, palette } = theme;
|
|
1669
|
+
const anchorRef = React4.useRef(null);
|
|
1670
|
+
const [isOpen, setIsOpen] = React4.useState(false);
|
|
1671
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1672
|
+
const selectedLabel = React4.useMemo(() => {
|
|
1673
|
+
const found = field.options.find((o) => o.value === value);
|
|
1674
|
+
return found?.label ?? field.placeholder ?? placeholder;
|
|
1675
|
+
}, [field.options, field.placeholder, placeholder, value]);
|
|
1676
|
+
const triggerLabel = accessibleName(
|
|
1677
|
+
t(FILTERS_I18N.selectTriggerLabel, field.label, selectedLabel),
|
|
1678
|
+
FILTERS_I18N.selectTriggerLabel,
|
|
1679
|
+
field.label
|
|
1680
|
+
);
|
|
1681
|
+
const close = React4.useCallback(() => {
|
|
1682
|
+
setIsOpen(false);
|
|
1683
|
+
}, []);
|
|
1684
|
+
const toggle = React4.useCallback(() => {
|
|
1685
|
+
setIsOpen((prev) => !prev);
|
|
1686
|
+
}, []);
|
|
1687
|
+
const select = React4.useCallback(
|
|
1688
|
+
(next) => {
|
|
1689
|
+
onChange(next);
|
|
1690
|
+
setIsOpen(false);
|
|
1691
|
+
},
|
|
1692
|
+
[onChange]
|
|
1693
|
+
);
|
|
1694
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: filterStyles.anchor, children: [
|
|
1695
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1696
|
+
reactNative.Pressable,
|
|
1697
|
+
{
|
|
1698
|
+
accessibilityRole: "button",
|
|
1699
|
+
accessibilityLabel: triggerLabel,
|
|
1700
|
+
accessibilityHint: field.accessibilityHint ?? dropdownHint,
|
|
1701
|
+
accessibilityState: { expanded: isOpen },
|
|
1702
|
+
"aria-expanded": isOpen,
|
|
1703
|
+
onPress: toggle,
|
|
1704
|
+
style: [filterStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surface }],
|
|
1705
|
+
testID: `${testID}-trigger`,
|
|
1706
|
+
children: [
|
|
1707
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [filterStyles.selectTriggerText, { color: value === "" ? colors.textSecondary : colors.text }], children: selectedLabel }),
|
|
1708
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { "aria-hidden": true, style: [filterStyles.chevron, { color: colors.textSecondary }], children: isOpen ? CHEVRON_UP2 : CHEVRON_DOWN2 })
|
|
1709
|
+
]
|
|
1710
|
+
}
|
|
1711
|
+
),
|
|
1712
|
+
isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1713
|
+
AnchoredMenu,
|
|
1714
|
+
{
|
|
1715
|
+
options: field.options,
|
|
1716
|
+
selectedValue: value,
|
|
1717
|
+
onSelect: select,
|
|
1718
|
+
onDismiss: close,
|
|
1719
|
+
colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1720
|
+
optionHint,
|
|
1721
|
+
testID,
|
|
1722
|
+
anchorRef
|
|
1723
|
+
}
|
|
1724
|
+
) : null
|
|
1725
|
+
] });
|
|
1726
|
+
}
|
|
1727
|
+
function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
1728
|
+
const { theme } = uiFeedback.useUi();
|
|
1729
|
+
const { colors } = theme;
|
|
1730
|
+
const isNumber = field.kind === "number";
|
|
1731
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1732
|
+
reactNative.TextInput,
|
|
1733
|
+
{
|
|
1734
|
+
accessibilityLabel: field.label,
|
|
1735
|
+
accessibilityHint: field.accessibilityHint,
|
|
1736
|
+
keyboardType: isNumber ? "numeric" : "default",
|
|
1737
|
+
placeholder: field.placeholder,
|
|
1738
|
+
placeholderTextColor: colors.textSecondary,
|
|
1739
|
+
value,
|
|
1740
|
+
onChangeText: onChange,
|
|
1741
|
+
onSubmitEditing: onSubmit,
|
|
1742
|
+
style: [filterStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }],
|
|
1743
|
+
testID: `${field.testID ?? fieldTestID(barTestID, field.key)}-input`
|
|
1744
|
+
}
|
|
1745
|
+
);
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
// src/Filters/utils/suggest.ts
|
|
1749
|
+
var RANK_VALUE_EXACT = 0;
|
|
1750
|
+
var RANK_VALUE_PREFIX = 1;
|
|
1751
|
+
var RANK_LABEL_PREFIX = 2;
|
|
1752
|
+
var RANK_LABEL_CONTAINS = 3;
|
|
1753
|
+
var NO_MATCH = -1;
|
|
1754
|
+
function rankOf(option, needle) {
|
|
1755
|
+
const value = option.value.toLowerCase();
|
|
1756
|
+
const label = option.label.toLowerCase();
|
|
1757
|
+
if (value === needle) return RANK_VALUE_EXACT;
|
|
1758
|
+
if (value.startsWith(needle)) return RANK_VALUE_PREFIX;
|
|
1759
|
+
if (label.startsWith(needle)) return RANK_LABEL_PREFIX;
|
|
1760
|
+
if (label.includes(needle)) return RANK_LABEL_CONTAINS;
|
|
1761
|
+
return NO_MATCH;
|
|
1762
|
+
}
|
|
1763
|
+
function suggestOptions(options, query, minChars, limit) {
|
|
1764
|
+
const needle = query.trim().toLowerCase();
|
|
1765
|
+
if (needle.length < minChars) return [];
|
|
1766
|
+
const scored = [];
|
|
1767
|
+
for (const option of options) {
|
|
1768
|
+
const rank = rankOf(option, needle);
|
|
1769
|
+
if (rank !== NO_MATCH) scored.push({ option, rank });
|
|
1770
|
+
}
|
|
1771
|
+
scored.sort((a, b) => a.rank !== b.rank ? a.rank - b.rank : a.option.label.localeCompare(b.option.label));
|
|
1772
|
+
return scored.slice(0, limit).map((entry) => entry.option);
|
|
1773
|
+
}
|
|
1774
|
+
function isUnmatched(options, text) {
|
|
1775
|
+
const needle = text.trim().toLowerCase();
|
|
1776
|
+
if (needle === "") return false;
|
|
1777
|
+
return !options.some((o) => o.value.toLowerCase() === needle || o.label.toLowerCase() === needle);
|
|
1778
|
+
}
|
|
1779
|
+
var CLOSE_DELAY_MS = 140;
|
|
1780
|
+
function TypeaheadField({ field, barTestID, value, onChange, onSubmit, optionHint }) {
|
|
1781
|
+
const { theme } = uiFeedback.useUi();
|
|
1782
|
+
const { colors, palette, semantic } = theme;
|
|
1783
|
+
const anchorRef = React4.useRef(null);
|
|
1784
|
+
const [isOpen, setIsOpen] = React4.useState(false);
|
|
1785
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1786
|
+
const minChars = field.minChars ?? DEFAULT_TYPEAHEAD_MIN_CHARS;
|
|
1787
|
+
const maxSuggestions = field.maxSuggestions ?? DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
1788
|
+
const exactPick = React4.useMemo(
|
|
1789
|
+
() => field.options.some((o) => o.label === value),
|
|
1790
|
+
[field.options, value]
|
|
1791
|
+
);
|
|
1792
|
+
const suggestions = React4.useMemo(
|
|
1793
|
+
() => exactPick ? [] : suggestOptions(field.options, value, minChars, maxSuggestions),
|
|
1794
|
+
[exactPick, field.options, value, minChars, maxSuggestions]
|
|
1795
|
+
);
|
|
1796
|
+
const showMenu = isOpen && suggestions.length > 0;
|
|
1797
|
+
const handleChange = React4.useCallback(
|
|
1798
|
+
(next) => {
|
|
1799
|
+
onChange(next);
|
|
1800
|
+
setIsOpen(true);
|
|
1801
|
+
},
|
|
1802
|
+
[onChange]
|
|
1803
|
+
);
|
|
1804
|
+
const pick = React4.useCallback(
|
|
1805
|
+
(optionValue) => {
|
|
1806
|
+
const opt = field.options.find((o) => o.value === optionValue);
|
|
1807
|
+
onChange(opt?.label ?? optionValue);
|
|
1808
|
+
setIsOpen(false);
|
|
1809
|
+
},
|
|
1810
|
+
[field.options, onChange]
|
|
1811
|
+
);
|
|
1812
|
+
const handleBlur = React4.useCallback(() => {
|
|
1813
|
+
setTimeout(() => setIsOpen(false), CLOSE_DELAY_MS);
|
|
1814
|
+
}, []);
|
|
1815
|
+
const handleSubmit = React4.useCallback(() => {
|
|
1816
|
+
setIsOpen(false);
|
|
1817
|
+
onSubmit();
|
|
1818
|
+
}, [onSubmit]);
|
|
1819
|
+
const hasError = field.error !== void 0 && field.error !== "";
|
|
1820
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: filterStyles.anchor, children: [
|
|
1821
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1822
|
+
reactNative.TextInput,
|
|
1823
|
+
{
|
|
1824
|
+
accessibilityLabel: field.label,
|
|
1825
|
+
accessibilityHint: field.accessibilityHint,
|
|
1826
|
+
autoCapitalize: "none",
|
|
1827
|
+
autoCorrect: false,
|
|
1828
|
+
placeholder: field.placeholder,
|
|
1829
|
+
placeholderTextColor: colors.textSecondary,
|
|
1830
|
+
spellCheck: false,
|
|
1831
|
+
value,
|
|
1832
|
+
onChangeText: handleChange,
|
|
1833
|
+
onFocus: () => setIsOpen(true),
|
|
1834
|
+
onBlur: handleBlur,
|
|
1835
|
+
onSubmitEditing: handleSubmit,
|
|
1836
|
+
style: [filterStyles.input, { borderColor: hasError ? semantic.error["500"] : colors.border, backgroundColor: colors.surface, color: colors.text }],
|
|
1837
|
+
testID: `${testID}-input`
|
|
1838
|
+
}
|
|
1839
|
+
),
|
|
1840
|
+
showMenu ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1841
|
+
AnchoredMenu,
|
|
1842
|
+
{
|
|
1843
|
+
options: suggestions,
|
|
1844
|
+
selectedValue: value,
|
|
1845
|
+
onSelect: pick,
|
|
1846
|
+
onDismiss: () => setIsOpen(false),
|
|
1847
|
+
colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1848
|
+
optionHint,
|
|
1849
|
+
testID,
|
|
1850
|
+
anchorRef
|
|
1851
|
+
}
|
|
1852
|
+
) : null,
|
|
1853
|
+
hasError ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [filterStyles.error, { color: semantic.error["500"] }], testID: `${testID}-error`, children: field.error }) : null
|
|
1854
|
+
] });
|
|
1855
|
+
}
|
|
1856
|
+
var EMPTY_RANGE = { from: "", to: "" };
|
|
1857
|
+
function asString(value) {
|
|
1858
|
+
return typeof value === "string" ? value : "";
|
|
1859
|
+
}
|
|
1860
|
+
function asBool(value) {
|
|
1861
|
+
return value === true;
|
|
1862
|
+
}
|
|
1863
|
+
function asRange(value) {
|
|
1864
|
+
if (typeof value === "object" && value !== null && "from" in value && "to" in value) return value;
|
|
1865
|
+
return EMPTY_RANGE;
|
|
1866
|
+
}
|
|
1867
|
+
function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings, renderSelect }) {
|
|
1868
|
+
const raw = values[field.key];
|
|
1869
|
+
if (field.kind === "boolean") {
|
|
1870
|
+
return /* @__PURE__ */ jsxRuntime.jsx(BooleanField, { field, barTestID, value: asBool(raw), onChange: (v) => setField(field.key, v) });
|
|
1871
|
+
}
|
|
1872
|
+
const body = (() => {
|
|
1873
|
+
switch (field.kind) {
|
|
1874
|
+
case "select":
|
|
1875
|
+
if (renderSelect !== void 0) {
|
|
1876
|
+
return renderSelect({
|
|
1877
|
+
field,
|
|
1878
|
+
value: asString(raw),
|
|
1879
|
+
onChange: (v) => setField(field.key, v),
|
|
1880
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key)
|
|
1881
|
+
});
|
|
1222
1882
|
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1883
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1884
|
+
SelectField,
|
|
1885
|
+
{
|
|
1886
|
+
field,
|
|
1887
|
+
barTestID,
|
|
1888
|
+
value: asString(raw),
|
|
1889
|
+
onChange: (v) => setField(field.key, v),
|
|
1890
|
+
placeholder: strings.selectPlaceholder,
|
|
1891
|
+
dropdownHint: strings.dropdownHint,
|
|
1892
|
+
optionHint: strings.optionHint
|
|
1893
|
+
}
|
|
1894
|
+
);
|
|
1895
|
+
case "typeahead":
|
|
1896
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1897
|
+
TypeaheadField,
|
|
1898
|
+
{
|
|
1899
|
+
field,
|
|
1900
|
+
barTestID,
|
|
1901
|
+
value: asString(raw),
|
|
1902
|
+
onChange: (v) => setField(field.key, v),
|
|
1903
|
+
onSubmit,
|
|
1904
|
+
optionHint: strings.optionHint
|
|
1905
|
+
}
|
|
1906
|
+
);
|
|
1907
|
+
case "dateRange":
|
|
1908
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1909
|
+
DateRangeField,
|
|
1910
|
+
{
|
|
1911
|
+
field,
|
|
1912
|
+
barTestID,
|
|
1913
|
+
value: asRange(raw),
|
|
1914
|
+
onChange: (v) => setField(field.key, v),
|
|
1915
|
+
onSubmit,
|
|
1916
|
+
fromLabel: strings.fromLabel,
|
|
1917
|
+
toLabel: strings.toLabel
|
|
1918
|
+
}
|
|
1919
|
+
);
|
|
1920
|
+
default:
|
|
1921
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1922
|
+
TextField,
|
|
1923
|
+
{
|
|
1924
|
+
field,
|
|
1925
|
+
barTestID,
|
|
1926
|
+
value: asString(raw),
|
|
1927
|
+
onChange: (v) => setField(field.key, v),
|
|
1928
|
+
onSubmit
|
|
1929
|
+
}
|
|
1930
|
+
);
|
|
1931
|
+
}
|
|
1932
|
+
})();
|
|
1933
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FieldShell, { field, barTestID, children: body });
|
|
1934
|
+
}
|
|
1935
|
+
function Filters({
|
|
1936
|
+
fields,
|
|
1937
|
+
values,
|
|
1938
|
+
onChange,
|
|
1939
|
+
resultsCount,
|
|
1940
|
+
resultsLabel,
|
|
1941
|
+
onApply,
|
|
1942
|
+
applyLabel,
|
|
1943
|
+
applyHint,
|
|
1944
|
+
applyDisabled = false,
|
|
1945
|
+
onClear,
|
|
1946
|
+
clearLabel,
|
|
1947
|
+
clearHint,
|
|
1948
|
+
actions,
|
|
1949
|
+
selectPlaceholder,
|
|
1950
|
+
fromLabel,
|
|
1951
|
+
toLabel,
|
|
1952
|
+
renderSelect,
|
|
1953
|
+
styleOverrides,
|
|
1954
|
+
testID = FILTERS_TEST_ID
|
|
1955
|
+
}) {
|
|
1956
|
+
const { t } = uiFeedback.useUi();
|
|
1957
|
+
const setField = React4.useCallback(
|
|
1958
|
+
(key, value) => {
|
|
1959
|
+
onChange({ ...values, [key]: value });
|
|
1960
|
+
},
|
|
1961
|
+
[onChange, values]
|
|
1962
|
+
);
|
|
1963
|
+
const onSubmit = React4.useCallback(() => {
|
|
1964
|
+
if (onApply !== void 0 && !applyDisabled) onApply();
|
|
1965
|
+
}, [onApply, applyDisabled]);
|
|
1966
|
+
const strings = React4.useMemo(
|
|
1967
|
+
() => ({
|
|
1968
|
+
selectPlaceholder: selectPlaceholder ?? t(FILTERS_I18N.selectPlaceholder),
|
|
1969
|
+
dropdownHint: t(FILTERS_I18N.dropdownHint),
|
|
1970
|
+
optionHint: t(FILTERS_I18N.optionHint),
|
|
1971
|
+
fromLabel: fromLabel ?? t(FILTERS_I18N.from),
|
|
1972
|
+
toLabel: toLabel ?? t(FILTERS_I18N.to)
|
|
1973
|
+
}),
|
|
1974
|
+
[selectPlaceholder, fromLabel, toLabel, t]
|
|
1975
|
+
);
|
|
1976
|
+
const barActions = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1977
|
+
actions,
|
|
1978
|
+
onClear !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1979
|
+
ActionButton,
|
|
1980
|
+
{
|
|
1981
|
+
label: clearLabel ?? t(FILTERS_I18N.clear),
|
|
1982
|
+
hint: clearHint ?? t(FILTERS_I18N.clearHint),
|
|
1983
|
+
tone: "ghost",
|
|
1984
|
+
onPress: onClear,
|
|
1985
|
+
testID: clearTestID(testID)
|
|
1986
|
+
}
|
|
1987
|
+
),
|
|
1988
|
+
onApply !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1989
|
+
ActionButton,
|
|
1990
|
+
{
|
|
1991
|
+
label: applyLabel ?? t(FILTERS_I18N.apply),
|
|
1992
|
+
hint: applyHint ?? t(FILTERS_I18N.applyHint),
|
|
1993
|
+
tone: "primary",
|
|
1994
|
+
disabled: applyDisabled,
|
|
1995
|
+
onPress: onApply,
|
|
1996
|
+
testID: applyTestID(testID)
|
|
1997
|
+
}
|
|
1998
|
+
)
|
|
1225
1999
|
] });
|
|
2000
|
+
const hasActions = actions !== void 0 || onClear !== void 0 || onApply !== void 0;
|
|
2001
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2002
|
+
FilterBar,
|
|
2003
|
+
{
|
|
2004
|
+
resultsCount,
|
|
2005
|
+
resultsLabel,
|
|
2006
|
+
actions: hasActions ? barActions : void 0,
|
|
2007
|
+
styleOverrides,
|
|
2008
|
+
testID,
|
|
2009
|
+
children: fields.map((field) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2010
|
+
FilterFieldView,
|
|
2011
|
+
{
|
|
2012
|
+
field,
|
|
2013
|
+
barTestID: testID,
|
|
2014
|
+
values,
|
|
2015
|
+
setField,
|
|
2016
|
+
onSubmit,
|
|
2017
|
+
strings,
|
|
2018
|
+
renderSelect
|
|
2019
|
+
},
|
|
2020
|
+
field.key
|
|
2021
|
+
))
|
|
2022
|
+
}
|
|
2023
|
+
);
|
|
2024
|
+
}
|
|
2025
|
+
function shallowEqual(a, b) {
|
|
2026
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
2027
|
+
}
|
|
2028
|
+
function useFilterDraft({ initial, onApply, onReset }) {
|
|
2029
|
+
const [draft, setDraft] = React4.useState(initial);
|
|
2030
|
+
const [committed, setCommitted] = React4.useState(initial);
|
|
2031
|
+
const setField = React4.useCallback((key, value) => {
|
|
2032
|
+
setDraft((prev) => ({ ...prev, [key]: value }));
|
|
2033
|
+
}, []);
|
|
2034
|
+
const apply = React4.useCallback(() => {
|
|
2035
|
+
setCommitted(draft);
|
|
2036
|
+
onApply?.(draft);
|
|
2037
|
+
}, [draft, onApply]);
|
|
2038
|
+
const reset = React4.useCallback(() => {
|
|
2039
|
+
setDraft(initial);
|
|
2040
|
+
setCommitted(initial);
|
|
2041
|
+
onReset?.();
|
|
2042
|
+
}, [initial, onReset]);
|
|
2043
|
+
const dirty = React4.useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
|
|
2044
|
+
return { draft, committed, setField, setDraft, apply, reset, dirty };
|
|
1226
2045
|
}
|
|
1227
2046
|
|
|
1228
2047
|
exports.CARD_STACK_BREAKPOINT = CARD_STACK_BREAKPOINT;
|
|
1229
2048
|
exports.DEFAULT_PAGE_SIZE_OPTIONS = DEFAULT_PAGE_SIZE_OPTIONS;
|
|
2049
|
+
exports.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
2050
|
+
exports.DEFAULT_TYPEAHEAD_MIN_CHARS = DEFAULT_TYPEAHEAD_MIN_CHARS;
|
|
1230
2051
|
exports.DataTable = DataTable;
|
|
2052
|
+
exports.FIELD_MIN_WIDTH = FIELD_MIN_WIDTH;
|
|
2053
|
+
exports.FILTERS_I18N = FILTERS_I18N;
|
|
2054
|
+
exports.FILTERS_TEST_ID = FILTERS_TEST_ID;
|
|
1231
2055
|
exports.FilterBar = FilterBar;
|
|
2056
|
+
exports.Filters = Filters;
|
|
1232
2057
|
exports.Pager = Pager;
|
|
1233
2058
|
exports.StatCard = StatCard;
|
|
1234
2059
|
exports.TABLE_I18N = TABLE_I18N;
|
|
1235
2060
|
exports.TABLE_TEST_IDS = TABLE_TEST_IDS;
|
|
2061
|
+
exports.applyTestID = applyTestID;
|
|
2062
|
+
exports.clearTestID = clearTestID;
|
|
2063
|
+
exports.fieldTestID = fieldTestID;
|
|
2064
|
+
exports.isUnmatched = isUnmatched;
|
|
1236
2065
|
exports.rowDetailTestID = rowDetailTestID;
|
|
1237
2066
|
exports.rowSelectTestID = rowSelectTestID;
|
|
1238
2067
|
exports.rowTestID = rowTestID;
|
|
1239
2068
|
exports.selectAllTestID = selectAllTestID;
|
|
2069
|
+
exports.suggestOptions = suggestOptions;
|
|
2070
|
+
exports.useFilterDraft = useFilterDraft;
|
|
1240
2071
|
//# sourceMappingURL=index.js.map
|
|
1241
2072
|
//# sourceMappingURL=index.js.map
|