@dloizides/ui-tables 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
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
14
  var CARD_PADDING = 16;
11
15
  var CARD_BORDER_RADIUS = 12;
@@ -29,7 +33,7 @@ var styles = reactNative.StyleSheet.create({
29
33
  lineHeight: VALUE_LINE_HEIGHT
30
34
  }
31
35
  });
32
- var StatCard = react.memo(({ label, value, testID }) => {
36
+ var StatCard = React4.memo(({ label, value, testID }) => {
33
37
  const { theme, t } = uiFeedback.useUi();
34
38
  const { colors } = theme;
35
39
  const formattedValue = value.toLocaleString();
@@ -72,8 +76,10 @@ var TABLE_TEST_IDS = {
72
76
  results: "ui-results",
73
77
  pager: "ui-pager",
74
78
  pagerInfo: "ui-pager-info",
79
+ pagerFirst: "ui-pager-first",
75
80
  pagerPrev: "ui-pager-prev",
76
- pagerNext: "ui-pager-next"
81
+ pagerNext: "ui-pager-next",
82
+ pagerLast: "ui-pager-last"
77
83
  };
78
84
  var rowTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowInfix}-${key}`;
79
85
  var rowDetailTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowDetailInfix}-${key}`;
@@ -104,10 +110,14 @@ var TABLE_I18N = {
104
110
  selectClearHint: "uiTables.select.clearHint",
105
111
  results: "uiTables.results",
106
112
  pagerInfo: "uiTables.pager.info",
113
+ pagerFirst: "uiTables.pager.first",
107
114
  pagerPrev: "uiTables.pager.prev",
108
115
  pagerNext: "uiTables.pager.next",
116
+ pagerLast: "uiTables.pager.last",
117
+ pagerFirstHint: "uiTables.pager.firstHint",
109
118
  pagerPrevHint: "uiTables.pager.prevHint",
110
119
  pagerNextHint: "uiTables.pager.nextHint",
120
+ pagerLastHint: "uiTables.pager.lastHint",
111
121
  pagerRows: "uiTables.pager.rows",
112
122
  pagerRowsOptionHint: "uiTables.pager.rowsOptionHint",
113
123
  /** Accessible hint for the dropdown-variant rows-per-page trigger button. */
@@ -625,21 +635,21 @@ var TAB_INDEX_ACTIVE = 0;
625
635
  var TAB_INDEX_INACTIVE2 = -1;
626
636
  var IS_WEB = reactNative.Platform.OS === "web";
627
637
  function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
628
- const [focusedKey, setFocusedKey] = react.useState(void 0);
629
- const nodes = react.useRef(/* @__PURE__ */ new Map());
638
+ const [focusedKey, setFocusedKey] = React4.useState(void 0);
639
+ const nodes = React4.useRef(/* @__PURE__ */ new Map());
630
640
  const tabbableKey = enabled ? resolveTabbableKey(rowKeys, focusedKey) : void 0;
631
- const registerRow = react.useCallback((key, node) => {
641
+ const registerRow = React4.useCallback((key, node) => {
632
642
  if (node === null || node === void 0) {
633
643
  nodes.current.delete(key);
634
644
  return;
635
645
  }
636
646
  nodes.current.set(key, node);
637
647
  }, []);
638
- const focusRow = react.useCallback((key) => {
648
+ const focusRow = React4.useCallback((key) => {
639
649
  setFocusedKey(key);
640
650
  nodes.current.get(key)?.focus?.();
641
651
  }, []);
642
- const handleKey = react.useCallback(
652
+ const handleKey = React4.useCallback(
643
653
  (event, key) => {
644
654
  const action = toRowNavAction(event.key);
645
655
  if (action === void 0) return;
@@ -664,18 +674,18 @@ function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
664
674
  },
665
675
  [rowKeys, onToggleKey, onActivateKey, focusRow]
666
676
  );
667
- const keyDownFor = react.useCallback(
677
+ const keyDownFor = React4.useCallback(
668
678
  (key) => {
669
679
  if (!enabled || !IS_WEB) return void 0;
670
680
  return (event) => handleKey(event, key);
671
681
  },
672
682
  [enabled, handleKey]
673
683
  );
674
- const tabIndexFor = react.useCallback(
684
+ const tabIndexFor = React4.useCallback(
675
685
  (key) => key === tabbableKey ? TAB_INDEX_ACTIVE : TAB_INDEX_INACTIVE2,
676
686
  [tabbableKey]
677
687
  );
678
- const onRowFocus = react.useCallback((key) => setFocusedKey(key), []);
688
+ const onRowFocus = React4.useCallback((key) => setFocusedKey(key), []);
679
689
  return { tabIndexFor, registerRow, onRowFocus, keyDownFor };
680
690
  }
681
691
 
@@ -727,20 +737,20 @@ function useTableSelection({
727
737
  const selected = selectedRowKeys ?? NO_KEYS;
728
738
  const allMatching = allMatchingSelected ?? false;
729
739
  const matching = matchingCount ?? NO_MATCHES;
730
- const pageHeaderState = react.useMemo(
740
+ const pageHeaderState = React4.useMemo(
731
741
  () => resolveHeaderCheckboxState(selected, pageKeys),
732
742
  [selected, pageKeys]
733
743
  );
734
744
  const headerState = allMatching ? "all" /* All */ : pageHeaderState;
735
- const bannerMode = react.useMemo(
745
+ const bannerMode = React4.useMemo(
736
746
  () => onSelectAllMatchingChange === void 0 ? "hidden" /* Hidden */ : resolveSelectAllBannerMode(pageHeaderState, allMatching, pageKeys.length, matching),
737
747
  [onSelectAllMatchingChange, pageHeaderState, allMatching, pageKeys.length, matching]
738
748
  );
739
- const isSelected = react.useCallback(
749
+ const isSelected = React4.useCallback(
740
750
  (key) => isRowSelected(selected, key, allMatching),
741
751
  [selected, allMatching]
742
752
  );
743
- const toggleRow = react.useCallback(
753
+ const toggleRow = React4.useCallback(
744
754
  (key) => {
745
755
  if (allMatching) {
746
756
  onSelectAllMatchingChange?.(false);
@@ -751,7 +761,7 @@ function useTableSelection({
751
761
  },
752
762
  [allMatching, onSelectAllMatchingChange, onSelectionChange, pageKeys, selected]
753
763
  );
754
- const toggleAll = react.useCallback(() => {
764
+ const toggleAll = React4.useCallback(() => {
755
765
  if (allMatching) {
756
766
  onSelectAllMatchingChange?.(false);
757
767
  onSelectionChange?.(NO_KEYS);
@@ -759,7 +769,7 @@ function useTableSelection({
759
769
  }
760
770
  onSelectionChange?.(toggleAllOnPage(selected, pageKeys));
761
771
  }, [allMatching, onSelectAllMatchingChange, onSelectionChange, selected, pageKeys]);
762
- const toggleAllMatching = react.useCallback(() => {
772
+ const toggleAllMatching = React4.useCallback(() => {
763
773
  const next = !allMatching;
764
774
  onSelectAllMatchingChange?.(next);
765
775
  if (!next) onSelectionChange?.(NO_KEYS);
@@ -800,9 +810,9 @@ function DataTable(props) {
800
810
  const stacked = width < stackBreakpoint;
801
811
  const frame = { backgroundColor: colors.surface, borderColor: colors.border };
802
812
  const interactive = onRowPress !== void 0;
803
- const [hoveredKey, setHoveredKey] = react.useState(void 0);
813
+ const [hoveredKey, setHoveredKey] = React4.useState(void 0);
804
814
  const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
805
- const rowKeys = react.useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
815
+ const rowKeys = React4.useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
806
816
  const selection = useTableSelection({
807
817
  pageKeys: rowKeys,
808
818
  selectedRowKeys,
@@ -811,7 +821,7 @@ function DataTable(props) {
811
821
  allMatchingSelected,
812
822
  onSelectAllMatchingChange
813
823
  });
814
- const activateKey = react.useCallback(
824
+ const activateKey = React4.useCallback(
815
825
  (key) => {
816
826
  const row = rows[rowKeys.indexOf(key)];
817
827
  if (row !== void 0) onRowPress?.(row);
@@ -824,7 +834,7 @@ function DataTable(props) {
824
834
  onToggleKey: selection.selectable ? selection.toggleRow : void 0,
825
835
  onActivateKey: interactive ? activateKey : void 0
826
836
  });
827
- const rowBackground = react.useCallback(
837
+ const rowBackground = React4.useCallback(
828
838
  (row, index) => {
829
839
  const tint = rowTint?.(row);
830
840
  if (tint) return tint;
@@ -969,8 +979,8 @@ function buildWebFixedStyle(rect, viewportWidth) {
969
979
  };
970
980
  }
971
981
  function useTriggerRect(anchorRef, isOpen) {
972
- const [rect, setRect] = react.useState(null);
973
- react.useLayoutEffect(() => {
982
+ const [rect, setRect] = React4.useState(null);
983
+ React4.useLayoutEffect(() => {
974
984
  if (!IS_WEB2 || !isOpen) return void 0;
975
985
  const measure = () => {
976
986
  setRect(readTriggerRect(anchorRef));
@@ -986,7 +996,7 @@ function useTriggerRect(anchorRef, isOpen) {
986
996
  return rect;
987
997
  }
988
998
  function useDismissOnOutside(anchorRef, menuRef, isOpen, onClose) {
989
- react.useEffect(() => {
999
+ React4.useEffect(() => {
990
1000
  if (!IS_WEB2 || !isOpen) return void 0;
991
1001
  const onMouseDown = (event) => {
992
1002
  const anchorNode = anchorRef.current;
@@ -1022,16 +1032,16 @@ function SizeDropdown({
1022
1032
  triggerStyle,
1023
1033
  triggerTextStyle
1024
1034
  }) {
1025
- const anchorRef = react.useRef(null);
1026
- const menuRef = react.useRef(null);
1027
- const [isOpen, setIsOpen] = react.useState(false);
1028
- const close = react.useCallback(() => {
1035
+ const anchorRef = React4.useRef(null);
1036
+ const menuRef = React4.useRef(null);
1037
+ const [isOpen, setIsOpen] = React4.useState(false);
1038
+ const close = React4.useCallback(() => {
1029
1039
  setIsOpen(false);
1030
1040
  }, []);
1031
- const toggle = react.useCallback(() => {
1041
+ const toggle = React4.useCallback(() => {
1032
1042
  setIsOpen((prev) => !prev);
1033
1043
  }, []);
1034
- const select = react.useCallback(
1044
+ const select = React4.useCallback(
1035
1045
  (size) => {
1036
1046
  onPageSizeChange(size);
1037
1047
  setIsOpen(false);
@@ -1089,11 +1099,9 @@ function SizeDropdown({
1089
1099
  ] });
1090
1100
  }
1091
1101
  var FIRST_PAGE = 1;
1092
- var EN_DASH = "\u2013";
1093
1102
  var DISABLED_OPACITY = 0.4;
1094
1103
  var FULL_OPACITY = 1;
1095
1104
  var TRANSPARENT2 = "transparent";
1096
- var BOLD = "700";
1097
1105
  var PAGER_HIT_SLOP = { top: 10, bottom: 10 };
1098
1106
  function NavButton({ label, hint, disabled, onPress, color, border, testID, styleOverrides: o }) {
1099
1107
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -1112,6 +1120,136 @@ function NavButton({ label, hint, disabled, onPress, color, border, testID, styl
1112
1120
  }
1113
1121
  );
1114
1122
  }
1123
+ function RowsControl({ pageSize, pageSizeOptions, onPageSizeChange, isDropdown, testID, styleOverrides: o }) {
1124
+ const { theme, t } = uiFeedback.useUi();
1125
+ const { colors, palette } = theme;
1126
+ const brand = palette.primary["500"];
1127
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1128
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [isDropdown ? chromeStyles.pagerRowsLabelPlain : chromeStyles.pagerRowsLabel, { color: colors.textSecondary }, o?.pagerRowsLabel], children: t(TABLE_I18N.pagerRows) }),
1129
+ isDropdown ? /* @__PURE__ */ jsxRuntime.jsx(
1130
+ SizeDropdown,
1131
+ {
1132
+ pageSize,
1133
+ pageSizeOptions,
1134
+ onPageSizeChange,
1135
+ testID,
1136
+ triggerHint: t(TABLE_I18N.pagerRowsTriggerHint),
1137
+ optionHint: t(TABLE_I18N.pagerRowsOptionHint),
1138
+ textColor: colors.text,
1139
+ mutedColor: colors.textSecondary,
1140
+ borderColor: colors.border,
1141
+ surfaceColor: colors.surface,
1142
+ brandColor: brand,
1143
+ triggerStyle: o?.sizePill,
1144
+ triggerTextStyle: o?.sizePillText
1145
+ }
1146
+ ) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [chromeStyles.sizeGroup, o?.sizeGroup], children: pageSizeOptions.map((size) => {
1147
+ const active = size === pageSize;
1148
+ return /* @__PURE__ */ jsxRuntime.jsx(
1149
+ reactNative.Pressable,
1150
+ {
1151
+ testID: `${testID}-size-${size}`,
1152
+ accessibilityRole: "button",
1153
+ accessibilityLabel: String(size),
1154
+ accessibilityHint: t(TABLE_I18N.pagerRowsOptionHint),
1155
+ accessibilityState: { selected: active },
1156
+ hitSlop: PAGER_HIT_SLOP,
1157
+ onPress: () => onPageSizeChange(size),
1158
+ style: [chromeStyles.sizePill, { borderColor: active ? brand : colors.border, backgroundColor: active ? brand : TRANSPARENT2 }, o?.sizePill],
1159
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [chromeStyles.sizePillText, { color: active ? colors.surface : colors.textSecondary }, o?.sizePillText], children: size })
1160
+ },
1161
+ size
1162
+ );
1163
+ }) })
1164
+ ] });
1165
+ }
1166
+ function PagerNav({
1167
+ pageSize,
1168
+ pageSizeOptions,
1169
+ onPageSizeChange,
1170
+ onPageChange,
1171
+ safePage,
1172
+ lastPage,
1173
+ isCompact,
1174
+ isDropdown,
1175
+ showFirstLast,
1176
+ testID,
1177
+ styleOverrides: o
1178
+ }) {
1179
+ const { theme, t } = uiFeedback.useUi();
1180
+ const { colors } = theme;
1181
+ const atFirst = safePage <= FIRST_PAGE;
1182
+ const atLast = safePage >= lastPage;
1183
+ const showJumps = showFirstLast && !isCompact;
1184
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [chromeStyles.pagerNav, o?.pagerNav], children: [
1185
+ !isCompact && /* @__PURE__ */ jsxRuntime.jsx(
1186
+ RowsControl,
1187
+ {
1188
+ pageSize,
1189
+ pageSizeOptions,
1190
+ onPageSizeChange,
1191
+ isDropdown,
1192
+ testID,
1193
+ styleOverrides: o
1194
+ }
1195
+ ),
1196
+ showJumps && /* @__PURE__ */ jsxRuntime.jsx(
1197
+ NavButton,
1198
+ {
1199
+ label: t(TABLE_I18N.pagerFirst),
1200
+ hint: t(TABLE_I18N.pagerFirstHint),
1201
+ disabled: atFirst,
1202
+ onPress: () => onPageChange(FIRST_PAGE),
1203
+ color: colors.text,
1204
+ border: colors.border,
1205
+ styleOverrides: o,
1206
+ testID: TABLE_TEST_IDS.pagerFirst
1207
+ }
1208
+ ),
1209
+ /* @__PURE__ */ jsxRuntime.jsx(
1210
+ NavButton,
1211
+ {
1212
+ label: t(TABLE_I18N.pagerPrev),
1213
+ hint: t(TABLE_I18N.pagerPrevHint),
1214
+ disabled: atFirst,
1215
+ onPress: () => onPageChange(safePage - 1),
1216
+ color: colors.text,
1217
+ border: colors.border,
1218
+ styleOverrides: o,
1219
+ testID: TABLE_TEST_IDS.pagerPrev
1220
+ }
1221
+ ),
1222
+ /* @__PURE__ */ jsxRuntime.jsx(
1223
+ NavButton,
1224
+ {
1225
+ label: t(TABLE_I18N.pagerNext),
1226
+ hint: t(TABLE_I18N.pagerNextHint),
1227
+ disabled: atLast,
1228
+ onPress: () => onPageChange(safePage + 1),
1229
+ color: colors.text,
1230
+ border: colors.border,
1231
+ styleOverrides: o,
1232
+ testID: TABLE_TEST_IDS.pagerNext
1233
+ }
1234
+ ),
1235
+ showJumps && /* @__PURE__ */ jsxRuntime.jsx(
1236
+ NavButton,
1237
+ {
1238
+ label: t(TABLE_I18N.pagerLast),
1239
+ hint: t(TABLE_I18N.pagerLastHint),
1240
+ disabled: atLast,
1241
+ onPress: () => onPageChange(lastPage),
1242
+ color: colors.text,
1243
+ border: colors.border,
1244
+ styleOverrides: o,
1245
+ testID: TABLE_TEST_IDS.pagerLast
1246
+ }
1247
+ )
1248
+ ] });
1249
+ }
1250
+ var FIRST_PAGE2 = 1;
1251
+ var EN_DASH = "\u2013";
1252
+ var BOLD = "700";
1115
1253
  function Pager({
1116
1254
  page,
1117
1255
  pageSize,
@@ -1121,24 +1259,30 @@ function Pager({
1121
1259
  pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS,
1122
1260
  rowsVariant = "pills",
1123
1261
  unitLabel,
1262
+ unitLabelSingular,
1263
+ showFirstLast = false,
1264
+ responsive = false,
1265
+ stackBreakpoint = CARD_STACK_BREAKPOINT,
1124
1266
  infoPrefix,
1125
1267
  boldNumbers = false,
1126
1268
  styleOverrides: o,
1127
1269
  testID = TABLE_TEST_IDS.pager
1128
1270
  }) {
1129
1271
  const { theme, t } = uiFeedback.useUi();
1130
- const { colors, palette } = theme;
1131
- const brand = palette.primary["500"];
1272
+ const { colors } = theme;
1273
+ const { width } = reactNative.useWindowDimensions();
1132
1274
  const isDropdown = rowsVariant === "dropdown";
1133
- const lastPage = Math.max(FIRST_PAGE, Math.ceil(total / pageSize));
1134
- const safePage = Math.min(Math.max(page, FIRST_PAGE), lastPage);
1275
+ const isCompact = responsive && width < stackBreakpoint;
1276
+ const lastPage = Math.max(FIRST_PAGE2, Math.ceil(total / pageSize));
1277
+ const safePage = Math.min(Math.max(page, FIRST_PAGE2), lastPage);
1135
1278
  const from = total === 0 ? 0 : (safePage - 1) * pageSize + 1;
1136
1279
  const to = Math.min(safePage * pageSize, total);
1137
1280
  const hasUnit = unitLabel !== void 0 && unitLabel !== "";
1281
+ const resolvedUnit = total === 1 && unitLabelSingular !== void 0 && unitLabelSingular !== "" ? unitLabelSingular : unitLabel;
1138
1282
  const hasPrefix = infoPrefix !== void 0 && infoPrefix !== "";
1139
1283
  const prefix = hasPrefix ? `${infoPrefix} ` : "";
1140
1284
  const ofWord = t(TABLE_I18N.pagerInfo);
1141
- const unitSuffix = hasUnit ? ` ${unitLabel}` : "";
1285
+ const unitSuffix = hasUnit ? ` ${resolvedUnit}` : "";
1142
1286
  const count = `${from.toLocaleString()}${EN_DASH}${to.toLocaleString()} ${ofWord} ${total.toLocaleString()}`;
1143
1287
  const info = `${prefix}${count}${unitSuffix}`;
1144
1288
  const boldStyle = { color: colors.text, fontWeight: BOLD };
@@ -1152,90 +1296,727 @@ function Pager({
1152
1296
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: boldStyle, children: total.toLocaleString() }),
1153
1297
  unitSuffix
1154
1298
  ] }) : info }),
1155
- /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [chromeStyles.pagerNav, o?.pagerNav], children: [
1156
- /* @__PURE__ */ jsxRuntime.jsx(
1157
- reactNative.Text,
1158
- {
1159
- style: [isDropdown ? chromeStyles.pagerRowsLabelPlain : chromeStyles.pagerRowsLabel, { color: colors.textSecondary }, o?.pagerRowsLabel],
1160
- children: t(TABLE_I18N.pagerRows)
1161
- }
1162
- ),
1163
- isDropdown ? /* @__PURE__ */ jsxRuntime.jsx(
1164
- SizeDropdown,
1299
+ /* @__PURE__ */ jsxRuntime.jsx(
1300
+ PagerNav,
1301
+ {
1302
+ pageSize,
1303
+ pageSizeOptions,
1304
+ onPageSizeChange,
1305
+ onPageChange,
1306
+ safePage,
1307
+ lastPage,
1308
+ isCompact,
1309
+ isDropdown,
1310
+ showFirstLast,
1311
+ testID,
1312
+ styleOverrides: o
1313
+ }
1314
+ )
1315
+ ] });
1316
+ }
1317
+ var FIELD_GAP = 4;
1318
+ var LABEL_FONT = 11;
1319
+ var LABEL_LETTER_SPACING2 = 0.4;
1320
+ var INPUT_RADIUS = 8;
1321
+ var INPUT_PAD_H = 12;
1322
+ var INPUT_PAD_V = 10;
1323
+ var INPUT_FONT = 14;
1324
+ var INPUT_BORDER = 1;
1325
+ var DATE_ROW_GAP = 8;
1326
+ var CHEVRON_FONT2 = 10;
1327
+ var MENU_TOP_GAP3 = 4;
1328
+ var MENU_RADIUS = 8;
1329
+ var MENU_PAD_V2 = 4;
1330
+ var MENU_OPT_PAD_H = 12;
1331
+ var MENU_OPT_PAD_V2 = 8;
1332
+ var MENU_MIN_WIDTH2 = 160;
1333
+ var MENU_MAX_HEIGHT = 260;
1334
+ var MENU_Z = 1e3;
1335
+ var MENU_ELEVATION2 = 8;
1336
+ var MENU_BOX_SHADOW2 = "0px 2px 8px rgba(0, 0, 0, 0.15)";
1337
+ var OPTION_FONT = 14;
1338
+ var ERROR_FONT = 12;
1339
+ var ERROR_GAP = 3;
1340
+ var SWITCH_ROW_GAP = 8;
1341
+ var ACTION_PAD_H = 14;
1342
+ var ACTION_PAD_V = 8;
1343
+ var ACTION_RADIUS = 8;
1344
+ var ACTION_FONT = 13;
1345
+ var filterStyles = reactNative.StyleSheet.create({
1346
+ field: { gap: FIELD_GAP },
1347
+ label: { fontSize: LABEL_FONT, fontWeight: "700", letterSpacing: LABEL_LETTER_SPACING2, textTransform: "uppercase" },
1348
+ input: {
1349
+ borderWidth: INPUT_BORDER,
1350
+ borderRadius: INPUT_RADIUS,
1351
+ paddingHorizontal: INPUT_PAD_H,
1352
+ paddingVertical: INPUT_PAD_V,
1353
+ fontSize: INPUT_FONT
1354
+ },
1355
+ /** The select trigger: a bordered field box matching the text inputs + a chevron. */
1356
+ selectTrigger: {
1357
+ flexDirection: "row",
1358
+ alignItems: "center",
1359
+ justifyContent: "space-between",
1360
+ gap: DATE_ROW_GAP,
1361
+ borderWidth: INPUT_BORDER,
1362
+ borderRadius: INPUT_RADIUS,
1363
+ paddingHorizontal: INPUT_PAD_H,
1364
+ paddingVertical: INPUT_PAD_V
1365
+ },
1366
+ selectTriggerText: { fontSize: INPUT_FONT, flexShrink: 1 },
1367
+ chevron: { fontSize: CHEVRON_FONT2 },
1368
+ dateRow: { flexDirection: "row", gap: DATE_ROW_GAP },
1369
+ dateCol: { gap: FIELD_GAP, flex: 1 },
1370
+ subLabel: { fontSize: LABEL_FONT, letterSpacing: LABEL_LETTER_SPACING2 },
1371
+ anchor: { position: "relative" },
1372
+ menu: {
1373
+ position: "absolute",
1374
+ top: "100%",
1375
+ left: 0,
1376
+ marginTop: MENU_TOP_GAP3,
1377
+ minWidth: MENU_MIN_WIDTH2,
1378
+ maxHeight: MENU_MAX_HEIGHT,
1379
+ borderWidth: INPUT_BORDER,
1380
+ borderRadius: MENU_RADIUS,
1381
+ paddingVertical: MENU_PAD_V2,
1382
+ zIndex: MENU_Z,
1383
+ boxShadow: MENU_BOX_SHADOW2,
1384
+ elevation: MENU_ELEVATION2,
1385
+ overflow: "hidden"
1386
+ },
1387
+ option: { paddingHorizontal: MENU_OPT_PAD_H, paddingVertical: MENU_OPT_PAD_V2 },
1388
+ optionText: { fontSize: OPTION_FONT },
1389
+ error: { fontSize: ERROR_FONT, marginTop: ERROR_GAP },
1390
+ switchRow: { flexDirection: "row", alignItems: "center", gap: SWITCH_ROW_GAP, paddingVertical: FIELD_GAP },
1391
+ action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth: INPUT_BORDER },
1392
+ actionText: { fontSize: ACTION_FONT, fontWeight: "600" }
1393
+ });
1394
+ var FILTER_HIT_SLOP = { top: 8, bottom: 8 };
1395
+ var DISABLED_OPACITY2 = 0.4;
1396
+ var FULL_OPACITY2 = 1;
1397
+ var TRANSPARENT3 = "transparent";
1398
+ function ActionButton({ label, hint, tone, disabled = false, onPress, testID }) {
1399
+ const { theme } = uiFeedback.useUi();
1400
+ const { colors, palette } = theme;
1401
+ const isPrimary = tone === "primary";
1402
+ const brand = palette.primary["500"];
1403
+ return /* @__PURE__ */ jsxRuntime.jsx(
1404
+ reactNative.Pressable,
1405
+ {
1406
+ accessibilityRole: "button",
1407
+ accessibilityLabel: label,
1408
+ accessibilityHint: hint,
1409
+ accessibilityState: { disabled },
1410
+ disabled,
1411
+ hitSlop: FILTER_HIT_SLOP,
1412
+ onPress,
1413
+ style: [
1414
+ filterStyles.action,
1165
1415
  {
1166
- pageSize,
1167
- pageSizeOptions,
1168
- onPageSizeChange,
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
1416
+ borderColor: isPrimary ? brand : colors.border,
1417
+ backgroundColor: isPrimary ? brand : TRANSPARENT3,
1418
+ opacity: disabled ? DISABLED_OPACITY2 : FULL_OPACITY2
1179
1419
  }
1180
- ) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [chromeStyles.sizeGroup, o?.sizeGroup], children: pageSizeOptions.map((size) => {
1181
- const active = size === pageSize;
1420
+ ],
1421
+ testID,
1422
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.actionText, { color: isPrimary ? colors.surface : colors.text }], children: label })
1423
+ }
1424
+ );
1425
+ }
1426
+
1427
+ // src/Filters/constants.ts
1428
+ var FILTERS_TEST_ID = "ui-filters-declarative";
1429
+ var FIELD_MIN_WIDTH = {
1430
+ select: 150,
1431
+ text: 200,
1432
+ number: 130,
1433
+ dateRange: 260,
1434
+ typeahead: 200,
1435
+ boolean: 150
1436
+ };
1437
+ var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
1438
+ var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
1439
+ var fieldTestID = (barTestID, key) => `${barTestID}-field-${key}`;
1440
+ var applyTestID = (barTestID) => `${barTestID}-apply`;
1441
+ var clearTestID = (barTestID) => `${barTestID}-clear`;
1442
+ var FILTERS_I18N = {
1443
+ apply: "uiTables.filters.apply",
1444
+ applyHint: "uiTables.filters.applyHint",
1445
+ clear: "uiTables.filters.clear",
1446
+ clearHint: "uiTables.filters.clearHint",
1447
+ selectPlaceholder: "uiTables.filters.selectPlaceholder",
1448
+ dropdownHint: "uiTables.filters.dropdownHint",
1449
+ optionHint: "uiTables.filters.optionHint",
1450
+ from: "uiTables.filters.from",
1451
+ to: "uiTables.filters.to"
1452
+ };
1453
+ var GROW_FLEX = 1;
1454
+ function FieldShell({ field, barTestID, children }) {
1455
+ const { theme } = uiFeedback.useUi();
1456
+ const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
1457
+ const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
1458
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1459
+ reactNative.View,
1460
+ {
1461
+ style: [filterStyles.field, { minWidth }, grow, field.style],
1462
+ testID: field.testID ?? fieldTestID(barTestID, field.key),
1463
+ children: [
1464
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.label, { color: theme.colors.textSecondary }], children: field.label }),
1465
+ children
1466
+ ]
1467
+ }
1468
+ );
1469
+ }
1470
+ function BooleanField({ field, barTestID, value, onChange }) {
1471
+ const { theme } = uiFeedback.useUi();
1472
+ const { colors, palette } = theme;
1473
+ const testID = field.testID ?? fieldTestID(barTestID, field.key);
1474
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.switchRow, testID, children: [
1475
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.subLabel, { color: colors.text }], children: field.label }),
1476
+ /* @__PURE__ */ jsxRuntime.jsx(
1477
+ reactNative.Switch,
1478
+ {
1479
+ accessibilityLabel: field.label,
1480
+ accessibilityHint: field.accessibilityHint,
1481
+ accessibilityRole: "switch",
1482
+ accessibilityState: { checked: value },
1483
+ trackColor: { false: colors.border, true: palette.primary["500"] },
1484
+ thumbColor: colors.surface,
1485
+ value,
1486
+ onValueChange: onChange,
1487
+ testID: `${testID}-switch`
1488
+ }
1489
+ )
1490
+ ] });
1491
+ }
1492
+ var WEB_DATE_PROPS = typeof document !== "undefined" ? { type: "date" } : {};
1493
+ function DateInput(p) {
1494
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.dateCol, children: [
1495
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.subLabel, { color: p.muted }], children: p.label }),
1496
+ /* @__PURE__ */ jsxRuntime.jsx(
1497
+ reactNative.TextInput,
1498
+ {
1499
+ accessibilityLabel: p.label,
1500
+ accessibilityHint: p.hint,
1501
+ placeholder: p.placeholder,
1502
+ placeholderTextColor: p.muted,
1503
+ value: p.value,
1504
+ onChangeText: p.onChangeText,
1505
+ onSubmitEditing: p.onSubmit,
1506
+ style: [filterStyles.input, { borderColor: p.border, backgroundColor: p.surface, color: p.color }],
1507
+ testID: `${p.testID}-${p.side}`,
1508
+ ...WEB_DATE_PROPS
1509
+ }
1510
+ )
1511
+ ] });
1512
+ }
1513
+ function DateRangeField({ field, barTestID, value, onChange, onSubmit, fromLabel, toLabel }) {
1514
+ const { theme } = uiFeedback.useUi();
1515
+ const { colors } = theme;
1516
+ const testID = field.testID ?? fieldTestID(barTestID, field.key);
1517
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.dateRow, testID: `${testID}-range`, children: [
1518
+ /* @__PURE__ */ jsxRuntime.jsx(
1519
+ DateInput,
1520
+ {
1521
+ side: "from",
1522
+ label: field.fromLabel ?? fromLabel,
1523
+ placeholder: field.fromPlaceholder,
1524
+ value: value.from,
1525
+ color: colors.text,
1526
+ border: colors.border,
1527
+ surface: colors.surface,
1528
+ muted: colors.textSecondary,
1529
+ hint: field.accessibilityHint,
1530
+ testID,
1531
+ onChangeText: (from) => onChange({ from, to: value.to }),
1532
+ onSubmit
1533
+ }
1534
+ ),
1535
+ /* @__PURE__ */ jsxRuntime.jsx(
1536
+ DateInput,
1537
+ {
1538
+ side: "to",
1539
+ label: field.toLabel ?? toLabel,
1540
+ placeholder: field.toPlaceholder,
1541
+ value: value.to,
1542
+ color: colors.text,
1543
+ border: colors.border,
1544
+ surface: colors.surface,
1545
+ muted: colors.textSecondary,
1546
+ hint: field.accessibilityHint,
1547
+ testID,
1548
+ onChangeText: (to) => onChange({ from: value.from, to }),
1549
+ onSubmit
1550
+ }
1551
+ )
1552
+ ] });
1553
+ }
1554
+ var IS_WEB3 = typeof document !== "undefined";
1555
+ var ESCAPE_KEY = "Escape";
1556
+ var ACTIVE_WEIGHT = "700";
1557
+ var IDLE_WEIGHT = "400";
1558
+ function useDismiss(anchorRef, menuRef, onDismiss) {
1559
+ React4.useEffect(() => {
1560
+ if (!IS_WEB3) return void 0;
1561
+ const onMouseDown = (event) => {
1562
+ const anchorNode = anchorRef.current;
1563
+ const menuNode = menuRef.current;
1564
+ const target = event.target instanceof Node ? event.target : null;
1565
+ const insideAnchor = anchorNode !== null && target !== null && anchorNode.contains(target);
1566
+ const insideMenu = menuNode !== null && target !== null && menuNode.contains(target);
1567
+ if (!insideAnchor && !insideMenu) onDismiss();
1568
+ };
1569
+ const onKeyDown = (event) => {
1570
+ if (event.key === ESCAPE_KEY) onDismiss();
1571
+ };
1572
+ document.addEventListener("mousedown", onMouseDown);
1573
+ document.addEventListener("keydown", onKeyDown);
1574
+ return () => {
1575
+ document.removeEventListener("mousedown", onMouseDown);
1576
+ document.removeEventListener("keydown", onKeyDown);
1577
+ };
1578
+ }, [anchorRef, menuRef, onDismiss]);
1579
+ }
1580
+ function AnchoredMenu({
1581
+ options,
1582
+ selectedValue,
1583
+ onSelect,
1584
+ onDismiss,
1585
+ colors,
1586
+ optionHint,
1587
+ testID,
1588
+ anchorRef
1589
+ }) {
1590
+ const menuRef = React4__default.default.useRef(null);
1591
+ useDismiss(anchorRef, menuRef, onDismiss);
1592
+ return /* @__PURE__ */ jsxRuntime.jsx(
1593
+ reactNative.View,
1594
+ {
1595
+ ref: menuRef,
1596
+ accessibilityRole: "menu",
1597
+ style: [filterStyles.menu, { borderColor: colors.border, backgroundColor: colors.surface }],
1598
+ testID: `${testID}-menu`,
1599
+ children: options.map((opt) => {
1600
+ const active = opt.value === selectedValue;
1182
1601
  return /* @__PURE__ */ jsxRuntime.jsx(
1183
1602
  reactNative.Pressable,
1184
1603
  {
1185
- testID: `${testID}-size-${size}`,
1186
- accessibilityRole: "button",
1187
- accessibilityLabel: String(size),
1188
- accessibilityHint: t(TABLE_I18N.pagerRowsOptionHint),
1604
+ accessibilityRole: "menuitem",
1605
+ accessibilityLabel: opt.label,
1606
+ accessibilityHint: optionHint,
1189
1607
  accessibilityState: { selected: active },
1190
- hitSlop: PAGER_HIT_SLOP,
1191
- onPress: () => onPageSizeChange(size),
1192
- style: [chromeStyles.sizePill, { borderColor: active ? brand : colors.border, backgroundColor: active ? brand : TRANSPARENT2 }, o?.sizePill],
1193
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [chromeStyles.sizePillText, { color: active ? colors.surface : colors.textSecondary }, o?.sizePillText], children: size })
1608
+ onPress: () => onSelect(opt.value),
1609
+ style: filterStyles.option,
1610
+ testID: `${testID}-option-${opt.value}`,
1611
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.optionText, { color: active ? colors.brand : colors.text, fontWeight: active ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: opt.label })
1194
1612
  },
1195
- size
1613
+ opt.value
1196
1614
  );
1197
- }) }),
1198
- /* @__PURE__ */ jsxRuntime.jsx(
1199
- NavButton,
1200
- {
1201
- label: t(TABLE_I18N.pagerPrev),
1202
- hint: t(TABLE_I18N.pagerPrevHint),
1203
- disabled: safePage <= FIRST_PAGE,
1204
- onPress: () => onPageChange(safePage - 1),
1205
- color: colors.text,
1206
- border: colors.border,
1207
- styleOverrides: o,
1208
- testID: TABLE_TEST_IDS.pagerPrev
1209
- }
1210
- ),
1211
- /* @__PURE__ */ jsxRuntime.jsx(
1212
- NavButton,
1213
- {
1214
- label: t(TABLE_I18N.pagerNext),
1215
- hint: t(TABLE_I18N.pagerNextHint),
1216
- disabled: safePage >= lastPage,
1217
- onPress: () => onPageChange(safePage + 1),
1218
- color: colors.text,
1219
- border: colors.border,
1220
- styleOverrides: o,
1221
- testID: TABLE_TEST_IDS.pagerNext
1615
+ })
1616
+ }
1617
+ );
1618
+ }
1619
+ var CHEVRON_DOWN2 = "\u25BE";
1620
+ var CHEVRON_UP2 = "\u25B4";
1621
+ function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
1622
+ const { theme } = uiFeedback.useUi();
1623
+ const { colors, palette } = theme;
1624
+ const anchorRef = React4.useRef(null);
1625
+ const [isOpen, setIsOpen] = React4.useState(false);
1626
+ const testID = field.testID ?? fieldTestID(barTestID, field.key);
1627
+ const selectedLabel = React4.useMemo(() => {
1628
+ const found = field.options.find((o) => o.value === value);
1629
+ return found?.label ?? field.placeholder ?? placeholder;
1630
+ }, [field.options, field.placeholder, placeholder, value]);
1631
+ const close = React4.useCallback(() => {
1632
+ setIsOpen(false);
1633
+ }, []);
1634
+ const toggle = React4.useCallback(() => {
1635
+ setIsOpen((prev) => !prev);
1636
+ }, []);
1637
+ const select = React4.useCallback(
1638
+ (next) => {
1639
+ onChange(next);
1640
+ setIsOpen(false);
1641
+ },
1642
+ [onChange]
1643
+ );
1644
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: filterStyles.anchor, children: [
1645
+ /* @__PURE__ */ jsxRuntime.jsxs(
1646
+ reactNative.Pressable,
1647
+ {
1648
+ accessibilityRole: "button",
1649
+ accessibilityLabel: field.label,
1650
+ accessibilityHint: field.accessibilityHint ?? dropdownHint,
1651
+ accessibilityState: { expanded: isOpen },
1652
+ "aria-expanded": isOpen,
1653
+ onPress: toggle,
1654
+ style: [filterStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surface }],
1655
+ testID: `${testID}-trigger`,
1656
+ children: [
1657
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [filterStyles.selectTriggerText, { color: value === "" ? colors.textSecondary : colors.text }], children: selectedLabel }),
1658
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { "aria-hidden": true, style: [filterStyles.chevron, { color: colors.textSecondary }], children: isOpen ? CHEVRON_UP2 : CHEVRON_DOWN2 })
1659
+ ]
1660
+ }
1661
+ ),
1662
+ isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
1663
+ AnchoredMenu,
1664
+ {
1665
+ options: field.options,
1666
+ selectedValue: value,
1667
+ onSelect: select,
1668
+ onDismiss: close,
1669
+ colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
1670
+ optionHint,
1671
+ testID,
1672
+ anchorRef
1673
+ }
1674
+ ) : null
1675
+ ] });
1676
+ }
1677
+ function TextField({ field, barTestID, value, onChange, onSubmit }) {
1678
+ const { theme } = uiFeedback.useUi();
1679
+ const { colors } = theme;
1680
+ const isNumber = field.kind === "number";
1681
+ return /* @__PURE__ */ jsxRuntime.jsx(
1682
+ reactNative.TextInput,
1683
+ {
1684
+ accessibilityLabel: field.label,
1685
+ accessibilityHint: field.accessibilityHint,
1686
+ keyboardType: isNumber ? "numeric" : "default",
1687
+ placeholder: field.placeholder,
1688
+ placeholderTextColor: colors.textSecondary,
1689
+ value,
1690
+ onChangeText: onChange,
1691
+ onSubmitEditing: onSubmit,
1692
+ style: [filterStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }],
1693
+ testID: `${field.testID ?? fieldTestID(barTestID, field.key)}-input`
1694
+ }
1695
+ );
1696
+ }
1697
+
1698
+ // src/Filters/utils/suggest.ts
1699
+ var RANK_VALUE_EXACT = 0;
1700
+ var RANK_VALUE_PREFIX = 1;
1701
+ var RANK_LABEL_PREFIX = 2;
1702
+ var RANK_LABEL_CONTAINS = 3;
1703
+ var NO_MATCH = -1;
1704
+ function rankOf(option, needle) {
1705
+ const value = option.value.toLowerCase();
1706
+ const label = option.label.toLowerCase();
1707
+ if (value === needle) return RANK_VALUE_EXACT;
1708
+ if (value.startsWith(needle)) return RANK_VALUE_PREFIX;
1709
+ if (label.startsWith(needle)) return RANK_LABEL_PREFIX;
1710
+ if (label.includes(needle)) return RANK_LABEL_CONTAINS;
1711
+ return NO_MATCH;
1712
+ }
1713
+ function suggestOptions(options, query, minChars, limit) {
1714
+ const needle = query.trim().toLowerCase();
1715
+ if (needle.length < minChars) return [];
1716
+ const scored = [];
1717
+ for (const option of options) {
1718
+ const rank = rankOf(option, needle);
1719
+ if (rank !== NO_MATCH) scored.push({ option, rank });
1720
+ }
1721
+ scored.sort((a, b) => a.rank !== b.rank ? a.rank - b.rank : a.option.label.localeCompare(b.option.label));
1722
+ return scored.slice(0, limit).map((entry) => entry.option);
1723
+ }
1724
+ function isUnmatched(options, text) {
1725
+ const needle = text.trim().toLowerCase();
1726
+ if (needle === "") return false;
1727
+ return !options.some((o) => o.value.toLowerCase() === needle || o.label.toLowerCase() === needle);
1728
+ }
1729
+ var CLOSE_DELAY_MS = 140;
1730
+ function TypeaheadField({ field, barTestID, value, onChange, onSubmit, optionHint }) {
1731
+ const { theme } = uiFeedback.useUi();
1732
+ const { colors, palette, semantic } = theme;
1733
+ const anchorRef = React4.useRef(null);
1734
+ const [isOpen, setIsOpen] = React4.useState(false);
1735
+ const testID = field.testID ?? fieldTestID(barTestID, field.key);
1736
+ const minChars = field.minChars ?? DEFAULT_TYPEAHEAD_MIN_CHARS;
1737
+ const maxSuggestions = field.maxSuggestions ?? DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
1738
+ const exactPick = React4.useMemo(
1739
+ () => field.options.some((o) => o.label === value),
1740
+ [field.options, value]
1741
+ );
1742
+ const suggestions = React4.useMemo(
1743
+ () => exactPick ? [] : suggestOptions(field.options, value, minChars, maxSuggestions),
1744
+ [exactPick, field.options, value, minChars, maxSuggestions]
1745
+ );
1746
+ const showMenu = isOpen && suggestions.length > 0;
1747
+ const handleChange = React4.useCallback(
1748
+ (next) => {
1749
+ onChange(next);
1750
+ setIsOpen(true);
1751
+ },
1752
+ [onChange]
1753
+ );
1754
+ const pick = React4.useCallback(
1755
+ (optionValue) => {
1756
+ const opt = field.options.find((o) => o.value === optionValue);
1757
+ onChange(opt?.label ?? optionValue);
1758
+ setIsOpen(false);
1759
+ },
1760
+ [field.options, onChange]
1761
+ );
1762
+ const handleBlur = React4.useCallback(() => {
1763
+ setTimeout(() => setIsOpen(false), CLOSE_DELAY_MS);
1764
+ }, []);
1765
+ const handleSubmit = React4.useCallback(() => {
1766
+ setIsOpen(false);
1767
+ onSubmit();
1768
+ }, [onSubmit]);
1769
+ const hasError = field.error !== void 0 && field.error !== "";
1770
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: filterStyles.anchor, children: [
1771
+ /* @__PURE__ */ jsxRuntime.jsx(
1772
+ reactNative.TextInput,
1773
+ {
1774
+ accessibilityLabel: field.label,
1775
+ accessibilityHint: field.accessibilityHint,
1776
+ autoCapitalize: "none",
1777
+ autoCorrect: false,
1778
+ placeholder: field.placeholder,
1779
+ placeholderTextColor: colors.textSecondary,
1780
+ spellCheck: false,
1781
+ value,
1782
+ onChangeText: handleChange,
1783
+ onFocus: () => setIsOpen(true),
1784
+ onBlur: handleBlur,
1785
+ onSubmitEditing: handleSubmit,
1786
+ style: [filterStyles.input, { borderColor: hasError ? semantic.error["500"] : colors.border, backgroundColor: colors.surface, color: colors.text }],
1787
+ testID: `${testID}-input`
1788
+ }
1789
+ ),
1790
+ showMenu ? /* @__PURE__ */ jsxRuntime.jsx(
1791
+ AnchoredMenu,
1792
+ {
1793
+ options: suggestions,
1794
+ selectedValue: value,
1795
+ onSelect: pick,
1796
+ onDismiss: () => setIsOpen(false),
1797
+ colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
1798
+ optionHint,
1799
+ testID,
1800
+ anchorRef
1801
+ }
1802
+ ) : null,
1803
+ hasError ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [filterStyles.error, { color: semantic.error["500"] }], testID: `${testID}-error`, children: field.error }) : null
1804
+ ] });
1805
+ }
1806
+ var EMPTY_RANGE = { from: "", to: "" };
1807
+ function asString(value) {
1808
+ return typeof value === "string" ? value : "";
1809
+ }
1810
+ function asBool(value) {
1811
+ return value === true;
1812
+ }
1813
+ function asRange(value) {
1814
+ if (typeof value === "object" && value !== null && "from" in value && "to" in value) return value;
1815
+ return EMPTY_RANGE;
1816
+ }
1817
+ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings, renderSelect }) {
1818
+ const raw = values[field.key];
1819
+ if (field.kind === "boolean") {
1820
+ return /* @__PURE__ */ jsxRuntime.jsx(BooleanField, { field, barTestID, value: asBool(raw), onChange: (v) => setField(field.key, v) });
1821
+ }
1822
+ const body = (() => {
1823
+ switch (field.kind) {
1824
+ case "select":
1825
+ if (renderSelect !== void 0) {
1826
+ return renderSelect({
1827
+ field,
1828
+ value: asString(raw),
1829
+ onChange: (v) => setField(field.key, v),
1830
+ testID: field.testID ?? fieldTestID(barTestID, field.key)
1831
+ });
1222
1832
  }
1223
- )
1224
- ] })
1833
+ return /* @__PURE__ */ jsxRuntime.jsx(
1834
+ SelectField,
1835
+ {
1836
+ field,
1837
+ barTestID,
1838
+ value: asString(raw),
1839
+ onChange: (v) => setField(field.key, v),
1840
+ placeholder: strings.selectPlaceholder,
1841
+ dropdownHint: strings.dropdownHint,
1842
+ optionHint: strings.optionHint
1843
+ }
1844
+ );
1845
+ case "typeahead":
1846
+ return /* @__PURE__ */ jsxRuntime.jsx(
1847
+ TypeaheadField,
1848
+ {
1849
+ field,
1850
+ barTestID,
1851
+ value: asString(raw),
1852
+ onChange: (v) => setField(field.key, v),
1853
+ onSubmit,
1854
+ optionHint: strings.optionHint
1855
+ }
1856
+ );
1857
+ case "dateRange":
1858
+ return /* @__PURE__ */ jsxRuntime.jsx(
1859
+ DateRangeField,
1860
+ {
1861
+ field,
1862
+ barTestID,
1863
+ value: asRange(raw),
1864
+ onChange: (v) => setField(field.key, v),
1865
+ onSubmit,
1866
+ fromLabel: strings.fromLabel,
1867
+ toLabel: strings.toLabel
1868
+ }
1869
+ );
1870
+ default:
1871
+ return /* @__PURE__ */ jsxRuntime.jsx(
1872
+ TextField,
1873
+ {
1874
+ field,
1875
+ barTestID,
1876
+ value: asString(raw),
1877
+ onChange: (v) => setField(field.key, v),
1878
+ onSubmit
1879
+ }
1880
+ );
1881
+ }
1882
+ })();
1883
+ return /* @__PURE__ */ jsxRuntime.jsx(FieldShell, { field, barTestID, children: body });
1884
+ }
1885
+ function Filters({
1886
+ fields,
1887
+ values,
1888
+ onChange,
1889
+ resultsCount,
1890
+ resultsLabel,
1891
+ onApply,
1892
+ applyLabel,
1893
+ applyHint,
1894
+ applyDisabled = false,
1895
+ onClear,
1896
+ clearLabel,
1897
+ clearHint,
1898
+ actions,
1899
+ selectPlaceholder,
1900
+ fromLabel,
1901
+ toLabel,
1902
+ renderSelect,
1903
+ styleOverrides,
1904
+ testID = FILTERS_TEST_ID
1905
+ }) {
1906
+ const { t } = uiFeedback.useUi();
1907
+ const setField = React4.useCallback(
1908
+ (key, value) => {
1909
+ onChange({ ...values, [key]: value });
1910
+ },
1911
+ [onChange, values]
1912
+ );
1913
+ const onSubmit = React4.useCallback(() => {
1914
+ if (onApply !== void 0 && !applyDisabled) onApply();
1915
+ }, [onApply, applyDisabled]);
1916
+ const strings = React4.useMemo(
1917
+ () => ({
1918
+ selectPlaceholder: selectPlaceholder ?? t(FILTERS_I18N.selectPlaceholder),
1919
+ dropdownHint: t(FILTERS_I18N.dropdownHint),
1920
+ optionHint: t(FILTERS_I18N.optionHint),
1921
+ fromLabel: fromLabel ?? t(FILTERS_I18N.from),
1922
+ toLabel: toLabel ?? t(FILTERS_I18N.to)
1923
+ }),
1924
+ [selectPlaceholder, fromLabel, toLabel, t]
1925
+ );
1926
+ const barActions = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1927
+ actions,
1928
+ onClear !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
1929
+ ActionButton,
1930
+ {
1931
+ label: clearLabel ?? t(FILTERS_I18N.clear),
1932
+ hint: clearHint ?? t(FILTERS_I18N.clearHint),
1933
+ tone: "ghost",
1934
+ onPress: onClear,
1935
+ testID: clearTestID(testID)
1936
+ }
1937
+ ),
1938
+ onApply !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
1939
+ ActionButton,
1940
+ {
1941
+ label: applyLabel ?? t(FILTERS_I18N.apply),
1942
+ hint: applyHint ?? t(FILTERS_I18N.applyHint),
1943
+ tone: "primary",
1944
+ disabled: applyDisabled,
1945
+ onPress: onApply,
1946
+ testID: applyTestID(testID)
1947
+ }
1948
+ )
1225
1949
  ] });
