@dloizides/ui-tables 1.13.0 → 1.14.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,14 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var React4 = require('react');
3
+ var react = 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
-
9
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
-
11
- var React4__default = /*#__PURE__*/_interopDefault(React4);
8
+ var uiForms = require('@dloizides/ui-forms');
12
9
 
13
10
  // src/StatCard/StatCard.tsx
14
11
 
@@ -123,7 +120,7 @@ var styles = reactNative.StyleSheet.create({
123
120
  lineHeight: VALUE_LINE_HEIGHT
124
121
  }
125
122
  });
126
- var StatCard = React4.memo(({ label, value, testID }) => {
123
+ var StatCard = react.memo(({ label, value, testID }) => {
127
124
  const { theme, t } = uiFeedback.useUi();
128
125
  const { colors } = theme;
129
126
  const formattedValue = value.toLocaleString();
@@ -655,21 +652,21 @@ var TAB_INDEX_ACTIVE = 0;
655
652
  var TAB_INDEX_INACTIVE2 = -1;
656
653
  var IS_WEB = reactNative.Platform.OS === "web";
657
654
  function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
658
- const [focusedKey, setFocusedKey] = React4.useState(void 0);
659
- const nodes = React4.useRef(/* @__PURE__ */ new Map());
655
+ const [focusedKey, setFocusedKey] = react.useState(void 0);
656
+ const nodes = react.useRef(/* @__PURE__ */ new Map());
660
657
  const tabbableKey = enabled ? resolveTabbableKey(rowKeys, focusedKey) : void 0;
661
- const registerRow = React4.useCallback((key, node) => {
658
+ const registerRow = react.useCallback((key, node) => {
662
659
  if (node === null || node === void 0) {
663
660
  nodes.current.delete(key);
664
661
  return;
665
662
  }
666
663
  nodes.current.set(key, node);
667
664
  }, []);
668
- const focusRow = React4.useCallback((key) => {
665
+ const focusRow = react.useCallback((key) => {
669
666
  setFocusedKey(key);
670
667
  nodes.current.get(key)?.focus?.();
671
668
  }, []);
672
- const handleKey = React4.useCallback(
669
+ const handleKey = react.useCallback(
673
670
  (event, key) => {
674
671
  const action = toRowNavAction(event.key);
675
672
  if (action === void 0) return;
@@ -694,18 +691,18 @@ function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
694
691
  },
695
692
  [rowKeys, onToggleKey, onActivateKey, focusRow]
696
693
  );
697
- const keyDownFor = React4.useCallback(
694
+ const keyDownFor = react.useCallback(
698
695
  (key) => {
699
696
  if (!enabled || !IS_WEB) return void 0;
700
697
  return (event) => handleKey(event, key);
701
698
  },
702
699
  [enabled, handleKey]
703
700
  );
704
- const tabIndexFor = React4.useCallback(
701
+ const tabIndexFor = react.useCallback(
705
702
  (key) => key === tabbableKey ? TAB_INDEX_ACTIVE : TAB_INDEX_INACTIVE2,
706
703
  [tabbableKey]
707
704
  );
708
- const onRowFocus = React4.useCallback((key) => setFocusedKey(key), []);
705
+ const onRowFocus = react.useCallback((key) => setFocusedKey(key), []);
709
706
  return { tabIndexFor, registerRow, onRowFocus, keyDownFor };
710
707
  }
711
708
 
@@ -757,20 +754,20 @@ function useTableSelection({
757
754
  const selected = selectedRowKeys ?? NO_KEYS;
758
755
  const allMatching = allMatchingSelected ?? false;
759
756
  const matching = matchingCount ?? NO_MATCHES;
760
- const pageHeaderState = React4.useMemo(
757
+ const pageHeaderState = react.useMemo(
761
758
  () => resolveHeaderCheckboxState(selected, pageKeys),
762
759
  [selected, pageKeys]
763
760
  );
764
761
  const headerState = allMatching ? "all" /* All */ : pageHeaderState;
765
- const bannerMode = React4.useMemo(
762
+ const bannerMode = react.useMemo(
766
763
  () => onSelectAllMatchingChange === void 0 ? "hidden" /* Hidden */ : resolveSelectAllBannerMode(pageHeaderState, allMatching, pageKeys.length, matching),
767
764
  [onSelectAllMatchingChange, pageHeaderState, allMatching, pageKeys.length, matching]
768
765
  );
769
- const isSelected = React4.useCallback(
766
+ const isSelected = react.useCallback(
770
767
  (key) => isRowSelected(selected, key, allMatching),
771
768
  [selected, allMatching]
772
769
  );
773
- const toggleRow = React4.useCallback(
770
+ const toggleRow = react.useCallback(
774
771
  (key) => {
775
772
  if (allMatching) {
776
773
  onSelectAllMatchingChange?.(false);
@@ -781,7 +778,7 @@ function useTableSelection({
781
778
  },
782
779
  [allMatching, onSelectAllMatchingChange, onSelectionChange, pageKeys, selected]
783
780
  );
784
- const toggleAll = React4.useCallback(() => {
781
+ const toggleAll = react.useCallback(() => {
785
782
  if (allMatching) {
786
783
  onSelectAllMatchingChange?.(false);
787
784
  onSelectionChange?.(NO_KEYS);
@@ -789,7 +786,7 @@ function useTableSelection({
789
786
  }
790
787
  onSelectionChange?.(toggleAllOnPage(selected, pageKeys));
791
788
  }, [allMatching, onSelectAllMatchingChange, onSelectionChange, selected, pageKeys]);
792
- const toggleAllMatching = React4.useCallback(() => {
789
+ const toggleAllMatching = react.useCallback(() => {
793
790
  const next = !allMatching;
794
791
  onSelectAllMatchingChange?.(next);
795
792
  if (!next) onSelectionChange?.(NO_KEYS);
@@ -830,9 +827,9 @@ function DataTable(props) {
830
827
  const stacked = width < stackBreakpoint;
831
828
  const frame = { backgroundColor: colors.surface, borderColor: colors.border };
832
829
  const interactive = onRowPress !== void 0;
833
- const [hoveredKey, setHoveredKey] = React4.useState(void 0);
830
+ const [hoveredKey, setHoveredKey] = react.useState(void 0);
834
831
  const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
835
- const rowKeys = React4.useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
832
+ const rowKeys = react.useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
836
833
  const selection = useTableSelection({
837
834
  pageKeys: rowKeys,
838
835
  selectedRowKeys,
@@ -841,7 +838,7 @@ function DataTable(props) {
841
838
  allMatchingSelected,
842
839
  onSelectAllMatchingChange
843
840
  });
844
- const activateKey = React4.useCallback(
841
+ const activateKey = react.useCallback(
845
842
  (key) => {
846
843
  const row = rows[rowKeys.indexOf(key)];
847
844
  if (row !== void 0) onRowPress?.(row);
@@ -854,7 +851,7 @@ function DataTable(props) {
854
851
  onToggleKey: selection.selectable ? selection.toggleRow : void 0,
855
852
  onActivateKey: interactive ? activateKey : void 0
856
853
  });
857
- const rowBackground = React4.useCallback(
854
+ const rowBackground = react.useCallback(
858
855
  (row, index) => {
859
856
  const tint = rowTint?.(row);
860
857
  if (tint) return tint;
@@ -1005,8 +1002,8 @@ function buildWebFixedStyle(rect, viewportWidth) {
1005
1002
  };
1006
1003
  }
1007
1004
  function useTriggerRect(anchorRef, isOpen) {
1008
- const [rect, setRect] = React4.useState(null);
1009
- React4.useLayoutEffect(() => {
1005
+ const [rect, setRect] = react.useState(null);
1006
+ react.useLayoutEffect(() => {
1010
1007
  if (!IS_WEB2 || !isOpen) return void 0;
1011
1008
  const measure = () => {
1012
1009
  setRect(readTriggerRect(anchorRef));
@@ -1022,7 +1019,7 @@ function useTriggerRect(anchorRef, isOpen) {
1022
1019
  return rect;
1023
1020
  }
1024
1021
  function useDismissOnOutside(anchorRef, menuRef, isOpen, onClose) {
1025
- React4.useEffect(() => {
1022
+ react.useEffect(() => {
1026
1023
  if (!IS_WEB2 || !isOpen) return void 0;
1027
1024
  const onMouseDown = (event) => {
1028
1025
  const anchorNode = anchorRef.current;
@@ -1060,16 +1057,16 @@ function SizeDropdown({
1060
1057
  triggerStyle,
1061
1058
  triggerTextStyle
1062
1059
  }) {
1063
- const anchorRef = React4.useRef(null);
1064
- const menuRef = React4.useRef(null);
1065
- const [isOpen, setIsOpen] = React4.useState(false);
1066
- const close = React4.useCallback(() => {
1060
+ const anchorRef = react.useRef(null);
1061
+ const menuRef = react.useRef(null);
1062
+ const [isOpen, setIsOpen] = react.useState(false);
1063
+ const close = react.useCallback(() => {
1067
1064
  setIsOpen(false);
1068
1065
  }, []);
1069
- const toggle = React4.useCallback(() => {
1066
+ const toggle = react.useCallback(() => {
1070
1067
  setIsOpen((prev) => !prev);
1071
1068
  }, []);
1072
- const select = React4.useCallback(
1069
+ const select = react.useCallback(
1073
1070
  (size) => {
1074
1071
  onPageSizeChange(size);
1075
1072
  setIsOpen(false);
@@ -1353,80 +1350,23 @@ function Pager({
1353
1350
  ] });
1354
1351
  }
1355
1352
  var FIELD_GAP = 4;
1356
- var LABEL_FONT = 11;
1357
- var LABEL_LETTER_SPACING2 = 0.4;
1358
- var INPUT_RADIUS = 8;
1359
- var INPUT_PAD_H = 12;
1360
- var INPUT_PAD_V = 10;
1361
- var INPUT_FONT = 14;
1362
- var INPUT_BORDER = 1;
1363
- var DATE_ROW_GAP = 8;
1364
- var CHEVRON_FONT2 = 10;
1365
- var MENU_TOP_GAP3 = 4;
1366
- var MENU_RADIUS = 8;
1367
- var MENU_PAD_V2 = 4;
1368
- var MENU_OPT_PAD_H = 12;
1369
- var MENU_OPT_PAD_V2 = 8;
1370
- var MENU_MIN_WIDTH2 = 160;
1371
- var MENU_MAX_HEIGHT = 260;
1372
- var MENU_Z = 1e3;
1373
- var MENU_ELEVATION2 = 8;
1374
- var MENU_BOX_SHADOW2 = "0px 2px 8px rgba(0, 0, 0, 0.15)";
1375
- var OPTION_FONT = 14;
1376
- var ERROR_FONT = 12;
1377
- var ERROR_GAP = 3;
1378
1353
  var SWITCH_ROW_GAP = 8;
1379
1354
  var ACTION_PAD_H = 14;
1380
1355
  var ACTION_PAD_V = 8;
1381
1356
  var ACTION_RADIUS = 8;
1382
1357
  var ACTION_FONT = 13;
1358
+ var ACTION_BORDER = 1;
1359
+ var NO_FORM_RHYTHM = 0;
1383
1360
  var filterStyles = reactNative.StyleSheet.create({
1384
- field: { gap: FIELD_GAP },
1385
- label: { fontSize: LABEL_FONT, fontWeight: "700", letterSpacing: LABEL_LETTER_SPACING2, textTransform: "uppercase" },
1386
- input: {
1387
- borderWidth: INPUT_BORDER,
1388
- borderRadius: INPUT_RADIUS,
1389
- paddingHorizontal: INPUT_PAD_H,
1390
- paddingVertical: INPUT_PAD_V,
1391
- fontSize: INPUT_FONT
1392
- },
1393
- /** The select trigger: a bordered field box matching the text inputs + a chevron. */
1394
- selectTrigger: {
1395
- flexDirection: "row",
1396
- alignItems: "center",
1397
- justifyContent: "space-between",
1398
- gap: DATE_ROW_GAP,
1399
- borderWidth: INPUT_BORDER,
1400
- borderRadius: INPUT_RADIUS,
1401
- paddingHorizontal: INPUT_PAD_H,
1402
- paddingVertical: INPUT_PAD_V
1403
- },
1404
- selectTriggerText: { fontSize: INPUT_FONT, flexShrink: 1 },
1405
- chevron: { fontSize: CHEVRON_FONT2 },
1406
- dateRow: { flexDirection: "row", gap: DATE_ROW_GAP },
1407
- dateCol: { gap: FIELD_GAP, flex: 1 },
1408
- subLabel: { fontSize: LABEL_FONT, letterSpacing: LABEL_LETTER_SPACING2 },
1409
- anchor: { position: "relative" },
1410
- menu: {
1411
- position: "absolute",
1412
- top: "100%",
1413
- left: 0,
1414
- marginTop: MENU_TOP_GAP3,
1415
- minWidth: MENU_MIN_WIDTH2,
1416
- maxHeight: MENU_MAX_HEIGHT,
1417
- borderWidth: INPUT_BORDER,
1418
- borderRadius: MENU_RADIUS,
1419
- paddingVertical: MENU_PAD_V2,
1420
- zIndex: MENU_Z,
1421
- boxShadow: MENU_BOX_SHADOW2,
1422
- elevation: MENU_ELEVATION2,
1423
- overflow: "hidden"
1424
- },
1425
- option: { paddingHorizontal: MENU_OPT_PAD_H, paddingVertical: MENU_OPT_PAD_V2 },
1426
- optionText: { fontSize: OPTION_FONT },
1427
- error: { fontSize: ERROR_FONT, marginTop: ERROR_GAP },
1361
+ /**
1362
+ * Merged onto `Field`'s container inside the bar. Zeroes the 16px bottom margin `Field` gives
1363
+ * a stacked form row: the bar is a flex ROW whose spacing comes from FilterBar's `gap`, so
1364
+ * inheriting the form rhythm would add a phantom gap under every field — a pixel change for
1365
+ * six live portals, which this wave must not make.
1366
+ */
1367
+ fieldInBar: { marginBottom: NO_FORM_RHYTHM },
1428
1368
  switchRow: { flexDirection: "row", alignItems: "center", gap: SWITCH_ROW_GAP, paddingVertical: FIELD_GAP },
1429
- action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth: INPUT_BORDER },
1369
+ action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth: ACTION_BORDER },
1430
1370
  actionText: { fontSize: ACTION_FONT, fontWeight: "600" }
1431
1371
  });
1432
1372
  var FILTER_HIT_SLOP = { top: 8, bottom: 8 };
@@ -1461,8 +1401,6 @@ function ActionButton({ label, hint, tone, disabled = false, onPress, testID })
1461
1401
  }
1462
1402
  );
1463
1403
  }
1464
-
1465
- // src/Filters/constants.ts
1466
1404
  var FILTERS_TEST_ID = "ui-filters-declarative";
1467
1405
  var FIELD_MIN_WIDTH = {
1468
1406
  select: 150,
@@ -1472,8 +1410,6 @@ var FIELD_MIN_WIDTH = {
1472
1410
  typeahead: 200,
1473
1411
  boolean: 150
1474
1412
  };
1475
- var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
1476
- var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
1477
1413
  var fieldTestID = (barTestID, key) => `${barTestID}-field-${key}`;
1478
1414
  var applyTestID = (barTestID) => `${barTestID}-apply`;
1479
1415
  var clearTestID = (barTestID) => `${barTestID}-clear`;
@@ -1495,29 +1431,12 @@ var FILTERS_I18N = {
1495
1431
  from: "uiTables.filters.from",
1496
1432
  to: "uiTables.filters.to"
1497
1433
  };
1498
- var GROW_FLEX = 1;
1499
- function FieldShell({ field, barTestID, children }) {
1500
- const { theme } = uiFeedback.useUi();
1501
- const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
1502
- const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
1503
- return /* @__PURE__ */ jsxRuntime.jsxs(
1504
- reactNative.View,
1505
- {
1506
- style: [filterStyles.field, { minWidth }, grow, field.style],
1507
- testID: field.testID ?? fieldTestID(barTestID, field.key),
1508
- children: [
1509
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.label, { color: theme.colors.textSecondary }], children: field.label }),
1510
- children
1511
- ]
1512
- }
1513
- );
1514
- }
1515
1434
  function BooleanField({ field, barTestID, value, onChange }) {
1516
1435
  const { theme } = uiFeedback.useUi();
1517
1436
  const { colors, palette } = theme;
1518
1437
  const testID = field.testID ?? fieldTestID(barTestID, field.key);
1519
1438
  return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.switchRow, testID, children: [
1520
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.subLabel, { color: colors.text }], children: field.label }),
1439
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [uiForms.controlStyles.subLabel, { color: colors.text }], children: field.label }),
1521
1440
  /* @__PURE__ */ jsxRuntime.jsx(
1522
1441
  reactNative.Switch,
1523
1442
  {
@@ -1534,195 +1453,45 @@ function BooleanField({ field, barTestID, value, onChange }) {
1534
1453
  )
1535
1454
  ] });
1536
1455
  }
1537
- var WEB_DATE_PROPS = typeof document !== "undefined" ? { type: "date" } : {};
1538
- function DateInput(p) {
1539
- return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.dateCol, children: [
1540
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.subLabel, { color: p.muted }], children: p.label }),
1541
- /* @__PURE__ */ jsxRuntime.jsx(
1542
- reactNative.TextInput,
1543
- {
1544
- accessibilityLabel: p.label,
1545
- accessibilityHint: p.hint,
1546
- placeholder: p.placeholder,
1547
- placeholderTextColor: p.muted,
1548
- value: p.value,
1549
- onChangeText: p.onChangeText,
1550
- onSubmitEditing: p.onSubmit,
1551
- style: [filterStyles.input, { borderColor: p.border, backgroundColor: p.surface, color: p.color }],
1552
- testID: `${p.testID}-${p.side}`,
1553
- ...WEB_DATE_PROPS
1554
- }
1555
- )
1556
- ] });
1557
- }
1558
1456
  function DateRangeField({ field, barTestID, value, onChange, onSubmit, fromLabel, toLabel }) {
1559
- const { theme } = uiFeedback.useUi();
1560
- const { colors } = theme;
1561
- const testID = field.testID ?? fieldTestID(barTestID, field.key);
1562
- return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.dateRow, testID: `${testID}-range`, children: [
1563
- /* @__PURE__ */ jsxRuntime.jsx(
1564
- DateInput,
1565
- {
1566
- side: "from",
1567
- label: field.fromLabel ?? fromLabel,
1568
- placeholder: field.fromPlaceholder,
1569
- value: value.from,
1570
- color: colors.text,
1571
- border: colors.border,
1572
- surface: colors.surface,
1573
- muted: colors.textSecondary,
1574
- hint: field.accessibilityHint,
1575
- testID,
1576
- onChangeText: (from) => onChange({ from, to: value.to }),
1577
- onSubmit
1578
- }
1579
- ),
1580
- /* @__PURE__ */ jsxRuntime.jsx(
1581
- DateInput,
1582
- {
1583
- side: "to",
1584
- label: field.toLabel ?? toLabel,
1585
- placeholder: field.toPlaceholder,
1586
- value: value.to,
1587
- color: colors.text,
1588
- border: colors.border,
1589
- surface: colors.surface,
1590
- muted: colors.textSecondary,
1591
- hint: field.accessibilityHint,
1592
- testID,
1593
- onChangeText: (to) => onChange({ from: value.from, to }),
1594
- onSubmit
1595
- }
1596
- )
1597
- ] });
1598
- }
1599
- var IS_WEB3 = typeof document !== "undefined";
1600
- var ESCAPE_KEY = "Escape";
1601
- var ACTIVE_WEIGHT = "700";
1602
- var IDLE_WEIGHT = "400";
1603
- function useDismiss(anchorRef, menuRef, onDismiss) {
1604
- React4.useEffect(() => {
1605
- if (!IS_WEB3) return void 0;
1606
- const onMouseDown = (event) => {
1607
- const anchorNode = anchorRef.current;
1608
- const menuNode = menuRef.current;
1609
- const target = event.target instanceof Node ? event.target : null;
1610
- const insideAnchor = anchorNode !== null && target !== null && anchorNode.contains(target);
1611
- const insideMenu = menuNode !== null && target !== null && menuNode.contains(target);
1612
- if (!insideAnchor && !insideMenu) onDismiss();
1613
- };
1614
- const onKeyDown = (event) => {
1615
- if (event.key === ESCAPE_KEY) onDismiss();
1616
- };
1617
- document.addEventListener("mousedown", onMouseDown);
1618
- document.addEventListener("keydown", onKeyDown);
1619
- return () => {
1620
- document.removeEventListener("mousedown", onMouseDown);
1621
- document.removeEventListener("keydown", onKeyDown);
1622
- };
1623
- }, [anchorRef, menuRef, onDismiss]);
1624
- }
1625
- function AnchoredMenu({
1626
- options,
1627
- selectedValue,
1628
- onSelect,
1629
- onDismiss,
1630
- colors,
1631
- optionHint,
1632
- testID,
1633
- anchorRef
1634
- }) {
1635
- const menuRef = React4__default.default.useRef(null);
1636
- useDismiss(anchorRef, menuRef, onDismiss);
1637
1457
  return /* @__PURE__ */ jsxRuntime.jsx(
1638
- reactNative.View,
1458
+ uiForms.DateRangeControl,
1639
1459
  {
1640
- ref: menuRef,
1641
- accessibilityRole: "menu",
1642
- style: [filterStyles.menu, { borderColor: colors.border, backgroundColor: colors.surface }],
1643
- testID: `${testID}-menu`,
1644
- children: options.map((opt) => {
1645
- const active = opt.value === selectedValue;
1646
- return /* @__PURE__ */ jsxRuntime.jsx(
1647
- reactNative.Pressable,
1648
- {
1649
- accessibilityRole: "menuitem",
1650
- accessibilityLabel: opt.label,
1651
- accessibilityHint: optionHint,
1652
- accessibilityState: { selected: active },
1653
- onPress: () => onSelect(opt.value),
1654
- style: filterStyles.option,
1655
- testID: `${testID}-option-${opt.value}`,
1656
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.optionText, { color: active ? colors.brand : colors.text, fontWeight: active ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: opt.label })
1657
- },
1658
- opt.value
1659
- );
1660
- })
1460
+ accessibilityHint: field.accessibilityHint,
1461
+ fromLabel: field.fromLabel ?? fromLabel,
1462
+ fromPlaceholder: field.fromPlaceholder,
1463
+ testID: field.testID ?? fieldTestID(barTestID, field.key),
1464
+ toLabel: field.toLabel ?? toLabel,
1465
+ toPlaceholder: field.toPlaceholder,
1466
+ value,
1467
+ onChange,
1468
+ onSubmit
1661
1469
  }
1662
1470
  );
1663
1471
  }
1664
- var CHEVRON_DOWN2 = "\u25BE";
1665
- var CHEVRON_UP2 = "\u25B4";
1666
1472
  function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
1667
- const { theme, t } = uiFeedback.useUi();
1668
- const { colors, palette } = theme;
1669
- const anchorRef = React4.useRef(null);
1670
- const [isOpen, setIsOpen] = React4.useState(false);
1473
+ const { t } = uiFeedback.useUi();
1671
1474
  const testID = field.testID ?? fieldTestID(barTestID, field.key);
1672
- const selectedLabel = React4.useMemo(() => {
1673
- const found = field.options.find((o) => o.value === value);
1674
- return found?.label ?? field.placeholder ?? placeholder;
1675
- }, [field.options, field.placeholder, placeholder, value]);
1475
+ const resolvedPlaceholder = field.placeholder ?? placeholder;
1476
+ const selectedLabel = field.options.find((o) => o.value === value)?.label ?? resolvedPlaceholder;
1676
1477
  const triggerLabel = accessibleName(
1677
1478
  t(FILTERS_I18N.selectTriggerLabel, field.label, selectedLabel),
1678
1479
  FILTERS_I18N.selectTriggerLabel,
1679
1480
  field.label
1680
1481
  );
1681
- const close = React4.useCallback(() => {
1682
- setIsOpen(false);
1683
- }, []);
1684
- const toggle = React4.useCallback(() => {
1685
- setIsOpen((prev) => !prev);
1686
- }, []);
1687
- const select = React4.useCallback(
1688
- (next) => {
1689
- onChange(next);
1690
- setIsOpen(false);
1691
- },
1692
- [onChange]
1482
+ return /* @__PURE__ */ jsxRuntime.jsx(
1483
+ uiForms.SelectControl,
1484
+ {
1485
+ accessibilityHint: field.accessibilityHint ?? dropdownHint,
1486
+ accessibilityLabel: triggerLabel,
1487
+ options: field.options,
1488
+ optionHint,
1489
+ placeholder: resolvedPlaceholder,
1490
+ testID,
1491
+ value,
1492
+ onChange
1493
+ }
1693
1494
  );
1694
- return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: filterStyles.anchor, children: [
1695
- /* @__PURE__ */ jsxRuntime.jsxs(
1696
- reactNative.Pressable,
1697
- {
1698
- accessibilityRole: "button",
1699
- accessibilityLabel: triggerLabel,
1700
- accessibilityHint: field.accessibilityHint ?? dropdownHint,
1701
- accessibilityState: { expanded: isOpen },
1702
- "aria-expanded": isOpen,
1703
- onPress: toggle,
1704
- style: [filterStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surface }],
1705
- testID: `${testID}-trigger`,
1706
- children: [
1707
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [filterStyles.selectTriggerText, { color: value === "" ? colors.textSecondary : colors.text }], children: selectedLabel }),
1708
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { "aria-hidden": true, style: [filterStyles.chevron, { color: colors.textSecondary }], children: isOpen ? CHEVRON_UP2 : CHEVRON_DOWN2 })
1709
- ]
1710
- }
1711
- ),
1712
- isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
1713
- AnchoredMenu,
1714
- {
1715
- options: field.options,
1716
- selectedValue: value,
1717
- onSelect: select,
1718
- onDismiss: close,
1719
- colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
1720
- optionHint,
1721
- testID,
1722
- anchorRef
1723
- }
1724
- ) : null
1725
- ] });
1726
1495
  }
1727
1496
  function TextField({ field, barTestID, value, onChange, onSubmit }) {
1728
1497
  const { theme } = uiFeedback.useUi();
@@ -1739,121 +1508,32 @@ function TextField({ field, barTestID, value, onChange, onSubmit }) {
1739
1508
  value,
1740
1509
  onChangeText: onChange,
1741
1510
  onSubmitEditing: onSubmit,
1742
- style: [filterStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }],
1511
+ style: [uiForms.controlStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }],
1743
1512
  testID: `${field.testID ?? fieldTestID(barTestID, field.key)}-input`
1744
1513
  }
1745
1514
  );
1746
1515
  }
1747
-
1748
- // src/Filters/utils/suggest.ts
1749
- var RANK_VALUE_EXACT = 0;
1750
- var RANK_VALUE_PREFIX = 1;
1751
- var RANK_LABEL_PREFIX = 2;
1752
- var RANK_LABEL_CONTAINS = 3;
1753
- var NO_MATCH = -1;
1754
- function rankOf(option, needle) {
1755
- const value = option.value.toLowerCase();
1756
- const label = option.label.toLowerCase();
1757
- if (value === needle) return RANK_VALUE_EXACT;
1758
- if (value.startsWith(needle)) return RANK_VALUE_PREFIX;
1759
- if (label.startsWith(needle)) return RANK_LABEL_PREFIX;
1760
- if (label.includes(needle)) return RANK_LABEL_CONTAINS;
1761
- return NO_MATCH;
1762
- }
1763
- function suggestOptions(options, query, minChars, limit) {
1764
- const needle = query.trim().toLowerCase();
1765
- if (needle.length < minChars) return [];
1766
- const scored = [];
1767
- for (const option of options) {
1768
- const rank = rankOf(option, needle);
1769
- if (rank !== NO_MATCH) scored.push({ option, rank });
1770
- }
1771
- scored.sort((a, b) => a.rank !== b.rank ? a.rank - b.rank : a.option.label.localeCompare(b.option.label));
1772
- return scored.slice(0, limit).map((entry) => entry.option);
1773
- }
1774
- function isUnmatched(options, text) {
1775
- const needle = text.trim().toLowerCase();
1776
- if (needle === "") return false;
1777
- return !options.some((o) => o.value.toLowerCase() === needle || o.label.toLowerCase() === needle);
1778
- }
1779
- var CLOSE_DELAY_MS = 140;
1780
1516
  function TypeaheadField({ field, barTestID, value, onChange, onSubmit, optionHint }) {
1781
- const { theme } = uiFeedback.useUi();
1782
- const { colors, palette, semantic } = theme;
1783
- const anchorRef = React4.useRef(null);
1784
- const [isOpen, setIsOpen] = React4.useState(false);
1785
- const testID = field.testID ?? fieldTestID(barTestID, field.key);
1786
- const minChars = field.minChars ?? DEFAULT_TYPEAHEAD_MIN_CHARS;
1787
- const maxSuggestions = field.maxSuggestions ?? DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
1788
- const exactPick = React4.useMemo(
1789
- () => field.options.some((o) => o.label === value),
1790
- [field.options, value]
1791
- );
1792
- const suggestions = React4.useMemo(
1793
- () => exactPick ? [] : suggestOptions(field.options, value, minChars, maxSuggestions),
1794
- [exactPick, field.options, value, minChars, maxSuggestions]
1795
- );
1796
- const showMenu = isOpen && suggestions.length > 0;
1797
- const handleChange = React4.useCallback(
1798
- (next) => {
1799
- onChange(next);
1800
- setIsOpen(true);
1801
- },
1802
- [onChange]
1803
- );
1804
- const pick = React4.useCallback(
1805
- (optionValue) => {
1806
- const opt = field.options.find((o) => o.value === optionValue);
1807
- onChange(opt?.label ?? optionValue);
1808
- setIsOpen(false);
1809
- },
1810
- [field.options, onChange]
1517
+ return /* @__PURE__ */ jsxRuntime.jsx(
1518
+ uiForms.TypeaheadControl,
1519
+ {
1520
+ accessibilityHint: field.accessibilityHint,
1521
+ accessibilityLabel: field.label,
1522
+ error: field.error,
1523
+ maxSuggestions: field.maxSuggestions ?? uiForms.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS,
1524
+ minChars: field.minChars ?? uiForms.DEFAULT_TYPEAHEAD_MIN_CHARS,
1525
+ options: field.options,
1526
+ optionHint,
1527
+ placeholder: field.placeholder,
1528
+ testID: field.testID ?? fieldTestID(barTestID, field.key),
1529
+ value,
1530
+ onChange,
1531
+ onSubmit
1532
+ }
1811
1533
  );
1812
- const handleBlur = React4.useCallback(() => {
1813
- setTimeout(() => setIsOpen(false), CLOSE_DELAY_MS);
1814
- }, []);
1815
- const handleSubmit = React4.useCallback(() => {
1816
- setIsOpen(false);
1817
- onSubmit();
1818
- }, [onSubmit]);
1819
- const hasError = field.error !== void 0 && field.error !== "";
1820
- return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: filterStyles.anchor, children: [
1821
- /* @__PURE__ */ jsxRuntime.jsx(
1822
- reactNative.TextInput,
1823
- {
1824
- accessibilityLabel: field.label,
1825
- accessibilityHint: field.accessibilityHint,
1826
- autoCapitalize: "none",
1827
- autoCorrect: false,
1828
- placeholder: field.placeholder,
1829
- placeholderTextColor: colors.textSecondary,
1830
- spellCheck: false,
1831
- value,
1832
- onChangeText: handleChange,
1833
- onFocus: () => setIsOpen(true),
1834
- onBlur: handleBlur,
1835
- onSubmitEditing: handleSubmit,
1836
- style: [filterStyles.input, { borderColor: hasError ? semantic.error["500"] : colors.border, backgroundColor: colors.surface, color: colors.text }],
1837
- testID: `${testID}-input`
1838
- }
1839
- ),
1840
- showMenu ? /* @__PURE__ */ jsxRuntime.jsx(
1841
- AnchoredMenu,
1842
- {
1843
- options: suggestions,
1844
- selectedValue: value,
1845
- onSelect: pick,
1846
- onDismiss: () => setIsOpen(false),
1847
- colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
1848
- optionHint,
1849
- testID,
1850
- anchorRef
1851
- }
1852
- ) : null,
1853
- hasError ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [filterStyles.error, { color: semantic.error["500"] }], testID: `${testID}-error`, children: field.error }) : null
1854
- ] });
1855
1534
  }
1856
1535
  var EMPTY_RANGE = { from: "", to: "" };
1536
+ var GROW_FLEX = 1;
1857
1537
  function asString(value) {
1858
1538
  return typeof value === "string" ? value : "";
1859
1539
  }
@@ -1930,7 +1610,18 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
1930
1610
  );
1931
1611
  }
1932
1612
  })();
1933
- return /* @__PURE__ */ jsxRuntime.jsx(FieldShell, { field, barTestID, children: body });
1613
+ const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
1614
+ const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
1615
+ return /* @__PURE__ */ jsxRuntime.jsx(
1616
+ uiForms.Field,
1617
+ {
1618
+ containerStyle: [filterStyles.fieldInBar, { minWidth }, grow, field.style],
1619
+ label: field.label,
1620
+ labelVariant: "control",
1621
+ testID: field.testID ?? fieldTestID(barTestID, field.key),
1622
+ children: body
1623
+ }
1624
+ );
1934
1625
  }
1935
1626
  function Filters({
1936
1627
  fields,
@@ -1954,16 +1645,16 @@ function Filters({
1954
1645
  testID = FILTERS_TEST_ID
1955
1646
  }) {
1956
1647
  const { t } = uiFeedback.useUi();
1957
- const setField = React4.useCallback(
1648
+ const setField = react.useCallback(
1958
1649
  (key, value) => {
1959
1650
  onChange({ ...values, [key]: value });
1960
1651
  },
1961
1652
  [onChange, values]
1962
1653
  );
1963
- const onSubmit = React4.useCallback(() => {
1654
+ const onSubmit = react.useCallback(() => {
1964
1655
  if (onApply !== void 0 && !applyDisabled) onApply();
1965
1656
  }, [onApply, applyDisabled]);
1966
- const strings = React4.useMemo(
1657
+ const strings = react.useMemo(
1967
1658
  () => ({
1968
1659
  selectPlaceholder: selectPlaceholder ?? t(FILTERS_I18N.selectPlaceholder),
1969
1660
  dropdownHint: t(FILTERS_I18N.dropdownHint),
@@ -2026,37 +1717,37 @@ function shallowEqual(a, b) {
2026
1717
  return JSON.stringify(a) === JSON.stringify(b);
2027
1718
  }
2028
1719
  function useFilterDraft({ initial, onApply, onReset }) {
2029
- const [draft, setDraft] = React4.useState(initial);
2030
- const [committed, setCommitted] = React4.useState(initial);
2031
- const setField = React4.useCallback((key, value) => {
1720
+ const [draft, setDraft] = react.useState(initial);
1721
+ const [committed, setCommitted] = react.useState(initial);
1722
+ const setField = react.useCallback((key, value) => {
2032
1723
  setDraft((prev) => ({ ...prev, [key]: value }));
2033
1724
  }, []);
2034
- const apply = React4.useCallback(() => {
1725
+ const apply = react.useCallback(() => {
2035
1726
  setCommitted(draft);
2036
1727
  onApply?.(draft);
2037
1728
  }, [draft, onApply]);
2038
- const reset = React4.useCallback(() => {
1729
+ const reset = react.useCallback(() => {
2039
1730
  setDraft(initial);
2040
1731
  setCommitted(initial);
2041
1732
  onReset?.();
2042
1733
  }, [initial, onReset]);
2043
- const dirty = React4.useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
1734
+ const dirty = react.useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
2044
1735
  return { draft, committed, setField, setDraft, apply, reset, dirty };
2045
1736
  }
2046
1737
  var DEFAULT_PAGE_SIZE = 10;
2047
1738
  function usePagedRows(rows, options = {}) {
2048
1739
  const pageSize = Math.max(1, options.pageSize ?? DEFAULT_PAGE_SIZE);
2049
- const [currentPage, setCurrentPage] = React4.useState(0);
1740
+ const [currentPage, setCurrentPage] = react.useState(0);
2050
1741
  const totalPages = Math.ceil(rows.length / pageSize);
2051
- React4.useEffect(() => {
1742
+ react.useEffect(() => {
2052
1743
  const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
2053
1744
  if (currentPage > lastValidPage) setCurrentPage(lastValidPage);
2054
1745
  }, [currentPage, totalPages]);
2055
- const pageRows = React4.useMemo(() => {
1746
+ const pageRows = react.useMemo(() => {
2056
1747
  const start = currentPage * pageSize;
2057
1748
  return rows.slice(start, start + pageSize);
2058
1749
  }, [rows, currentPage, pageSize]);
2059
- const setPage = React4.useCallback(
1750
+ const setPage = react.useCallback(
2060
1751
  (page) => {
2061
1752
  const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
2062
1753
  const clamped = Math.min(Math.max(0, page), lastValidPage);
@@ -2074,11 +1765,25 @@ function usePagedRows(rows, options = {}) {
2074
1765
  };
2075
1766
  }
2076
1767
 
1768
+ Object.defineProperty(exports, "DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS", {
1769
+ enumerable: true,
1770
+ get: function () { return uiForms.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS; }
1771
+ });
1772
+ Object.defineProperty(exports, "DEFAULT_TYPEAHEAD_MIN_CHARS", {
1773
+ enumerable: true,
1774
+ get: function () { return uiForms.DEFAULT_TYPEAHEAD_MIN_CHARS; }
1775
+ });
1776
+ Object.defineProperty(exports, "isUnmatched", {
1777
+ enumerable: true,
1778
+ get: function () { return uiForms.isUnmatched; }
1779
+ });
1780
+ Object.defineProperty(exports, "suggestOptions", {
1781
+ enumerable: true,
1782
+ get: function () { return uiForms.suggestOptions; }
1783
+ });
2077
1784
  exports.CARD_STACK_BREAKPOINT = CARD_STACK_BREAKPOINT;
2078
1785
  exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
2079
1786
  exports.DEFAULT_PAGE_SIZE_OPTIONS = DEFAULT_PAGE_SIZE_OPTIONS;
2080
- exports.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
2081
- exports.DEFAULT_TYPEAHEAD_MIN_CHARS = DEFAULT_TYPEAHEAD_MIN_CHARS;
2082
1787
  exports.DataTable = DataTable;
2083
1788
  exports.FIELD_MIN_WIDTH = FIELD_MIN_WIDTH;
2084
1789
  exports.FILTERS_I18N = FILTERS_I18N;
@@ -2092,12 +1797,10 @@ exports.TABLE_TEST_IDS = TABLE_TEST_IDS;
2092
1797
  exports.applyTestID = applyTestID;
2093
1798
  exports.clearTestID = clearTestID;
2094
1799
  exports.fieldTestID = fieldTestID;
2095
- exports.isUnmatched = isUnmatched;
2096
1800
  exports.rowDetailTestID = rowDetailTestID;
2097
1801
  exports.rowSelectTestID = rowSelectTestID;
2098
1802
  exports.rowTestID = rowTestID;
2099
1803
  exports.selectAllTestID = selectAllTestID;
2100
- exports.suggestOptions = suggestOptions;
2101
1804
  exports.useFilterDraft = useFilterDraft;
2102
1805
  exports.usePagedRows = usePagedRows;
2103
1806
  //# sourceMappingURL=index.js.map