@dloizides/ui-tables 1.13.0 → 1.15.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 +105 -0
- package/README.md +11 -2
- package/dist/index.d.mts +22 -32
- package/dist/index.d.ts +22 -32
- package/dist/index.js +130 -425
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -377
- 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
|
|
|
@@ -858,8 +860,9 @@ function DataTable(props) {
|
|
|
858
860
|
);
|
|
859
861
|
const rowBg = (row, index, key) => interactive && hoveredKey === key ? hoverTint : rowBackground(row, index);
|
|
860
862
|
const stateView = (label) => /* @__PURE__ */ jsx(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, children: /* @__PURE__ */ jsx(View, { style: [tableStyles.state, o?.state], children: /* @__PURE__ */ jsx(Text, { style: [tableStyles.stateText, { color: colors.textSecondary }, o?.stateText], children: label }) }) });
|
|
861
|
-
if (
|
|
862
|
-
|
|
863
|
+
if (rows.length === 0) {
|
|
864
|
+
return stateView(loading ? loadingLabel ?? t(TABLE_I18N.loading) : emptyLabel ?? t(TABLE_I18N.empty));
|
|
865
|
+
}
|
|
863
866
|
const renderRow = (row, key, style) => /* @__PURE__ */ jsx(
|
|
864
867
|
DataTableRow,
|
|
865
868
|
{
|
|
@@ -895,7 +898,7 @@ function DataTable(props) {
|
|
|
895
898
|
}
|
|
896
899
|
);
|
|
897
900
|
if (stacked) {
|
|
898
|
-
return /* @__PURE__ */ jsxs(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, children: [
|
|
901
|
+
return /* @__PURE__ */ jsxs(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, "aria-busy": loading, children: [
|
|
899
902
|
banner,
|
|
900
903
|
rows.map((row, i) => {
|
|
901
904
|
const key = rowKeys[i] ?? keyExtractor(row);
|
|
@@ -917,6 +920,7 @@ function DataTable(props) {
|
|
|
917
920
|
{
|
|
918
921
|
style: [tableStyles.wrap, frame, o?.wrap],
|
|
919
922
|
testID,
|
|
923
|
+
"aria-busy": loading,
|
|
920
924
|
...keyboardNavigation ? { role: "grid" } : null,
|
|
921
925
|
children: [
|
|
922
926
|
banner,
|
|
@@ -1347,80 +1351,23 @@ function Pager({
|
|
|
1347
1351
|
] });
|
|
1348
1352
|
}
|
|
1349
1353
|
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
1354
|
var SWITCH_ROW_GAP = 8;
|
|
1373
1355
|
var ACTION_PAD_H = 14;
|
|
1374
1356
|
var ACTION_PAD_V = 8;
|
|
1375
1357
|
var ACTION_RADIUS = 8;
|
|
1376
1358
|
var ACTION_FONT = 13;
|
|
1359
|
+
var ACTION_BORDER = 1;
|
|
1360
|
+
var NO_FORM_RHYTHM = 0;
|
|
1377
1361
|
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 },
|
|
1362
|
+
/**
|
|
1363
|
+
* Merged onto `Field`'s container inside the bar. Zeroes the 16px bottom margin `Field` gives
|
|
1364
|
+
* a stacked form row: the bar is a flex ROW whose spacing comes from FilterBar's `gap`, so
|
|
1365
|
+
* inheriting the form rhythm would add a phantom gap under every field — a pixel change for
|
|
1366
|
+
* six live portals, which this wave must not make.
|
|
1367
|
+
*/
|
|
1368
|
+
fieldInBar: { marginBottom: NO_FORM_RHYTHM },
|
|
1422
1369
|
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:
|
|
1370
|
+
action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth: ACTION_BORDER },
|
|
1424
1371
|
actionText: { fontSize: ACTION_FONT, fontWeight: "600" }
|
|
1425
1372
|
});
|
|
1426
1373
|
var FILTER_HIT_SLOP = { top: 8, bottom: 8 };
|
|
@@ -1455,8 +1402,6 @@ function ActionButton({ label, hint, tone, disabled = false, onPress, testID })
|
|
|
1455
1402
|
}
|
|
1456
1403
|
);
|
|
1457
1404
|
}
|
|
1458
|
-
|
|
1459
|
-
// src/Filters/constants.ts
|
|
1460
1405
|
var FILTERS_TEST_ID = "ui-filters-declarative";
|
|
1461
1406
|
var FIELD_MIN_WIDTH = {
|
|
1462
1407
|
select: 150,
|
|
@@ -1466,8 +1411,6 @@ var FIELD_MIN_WIDTH = {
|
|
|
1466
1411
|
typeahead: 200,
|
|
1467
1412
|
boolean: 150
|
|
1468
1413
|
};
|
|
1469
|
-
var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
|
|
1470
|
-
var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
|
|
1471
1414
|
var fieldTestID = (barTestID, key) => `${barTestID}-field-${key}`;
|
|
1472
1415
|
var applyTestID = (barTestID) => `${barTestID}-apply`;
|
|
1473
1416
|
var clearTestID = (barTestID) => `${barTestID}-clear`;
|
|
@@ -1489,29 +1432,12 @@ var FILTERS_I18N = {
|
|
|
1489
1432
|
from: "uiTables.filters.from",
|
|
1490
1433
|
to: "uiTables.filters.to"
|
|
1491
1434
|
};
|
|
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
1435
|
function BooleanField({ field, barTestID, value, onChange }) {
|
|
1510
1436
|
const { theme } = useUi();
|
|
1511
1437
|
const { colors, palette } = theme;
|
|
1512
1438
|
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1513
1439
|
return /* @__PURE__ */ jsxs(View, { style: filterStyles.switchRow, testID, children: [
|
|
1514
|
-
/* @__PURE__ */ jsx(Text, { style: [
|
|
1440
|
+
/* @__PURE__ */ jsx(Text, { style: [controlStyles.subLabel, { color: colors.text }], children: field.label }),
|
|
1515
1441
|
/* @__PURE__ */ jsx(
|
|
1516
1442
|
Switch,
|
|
1517
1443
|
{
|
|
@@ -1528,195 +1454,45 @@ function BooleanField({ field, barTestID, value, onChange }) {
|
|
|
1528
1454
|
)
|
|
1529
1455
|
] });
|
|
1530
1456
|
}
|
|
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
1457
|
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
1458
|
return /* @__PURE__ */ jsx(
|
|
1632
|
-
|
|
1459
|
+
DateRangeControl,
|
|
1633
1460
|
{
|
|
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
|
-
})
|
|
1461
|
+
accessibilityHint: field.accessibilityHint,
|
|
1462
|
+
fromLabel: field.fromLabel ?? fromLabel,
|
|
1463
|
+
fromPlaceholder: field.fromPlaceholder,
|
|
1464
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1465
|
+
toLabel: field.toLabel ?? toLabel,
|
|
1466
|
+
toPlaceholder: field.toPlaceholder,
|
|
1467
|
+
value,
|
|
1468
|
+
onChange,
|
|
1469
|
+
onSubmit
|
|
1655
1470
|
}
|
|
1656
1471
|
);
|
|
1657
1472
|
}
|
|
1658
|
-
var CHEVRON_DOWN2 = "\u25BE";
|
|
1659
|
-
var CHEVRON_UP2 = "\u25B4";
|
|
1660
1473
|
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);
|
|
1474
|
+
const { t } = useUi();
|
|
1665
1475
|
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]);
|
|
1476
|
+
const resolvedPlaceholder = field.placeholder ?? placeholder;
|
|
1477
|
+
const selectedLabel = field.options.find((o) => o.value === value)?.label ?? resolvedPlaceholder;
|
|
1670
1478
|
const triggerLabel = accessibleName(
|
|
1671
1479
|
t(FILTERS_I18N.selectTriggerLabel, field.label, selectedLabel),
|
|
1672
1480
|
FILTERS_I18N.selectTriggerLabel,
|
|
1673
1481
|
field.label
|
|
1674
1482
|
);
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1483
|
+
return /* @__PURE__ */ jsx(
|
|
1484
|
+
SelectControl,
|
|
1485
|
+
{
|
|
1486
|
+
accessibilityHint: field.accessibilityHint ?? dropdownHint,
|
|
1487
|
+
accessibilityLabel: triggerLabel,
|
|
1488
|
+
options: field.options,
|
|
1489
|
+
optionHint,
|
|
1490
|
+
placeholder: resolvedPlaceholder,
|
|
1491
|
+
testID,
|
|
1492
|
+
value,
|
|
1493
|
+
onChange
|
|
1494
|
+
}
|
|
1687
1495
|
);
|
|
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
1496
|
}
|
|
1721
1497
|
function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
1722
1498
|
const { theme } = useUi();
|
|
@@ -1733,121 +1509,32 @@ function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
|
1733
1509
|
value,
|
|
1734
1510
|
onChangeText: onChange,
|
|
1735
1511
|
onSubmitEditing: onSubmit,
|
|
1736
|
-
style: [
|
|
1512
|
+
style: [controlStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }],
|
|
1737
1513
|
testID: `${field.testID ?? fieldTestID(barTestID, field.key)}-input`
|
|
1738
1514
|
}
|
|
1739
1515
|
);
|
|
1740
1516
|
}
|
|
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
1517
|
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]
|
|
1518
|
+
return /* @__PURE__ */ jsx(
|
|
1519
|
+
TypeaheadControl,
|
|
1520
|
+
{
|
|
1521
|
+
accessibilityHint: field.accessibilityHint,
|
|
1522
|
+
accessibilityLabel: field.label,
|
|
1523
|
+
error: field.error,
|
|
1524
|
+
maxSuggestions: field.maxSuggestions ?? DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS,
|
|
1525
|
+
minChars: field.minChars ?? DEFAULT_TYPEAHEAD_MIN_CHARS,
|
|
1526
|
+
options: field.options,
|
|
1527
|
+
optionHint,
|
|
1528
|
+
placeholder: field.placeholder,
|
|
1529
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1530
|
+
value,
|
|
1531
|
+
onChange,
|
|
1532
|
+
onSubmit
|
|
1533
|
+
}
|
|
1805
1534
|
);
|
|
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
1535
|
}
|
|
1850
1536
|
var EMPTY_RANGE = { from: "", to: "" };
|
|
1537
|
+
var GROW_FLEX = 1;
|
|
1851
1538
|
function asString(value) {
|
|
1852
1539
|
return typeof value === "string" ? value : "";
|
|
1853
1540
|
}
|
|
@@ -1924,7 +1611,18 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1924
1611
|
);
|
|
1925
1612
|
}
|
|
1926
1613
|
})();
|
|
1927
|
-
|
|
1614
|
+
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1615
|
+
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1616
|
+
return /* @__PURE__ */ jsx(
|
|
1617
|
+
Field,
|
|
1618
|
+
{
|
|
1619
|
+
containerStyle: [filterStyles.fieldInBar, { minWidth }, grow, field.style],
|
|
1620
|
+
label: field.label,
|
|
1621
|
+
labelVariant: "control",
|
|
1622
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1623
|
+
children: body
|
|
1624
|
+
}
|
|
1625
|
+
);
|
|
1928
1626
|
}
|
|
1929
1627
|
function Filters({
|
|
1930
1628
|
fields,
|
|
@@ -2068,6 +1766,6 @@ function usePagedRows(rows, options = {}) {
|
|
|
2068
1766
|
};
|
|
2069
1767
|
}
|
|
2070
1768
|
|
|
2071
|
-
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS,
|
|
1769
|
+
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 };
|
|
2072
1770
|
//# sourceMappingURL=index.mjs.map
|
|
2073
1771
|
//# sourceMappingURL=index.mjs.map
|