1950
+ const hasActions = actions !== void 0 || onClear !== void 0 || onApply !== void 0;
1951
+ return /* @__PURE__ */ jsxRuntime.jsx(
1952
+ FilterBar,
1953
+ {
1954
+ resultsCount,
1955
+ resultsLabel,
1956
+ actions: hasActions ? barActions : void 0,
1957
+ styleOverrides,
1958
+ testID,
1959
+ children: fields.map((field) => /* @__PURE__ */ jsxRuntime.jsx(
1960
+ FilterFieldView,
1961
+ {
1962
+ field,
1963
+ barTestID: testID,
1964
+ values,
1965
+ setField,
1966
+ onSubmit,
1967
+ strings,
1968
+ renderSelect
1969
+ },
1970
+ field.key
1971
+ ))
1972
+ }
1973
+ );
1974
+ }
1975
+ function shallowEqual(a, b) {
1976
+ return JSON.stringify(a) === JSON.stringify(b);
1977
+ }
1978
+ function useFilterDraft({ initial, onApply, onReset }) {
1979
+ const [draft, setDraft] = React4.useState(initial);
1980
+ const [committed, setCommitted] = React4.useState(initial);
1981
+ const setField = React4.useCallback((key, value) => {
1982
+ setDraft((prev) => ({ ...prev, [key]: value }));
1983
+ }, []);
1984
+ const apply = React4.useCallback(() => {
1985
+ setCommitted(draft);
1986
+ onApply?.(draft);
1987
+ }, [draft, onApply]);
1988
+ const reset = React4.useCallback(() => {
1989
+ setDraft(initial);
1990
+ setCommitted(initial);
1991
+ onReset?.();
1992
+ }, [initial, onReset]);
1993
+ const dirty = React4.useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
1994
+ return { draft, committed, setField, setDraft, apply, reset, dirty };
1226
1995
  }
