@dloizides/ui-tables 1.29.1 → 2.0.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.d.mts +22 -6
- package/dist/index.d.ts +22 -6
- package/dist/index.js +65 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
|
5
5
|
import { useReducedMotion, FadeIn } from '@dloizides/ui-motion';
|
|
6
6
|
import { Z_INDEX } from '@dloizides/design-tokens';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
|
-
import { Field, controlStyles,
|
|
8
|
+
import { DateRangeControl, Field, controlStyles, DateField, TypeaheadControl, DEFAULT_TYPEAHEAD_MIN_CHARS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, SelectControl } from '@dloizides/ui-forms';
|
|
9
9
|
export { DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, isUnmatched, suggestOptions } from '@dloizides/ui-forms';
|
|
10
10
|
import { useA11y } from '@dloizides/a11y';
|
|
11
11
|
|
|
@@ -446,6 +446,21 @@ function SelectionCheckbox({
|
|
|
446
446
|
}
|
|
447
447
|
);
|
|
448
448
|
}
|
|
449
|
+
|
|
450
|
+
// src/DataTable/rowInteraction.ts
|
|
451
|
+
var PRESSED_TINT_ALPHA = "33";
|
|
452
|
+
var HEX_RGB2 = /^#[0-9a-f]{6}$/i;
|
|
453
|
+
var FOCUS_RING_WIDTH = 2;
|
|
454
|
+
var FOCUS_RING_OFFSET = -2;
|
|
455
|
+
var POINTER = { cursor: "pointer" };
|
|
456
|
+
function rowInteractionStyle(state, tokens) {
|
|
457
|
+
const pressedTint = HEX_RGB2.test(tokens.brand) ? `${tokens.brand}${PRESSED_TINT_ALPHA}` : tokens.fallbackTint;
|
|
458
|
+
return [
|
|
459
|
+
POINTER,
|
|
460
|
+
state.pressed ? { backgroundColor: pressedTint } : null,
|
|
461
|
+
state.focused === true ? { outlineStyle: "solid", outlineWidth: FOCUS_RING_WIDTH, outlineColor: tokens.brand, outlineOffset: FOCUS_RING_OFFSET } : null
|
|
462
|
+
];
|
|
463
|
+
}
|
|
449
464
|
var TAB_INDEX_INACTIVE = -1;
|
|
450
465
|
function webKeyProps(onKeyDown) {
|
|
451
466
|
return onKeyDown === void 0 ? {} : { onKeyDown };
|
|
@@ -469,18 +484,19 @@ function TableRow({
|
|
|
469
484
|
onHoverOut,
|
|
470
485
|
selectionSlot,
|
|
471
486
|
stacked,
|
|
472
|
-
keyboard
|
|
487
|
+
keyboard,
|
|
488
|
+
interaction
|
|
473
489
|
}) {
|
|
474
490
|
const interactive = onPress !== void 0;
|
|
475
491
|
const hover = interactive ? { onHoverIn, onHoverOut } : null;
|
|
476
492
|
if (selectionSlot === void 0) {
|
|
477
|
-
return interactive ? /* @__PURE__ */ jsx(Pressable, { style, testID, onPress, ...hover, ...a11y, ...focusProps(keyboard), children }) : /* @__PURE__ */ jsx(View, { style, testID, ...a11y, ...focusProps(keyboard), children });
|
|
493
|
+
return interactive ? /* @__PURE__ */ jsx(Pressable, { style: (state) => [style, rowInteractionStyle(state, interaction)], testID, onPress, ...hover, ...a11y, ...focusProps(keyboard), children }) : /* @__PURE__ */ jsx(View, { style, testID, ...a11y, ...focusProps(keyboard), children });
|
|
478
494
|
}
|
|
479
495
|
const contentStyle = stacked ? selectionStyles.cardContent : selectionStyles.rowContent;
|
|
480
496
|
const content = interactive ? /* @__PURE__ */ jsx(
|
|
481
497
|
Pressable,
|
|
482
498
|
{
|
|
483
|
-
style: contentStyle,
|
|
499
|
+
style: (state) => [contentStyle, rowInteractionStyle(state, interaction)],
|
|
484
500
|
tabIndex: keyboard === void 0 ? void 0 : TAB_INDEX_INACTIVE,
|
|
485
501
|
onPress,
|
|
486
502
|
...hover,
|
|
@@ -557,6 +573,7 @@ function DataTableRow({
|
|
|
557
573
|
testID: rowID,
|
|
558
574
|
onHoverIn,
|
|
559
575
|
onHoverOut,
|
|
576
|
+
interaction: { brand: theme.palette.primary["500"], fallbackTint: colors.border },
|
|
560
577
|
onPress: pressRow,
|
|
561
578
|
children: /* @__PURE__ */ jsx(RowPressProvider, { value: pressRow, children: /* @__PURE__ */ jsx(
|
|
562
579
|
RowCells,
|
|
@@ -1553,6 +1570,7 @@ var FIELD_MIN_WIDTH = {
|
|
|
1553
1570
|
select: 150,
|
|
1554
1571
|
text: 200,
|
|
1555
1572
|
number: 130,
|
|
1573
|
+
date: 160,
|
|
1556
1574
|
dateRange: 260,
|
|
1557
1575
|
typeahead: 200,
|
|
1558
1576
|
boolean: 150
|
|
@@ -1611,22 +1629,6 @@ function BooleanField({ field, barTestID, value, onChange }) {
|
|
|
1611
1629
|
)
|
|
1612
1630
|
] });
|
|
1613
1631
|
}
|
|
1614
|
-
function DateRangeField({ field, barTestID, value, onChange, onSubmit, fromLabel, toLabel }) {
|
|
1615
|
-
return /* @__PURE__ */ jsx(
|
|
1616
|
-
DateRangeControl,
|
|
1617
|
-
{
|
|
1618
|
-
accessibilityHint: field.accessibilityHint,
|
|
1619
|
-
fromLabel: field.fromLabel ?? fromLabel,
|
|
1620
|
-
fromPlaceholder: field.fromPlaceholder,
|
|
1621
|
-
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1622
|
-
toLabel: field.toLabel ?? toLabel,
|
|
1623
|
-
toPlaceholder: field.toPlaceholder,
|
|
1624
|
-
value,
|
|
1625
|
-
onChange,
|
|
1626
|
-
onSubmit
|
|
1627
|
-
}
|
|
1628
|
-
);
|
|
1629
|
-
}
|
|
1630
1632
|
function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
|
|
1631
1633
|
const { t } = useUi();
|
|
1632
1634
|
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
@@ -1651,6 +1653,21 @@ function SelectField({ field, barTestID, value, onChange, placeholder, dropdownH
|
|
|
1651
1653
|
}
|
|
1652
1654
|
);
|
|
1653
1655
|
}
|
|
1656
|
+
var NO_HINT = "";
|
|
1657
|
+
function SingleDateField({ field, barTestID, value, onChange, onSubmit, containerStyle }) {
|
|
1658
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1659
|
+
return /* @__PURE__ */ jsx(View, { style: containerStyle, testID, children: /* @__PURE__ */ jsx(
|
|
1660
|
+
DateField,
|
|
1661
|
+
{
|
|
1662
|
+
accessibilityHint: field.accessibilityHint ?? NO_HINT,
|
|
1663
|
+
label: field.label,
|
|
1664
|
+
testID: `${testID}-input`,
|
|
1665
|
+
value,
|
|
1666
|
+
onChange,
|
|
1667
|
+
onSubmit
|
|
1668
|
+
}
|
|
1669
|
+
) });
|
|
1670
|
+
}
|
|
1654
1671
|
function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
1655
1672
|
const { theme } = useUi();
|
|
1656
1673
|
const { colors } = theme;
|
|
@@ -1712,11 +1729,30 @@ function asRange(value) {
|
|
|
1712
1729
|
if (typeof value === "object" && value !== null && "from" in value && "to" in value) return value;
|
|
1713
1730
|
return EMPTY_RANGE;
|
|
1714
1731
|
}
|
|
1732
|
+
function fieldContainerStyle(field) {
|
|
1733
|
+
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1734
|
+
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1735
|
+
return [filterStyles.fieldInBar, { minWidth: clampedMinWidth(minWidth), maxWidth: "100%" }, grow, field.style];
|
|
1736
|
+
}
|
|
1715
1737
|
function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings, renderSelect }) {
|
|
1716
1738
|
const raw = values[field.key];
|
|
1717
1739
|
if (field.kind === "boolean") {
|
|
1718
1740
|
return /* @__PURE__ */ jsx(BooleanField, { field, barTestID, value: asBool(raw), onChange: (v) => setField(field.key, v) });
|
|
1719
1741
|
}
|
|
1742
|
+
const containerStyle = fieldContainerStyle(field);
|
|
1743
|
+
if (field.kind === "date") {
|
|
1744
|
+
return /* @__PURE__ */ jsx(
|
|
1745
|
+
SingleDateField,
|
|
1746
|
+
{
|
|
1747
|
+
barTestID,
|
|
1748
|
+
containerStyle,
|
|
1749
|
+
field,
|
|
1750
|
+
value: asString(raw),
|
|
1751
|
+
onChange: (v) => setField(field.key, v),
|
|
1752
|
+
onSubmit
|
|
1753
|
+
}
|
|
1754
|
+
);
|
|
1755
|
+
}
|
|
1720
1756
|
const body = (() => {
|
|
1721
1757
|
switch (field.kind) {
|
|
1722
1758
|
case "select":
|
|
@@ -1754,15 +1790,15 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1754
1790
|
);
|
|
1755
1791
|
case "dateRange":
|
|
1756
1792
|
return /* @__PURE__ */ jsx(
|
|
1757
|
-
|
|
1793
|
+
DateRangeControl,
|
|
1758
1794
|
{
|
|
1759
|
-
field,
|
|
1760
|
-
|
|
1795
|
+
accessibilityHint: field.accessibilityHint,
|
|
1796
|
+
fromLabel: field.fromLabel ?? strings.fromLabel,
|
|
1797
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1798
|
+
toLabel: field.toLabel ?? strings.toLabel,
|
|
1761
1799
|
value: asRange(raw),
|
|
1762
1800
|
onChange: (v) => setField(field.key, v),
|
|
1763
|
-
onSubmit
|
|
1764
|
-
fromLabel: strings.fromLabel,
|
|
1765
|
-
toLabel: strings.toLabel
|
|
1801
|
+
onSubmit
|
|
1766
1802
|
}
|
|
1767
1803
|
);
|
|
1768
1804
|
default:
|
|
@@ -1778,12 +1814,10 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1778
1814
|
);
|
|
1779
1815
|
}
|
|
1780
1816
|
})();
|
|
1781
|
-
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1782
|
-
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1783
1817
|
return /* @__PURE__ */ jsx(
|
|
1784
1818
|
Field,
|
|
1785
1819
|
{
|
|
1786
|
-
containerStyle
|
|
1820
|
+
containerStyle,
|
|
1787
1821
|
label: field.label,
|
|
1788
1822
|
labelVariant: "control",
|
|
1789
1823
|
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
@@ -2112,6 +2146,7 @@ var LedgerLayout = /* @__PURE__ */ ((LedgerLayout2) => {
|
|
|
2112
2146
|
LedgerLayout2["Feed"] = "feed";
|
|
2113
2147
|
return LedgerLayout2;
|
|
2114
2148
|
})(LedgerLayout || {});
|
|
2149
|
+
var LEDGER_ROW_ACTION_FALLBACK = { none: "status ledger caller passed no onRowPress" };
|
|
2115
2150
|
var GAP = 12;
|
|
2116
2151
|
var HEADING_FONT = 15;
|
|
2117
2152
|
var HEADING_WEIGHT = "700";
|
|
@@ -2134,6 +2169,7 @@ function LedgerSection({ title, rows, columns, emptyLabel, testID, ledger }) {
|
|
|
2134
2169
|
getRowDetailAccessibilityLabel: ledger.getRowAccessibilityLabel,
|
|
2135
2170
|
keyExtractor: ledger.keyExtractor,
|
|
2136
2171
|
onRowPress: ledger.onRowPress,
|
|
2172
|
+
rowAction: LEDGER_ROW_ACTION_FALLBACK,
|
|
2137
2173
|
renderRowDetail: ledger.renderRowDetail,
|
|
2138
2174
|
rows,
|
|
2139
2175
|
stackBreakpoint: ledger.breakpoint ?? CARD_STACK_BREAKPOINT,
|
|
@@ -2188,6 +2224,7 @@ function StatusLedger(props) {
|
|
|
2188
2224
|
keyExtractor: props.keyExtractor,
|
|
2189
2225
|
loading,
|
|
2190
2226
|
onRowPress: props.onRowPress,
|
|
2227
|
+
rowAction: LEDGER_ROW_ACTION_FALLBACK,
|
|
2191
2228
|
renderRowDetail: props.renderRowDetail,
|
|
2192
2229
|
rows: view.visible,
|
|
2193
2230
|
stackBreakpoint: feed ? breakpoint : 0,
|