@dloizides/ui-tables 1.12.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/CHANGELOG.md +95 -0
- package/README.md +11 -2
- package/dist/index.d.mts +51 -32
- package/dist/index.d.ts +51 -32
- package/dist/index.js +153 -418
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -374
- package/dist/index.mjs.map +1 -1
- package/package.json +119 -115
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { memo, useState, useMemo, useCallback, useEffect, useRef, useLayoutEffect } from 'react';
|
|
2
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
|
+
import { Field, controlStyles, DateRangeControl, TypeaheadControl, DEFAULT_TYPEAHEAD_MIN_CHARS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, SelectControl } from '@dloizides/ui-forms';
|
|
7
|
+
export { DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, isUnmatched, suggestOptions } from '@dloizides/ui-forms';
|
|
6
8
|
|
|
7
9
|
// src/StatCard/StatCard.tsx
|
|
8
10
|
|
|
@@ -1347,80 +1349,23 @@ function Pager({
|
|
|
1347
1349
|
] });
|
|
1348
1350
|
}
|
|
1349
1351
|
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
1352
|
var SWITCH_ROW_GAP = 8;
|
|
1373
1353
|
var ACTION_PAD_H = 14;
|
|
1374
1354
|
var ACTION_PAD_V = 8;
|
|
1375
1355
|
var ACTION_RADIUS = 8;
|
|
1376
1356
|
var ACTION_FONT = 13;
|
|
1357
|
+
var ACTION_BORDER = 1;
|
|
1358
|
+
var NO_FORM_RHYTHM = 0;
|
|
1377
1359
|
var filterStyles = StyleSheet.create({
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
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 },
|
|
1360
|
+
/**
|
|
1361
|
+
* Merged onto `Field`'s container inside the bar. Zeroes the 16px bottom margin `Field` gives
|
|
1362
|
+
* a stacked form row: the bar is a flex ROW whose spacing comes from FilterBar's `gap`, so
|
|
1363
|
+
* inheriting the form rhythm would add a phantom gap under every field — a pixel change for
|
|
1364
|
+
* six live portals, which this wave must not make.
|
|
1365
|
+
*/
|
|
1366
|
+
fieldInBar: { marginBottom: NO_FORM_RHYTHM },
|
|
1422
1367
|
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:
|
|
1368
|
+
action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth: ACTION_BORDER },
|
|
1424
1369
|
actionText: { fontSize: ACTION_FONT, fontWeight: "600" }
|
|
1425
1370
|
});
|
|
1426
1371
|
var FILTER_HIT_SLOP = { top: 8, bottom: 8 };
|
|
@@ -1455,8 +1400,6 @@ function ActionButton({ label, hint, tone, disabled = false, onPress, testID })
|
|
|
1455
1400
|
}
|
|
1456
1401
|
);
|
|
1457
1402
|
}
|
|
1458
|
-
|
|
1459
|
-
// src/Filters/constants.ts
|
|
1460
1403
|
var FILTERS_TEST_ID = "ui-filters-declarative";
|
|
1461
1404
|
var FIELD_MIN_WIDTH = {
|
|
1462
1405
|
select: 150,
|
|
@@ -1466,8 +1409,6 @@ var FIELD_MIN_WIDTH = {
|
|
|
1466
1409
|
typeahead: 200,
|
|
1467
1410
|
boolean: 150
|
|
1468
1411
|
};
|
|
1469
|
-
var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
|
|
1470
|
-
var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
|
|
1471
1412
|
var fieldTestID = (barTestID, key) => `${barTestID}-field-${key}`;
|
|
1472
1413
|
var applyTestID = (barTestID) => `${barTestID}-apply`;
|
|
1473
1414
|
var clearTestID = (barTestID) => `${barTestID}-clear`;
|
|
@@ -1489,29 +1430,12 @@ var FILTERS_I18N = {
|
|
|
1489
1430
|
from: "uiTables.filters.from",
|
|
1490
1431
|
to: "uiTables.filters.to"
|
|
1491
1432
|
};
|
|
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
1433
|
function BooleanField({ field, barTestID, value, onChange }) {
|
|
1510
1434
|
const { theme } = useUi();
|
|
1511
1435
|
const { colors, palette } = theme;
|
|
1512
1436
|
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1513
1437
|
return /* @__PURE__ */ jsxs(View, { style: filterStyles.switchRow, testID, children: [
|
|
1514
|
-
/* @__PURE__ */ jsx(Text, { style: [
|
|
1438
|
+
/* @__PURE__ */ jsx(Text, { style: [controlStyles.subLabel, { color: colors.text }], children: field.label }),
|
|
1515
1439
|
/* @__PURE__ */ jsx(
|
|
1516
1440
|
Switch,
|
|
1517
1441
|
{
|
|
@@ -1528,195 +1452,45 @@ function BooleanField({ field, barTestID, value, onChange }) {
|
|
|
1528
1452
|
)
|
|
1529
1453
|
] });
|
|
1530
1454
|
}
|
|
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
1455
|
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
1456
|
return /* @__PURE__ */ jsx(
|
|
1632
|
-
|
|
1457
|
+
DateRangeControl,
|
|
1633
1458
|
{
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
testID:
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
accessibilityRole: "menuitem",
|
|
1644
|
-
accessibilityLabel: opt.label,
|
|
1645
|
-
accessibilityHint: optionHint,
|
|
1646
|
-
accessibilityState: { selected: active },
|
|
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 })
|
|
1651
|
-
},
|
|
1652
|
-
opt.value
|
|
1653
|
-
);
|
|
1654
|
-
})
|
|
1459
|
+
accessibilityHint: field.accessibilityHint,
|
|
1460
|
+
fromLabel: field.fromLabel ?? fromLabel,
|
|
1461
|
+
fromPlaceholder: field.fromPlaceholder,
|
|
1462
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1463
|
+
toLabel: field.toLabel ?? toLabel,
|
|
1464
|
+
toPlaceholder: field.toPlaceholder,
|
|
1465
|
+
value,
|
|
1466
|
+
onChange,
|
|
1467
|
+
onSubmit
|
|
1655
1468
|
}
|
|
1656
1469
|
);
|
|
1657
1470
|
}
|
|
1658
|
-
var CHEVRON_DOWN2 = "\u25BE";
|
|
1659
|
-
var CHEVRON_UP2 = "\u25B4";
|
|
1660
1471
|
function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
|
|
1661
|
-
const {
|
|
1662
|
-
const { colors, palette } = theme;
|
|
1663
|
-
const anchorRef = useRef(null);
|
|
1664
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
1472
|
+
const { t } = useUi();
|
|
1665
1473
|
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1666
|
-
const
|
|
1667
|
-
|
|
1668
|
-
return found?.label ?? field.placeholder ?? placeholder;
|
|
1669
|
-
}, [field.options, field.placeholder, placeholder, value]);
|
|
1474
|
+
const resolvedPlaceholder = field.placeholder ?? placeholder;
|
|
1475
|
+
const selectedLabel = field.options.find((o) => o.value === value)?.label ?? resolvedPlaceholder;
|
|
1670
1476
|
const triggerLabel = accessibleName(
|
|
1671
1477
|
t(FILTERS_I18N.selectTriggerLabel, field.label, selectedLabel),
|
|
1672
1478
|
FILTERS_I18N.selectTriggerLabel,
|
|
1673
1479
|
field.label
|
|
1674
1480
|
);
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1481
|
+
return /* @__PURE__ */ jsx(
|
|
1482
|
+
SelectControl,
|
|
1483
|
+
{
|
|
1484
|
+
accessibilityHint: field.accessibilityHint ?? dropdownHint,
|
|
1485
|
+
accessibilityLabel: triggerLabel,
|
|
1486
|
+
options: field.options,
|
|
1487
|
+
optionHint,
|
|
1488
|
+
placeholder: resolvedPlaceholder,
|
|
1489
|
+
testID,
|
|
1490
|
+
value,
|
|
1491
|
+
onChange
|
|
1492
|
+
}
|
|
1687
1493
|
);
|
|
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
1494
|
}
|
|
1721
1495
|
function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
1722
1496
|
const { theme } = useUi();
|
|
@@ -1733,121 +1507,32 @@ function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
|
1733
1507
|
value,
|
|
1734
1508
|
onChangeText: onChange,
|
|
1735
1509
|
onSubmitEditing: onSubmit,
|
|
1736
|
-
style: [
|
|
1510
|
+
style: [controlStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }],
|
|
1737
1511
|
testID: `${field.testID ?? fieldTestID(barTestID, field.key)}-input`
|
|
1738
1512
|
}
|
|
1739
1513
|
);
|
|
1740
1514
|
}
|
|
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
1515
|
function TypeaheadField({ field, barTestID, value, onChange, onSubmit, optionHint }) {
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
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]
|
|
1516
|
+
return /* @__PURE__ */ jsx(
|
|
1517
|
+
TypeaheadControl,
|
|
1518
|
+
{
|
|
1519
|
+
accessibilityHint: field.accessibilityHint,
|
|
1520
|
+
accessibilityLabel: field.label,
|
|
1521
|
+
error: field.error,
|
|
1522
|
+
maxSuggestions: field.maxSuggestions ?? DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS,
|
|
1523
|
+
minChars: field.minChars ?? DEFAULT_TYPEAHEAD_MIN_CHARS,
|
|
1524
|
+
options: field.options,
|
|
1525
|
+
optionHint,
|
|
1526
|
+
placeholder: field.placeholder,
|
|
1527
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1528
|
+
value,
|
|
1529
|
+
onChange,
|
|
1530
|
+
onSubmit
|
|
1531
|
+
}
|
|
1805
1532
|
);
|
|
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
1533
|
}
|
|
1850
1534
|
var EMPTY_RANGE = { from: "", to: "" };
|
|
1535
|
+
var GROW_FLEX = 1;
|
|
1851
1536
|
function asString(value) {
|
|
1852
1537
|
return typeof value === "string" ? value : "";
|
|
1853
1538
|
}
|
|
@@ -1924,7 +1609,18 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1924
1609
|
);
|
|
1925
1610
|
}
|
|
1926
1611
|
})();
|
|
1927
|
-
|
|
1612
|
+
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1613
|
+
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1614
|
+
return /* @__PURE__ */ jsx(
|
|
1615
|
+
Field,
|
|
1616
|
+
{
|
|
1617
|
+
containerStyle: [filterStyles.fieldInBar, { minWidth }, grow, field.style],
|
|
1618
|
+
label: field.label,
|
|
1619
|
+
labelVariant: "control",
|
|
1620
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1621
|
+
children: body
|
|
1622
|
+
}
|
|
1623
|
+
);
|
|
1928
1624
|
}
|
|
1929
1625
|
function Filters({
|
|
1930
1626
|
fields,
|
|
@@ -2037,7 +1733,37 @@ function useFilterDraft({ initial, onApply, onReset }) {
|
|
|
2037
1733
|
const dirty = useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
|
|
2038
1734
|
return { draft, committed, setField, setDraft, apply, reset, dirty };
|
|
2039
1735
|
}
|
|
1736
|
+
var DEFAULT_PAGE_SIZE = 10;
|
|
1737
|
+
function usePagedRows(rows, options = {}) {
|
|
1738
|
+
const pageSize = Math.max(1, options.pageSize ?? DEFAULT_PAGE_SIZE);
|
|
1739
|
+
const [currentPage, setCurrentPage] = useState(0);
|
|
1740
|
+
const totalPages = Math.ceil(rows.length / pageSize);
|
|
1741
|
+
useEffect(() => {
|
|
1742
|
+
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
1743
|
+
if (currentPage > lastValidPage) setCurrentPage(lastValidPage);
|
|
1744
|
+
}, [currentPage, totalPages]);
|
|
1745
|
+
const pageRows = useMemo(() => {
|
|
1746
|
+
const start = currentPage * pageSize;
|
|
1747
|
+
return rows.slice(start, start + pageSize);
|
|
1748
|
+
}, [rows, currentPage, pageSize]);
|
|
1749
|
+
const setPage = useCallback(
|
|
1750
|
+
(page) => {
|
|
1751
|
+
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
1752
|
+
const clamped = Math.min(Math.max(0, page), lastValidPage);
|
|
1753
|
+
setCurrentPage(clamped);
|
|
1754
|
+
},
|
|
1755
|
+
[totalPages]
|
|
1756
|
+
);
|
|
1757
|
+
return {
|
|
1758
|
+
pageRows,
|
|
1759
|
+
currentPage,
|
|
1760
|
+
totalPages,
|
|
1761
|
+
setPage,
|
|
1762
|
+
hasPages: totalPages > 1,
|
|
1763
|
+
pageSize
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
2040
1766
|
|
|
2041
|
-
export { CARD_STACK_BREAKPOINT,
|
|
1767
|
+
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, fieldTestID, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, useFilterDraft, usePagedRows };
|
|
2042
1768
|
//# sourceMappingURL=index.mjs.map
|
|
2043
1769
|
//# sourceMappingURL=index.mjs.map
|