1227
1996
 
1228
1997
  exports.CARD_STACK_BREAKPOINT = CARD_STACK_BREAKPOINT;
1229
1998
  exports.DEFAULT_PAGE_SIZE_OPTIONS = DEFAULT_PAGE_SIZE_OPTIONS;
1999
+ exports.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
2000
+ exports.DEFAULT_TYPEAHEAD_MIN_CHARS = DEFAULT_TYPEAHEAD_MIN_CHARS;
1230
2001
  exports.DataTable = DataTable;
2002
+ exports.FIELD_MIN_WIDTH = FIELD_MIN_WIDTH;
2003
+ exports.FILTERS_I18N = FILTERS_I18N;
2004
+ exports.FILTERS_TEST_ID = FILTERS_TEST_ID;
1231
2005
  exports.FilterBar = FilterBar;
2006
+ exports.Filters = Filters;
1232
2007
  exports.Pager = Pager;
1233
2008
  exports.StatCard = StatCard;
1234
2009
  exports.TABLE_I18N = TABLE_I18N;
1235
2010
  exports.TABLE_TEST_IDS = TABLE_TEST_IDS;
2011
+ exports.applyTestID = applyTestID;
2012
+ exports.clearTestID = clearTestID;
2013
+ exports.fieldTestID = fieldTestID;
2014
+ exports.isUnmatched = isUnmatched;
1236
2015
  exports.rowDetailTestID = rowDetailTestID;
1237
2016
  exports.rowSelectTestID = rowSelectTestID;
1238
2017
  exports.rowTestID = rowTestID;
1239
2018
  exports.selectAllTestID = selectAllTestID;
2019
+ exports.suggestOptions = suggestOptions;
2020
+ exports.useFilterDraft = useFilterDraft;
1240
2021
  //# sourceMappingURL=index.js.map
1241
2022
  //# sourceMappingURL=index.js.map