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