@dloizides/ui-tables 1.29.1 → 3.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 +24 -8
- package/dist/index.d.ts +24 -8
- package/dist/index.js +87 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -34
- 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,15 +446,40 @@ 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 focusRingStyle(focused, tokens) {
|
|
457
|
+
return focused === true ? { outlineStyle: "solid", outlineWidth: FOCUS_RING_WIDTH, outlineColor: tokens.brand, outlineOffset: FOCUS_RING_OFFSET } : null;
|
|
458
|
+
}
|
|
459
|
+
function rowInteractionStyle(state, tokens) {
|
|
460
|
+
const pressedTint = HEX_RGB2.test(tokens.brand) ? `${tokens.brand}${PRESSED_TINT_ALPHA}` : tokens.fallbackTint;
|
|
461
|
+
return [POINTER, state.pressed ? { backgroundColor: pressedTint } : null, focusRingStyle(state.focused, tokens)];
|
|
462
|
+
}
|
|
463
|
+
function useFrameFocus() {
|
|
464
|
+
const [focused, setFocused] = useState(false);
|
|
465
|
+
const onFocus = useCallback((event) => setFocused(event.target === event.currentTarget), []);
|
|
466
|
+
const onBlur = useCallback(() => setFocused(false), []);
|
|
467
|
+
return { focused, onFocus, onBlur };
|
|
468
|
+
}
|
|
449
469
|
var TAB_INDEX_INACTIVE = -1;
|
|
450
470
|
function webKeyProps(onKeyDown) {
|
|
451
471
|
return onKeyDown === void 0 ? {} : { onKeyDown };
|
|
452
472
|
}
|
|
453
|
-
function focusProps(keyboard) {
|
|
473
|
+
function focusProps(keyboard, frame) {
|
|
454
474
|
if (keyboard === void 0) return {};
|
|
475
|
+
const onFocus = frame === void 0 ? keyboard.onFocus : (event) => {
|
|
476
|
+
keyboard.onFocus();
|
|
477
|
+
frame.onFocus(event);
|
|
478
|
+
};
|
|
455
479
|
return {
|
|
456
480
|
tabIndex: keyboard.tabIndex,
|
|
457
|
-
onFocus
|
|
481
|
+
onFocus,
|
|
482
|
+
onBlur: frame?.onBlur,
|
|
458
483
|
ref: (node) => keyboard.registerNode(node),
|
|
459
484
|
...webKeyProps(keyboard.onKeyDown)
|
|
460
485
|
};
|
|
@@ -469,25 +494,28 @@ function TableRow({
|
|
|
469
494
|
onHoverOut,
|
|
470
495
|
selectionSlot,
|
|
471
496
|
stacked,
|
|
472
|
-
keyboard
|
|
497
|
+
keyboard,
|
|
498
|
+
interaction
|
|
473
499
|
}) {
|
|
474
500
|
const interactive = onPress !== void 0;
|
|
475
501
|
const hover = interactive ? { onHoverIn, onHoverOut } : null;
|
|
502
|
+
const frame = useFrameFocus();
|
|
503
|
+
const frameStyle = [style, focusRingStyle(frame.focused, interaction)];
|
|
476
504
|
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 });
|
|
505
|
+
return interactive ? /* @__PURE__ */ jsx(Pressable, { style: (state) => [style, rowInteractionStyle(state, interaction)], testID, onPress, ...hover, ...a11y, ...focusProps(keyboard), children }) : /* @__PURE__ */ jsx(View, { style: frameStyle, testID, ...a11y, ...focusProps(keyboard, frame), children });
|
|
478
506
|
}
|
|
479
507
|
const contentStyle = stacked ? selectionStyles.cardContent : selectionStyles.rowContent;
|
|
480
508
|
const content = interactive ? /* @__PURE__ */ jsx(
|
|
481
509
|
Pressable,
|
|
482
510
|
{
|
|
483
|
-
style: contentStyle,
|
|
511
|
+
style: (state) => [contentStyle, rowInteractionStyle(keyboard === void 0 ? state : { pressed: state.pressed }, interaction)],
|
|
484
512
|
tabIndex: keyboard === void 0 ? void 0 : TAB_INDEX_INACTIVE,
|
|
485
513
|
onPress,
|
|
486
514
|
...hover,
|
|
487
515
|
children
|
|
488
516
|
}
|
|
489
517
|
) : /* @__PURE__ */ jsx(View, { style: contentStyle, children });
|
|
490
|
-
return /* @__PURE__ */ jsxs(View, { style, testID, ...a11y, ...focusProps(keyboard), children: [
|
|
518
|
+
return /* @__PURE__ */ jsxs(View, { style: frameStyle, testID, ...a11y, ...focusProps(keyboard, frame), children: [
|
|
491
519
|
/* @__PURE__ */ jsx(View, { style: selectionStyles.selectCell, children: selectionSlot }),
|
|
492
520
|
content
|
|
493
521
|
] });
|
|
@@ -557,6 +585,7 @@ function DataTableRow({
|
|
|
557
585
|
testID: rowID,
|
|
558
586
|
onHoverIn,
|
|
559
587
|
onHoverOut,
|
|
588
|
+
interaction: { brand: theme.palette.primary["500"], fallbackTint: colors.border },
|
|
560
589
|
onPress: pressRow,
|
|
561
590
|
children: /* @__PURE__ */ jsx(RowPressProvider, { value: pressRow, children: /* @__PURE__ */ jsx(
|
|
562
591
|
RowCells,
|
|
@@ -1553,6 +1582,7 @@ var FIELD_MIN_WIDTH = {
|
|
|
1553
1582
|
select: 150,
|
|
1554
1583
|
text: 200,
|
|
1555
1584
|
number: 130,
|
|
1585
|
+
date: 160,
|
|
1556
1586
|
dateRange: 260,
|
|
1557
1587
|
typeahead: 200,
|
|
1558
1588
|
boolean: 150
|
|
@@ -1611,22 +1641,6 @@ function BooleanField({ field, barTestID, value, onChange }) {
|
|
|
1611
1641
|
)
|
|
1612
1642
|
] });
|
|
1613
1643
|
}
|
|
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
1644
|
function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
|
|
1631
1645
|
const { t } = useUi();
|
|
1632
1646
|
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
@@ -1651,6 +1665,21 @@ function SelectField({ field, barTestID, value, onChange, placeholder, dropdownH
|
|
|
1651
1665
|
}
|
|
1652
1666
|
);
|
|
1653
1667
|
}
|
|
1668
|
+
var NO_HINT = "";
|
|
1669
|
+
function SingleDateField({ field, barTestID, value, onChange, onSubmit, containerStyle }) {
|
|
1670
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1671
|
+
return /* @__PURE__ */ jsx(View, { style: containerStyle, testID, children: /* @__PURE__ */ jsx(
|
|
1672
|
+
DateField,
|
|
1673
|
+
{
|
|
1674
|
+
accessibilityHint: field.accessibilityHint ?? NO_HINT,
|
|
1675
|
+
label: field.label,
|
|
1676
|
+
testID: `${testID}-input`,
|
|
1677
|
+
value,
|
|
1678
|
+
onChange,
|
|
1679
|
+
onSubmit
|
|
1680
|
+
}
|
|
1681
|
+
) });
|
|
1682
|
+
}
|
|
1654
1683
|
function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
1655
1684
|
const { theme } = useUi();
|
|
1656
1685
|
const { colors } = theme;
|
|
@@ -1712,11 +1741,30 @@ function asRange(value) {
|
|
|
1712
1741
|
if (typeof value === "object" && value !== null && "from" in value && "to" in value) return value;
|
|
1713
1742
|
return EMPTY_RANGE;
|
|
1714
1743
|
}
|
|
1744
|
+
function fieldContainerStyle(field) {
|
|
1745
|
+
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1746
|
+
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1747
|
+
return [filterStyles.fieldInBar, { minWidth: clampedMinWidth(minWidth), maxWidth: "100%" }, grow, field.style];
|
|
1748
|
+
}
|
|
1715
1749
|
function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings, renderSelect }) {
|
|
1716
1750
|
const raw = values[field.key];
|
|
1717
1751
|
if (field.kind === "boolean") {
|
|
1718
1752
|
return /* @__PURE__ */ jsx(BooleanField, { field, barTestID, value: asBool(raw), onChange: (v) => setField(field.key, v) });
|
|
1719
1753
|
}
|
|
1754
|
+
const containerStyle = fieldContainerStyle(field);
|
|
1755
|
+
if (field.kind === "date") {
|
|
1756
|
+
return /* @__PURE__ */ jsx(
|
|
1757
|
+
SingleDateField,
|
|
1758
|
+
{
|
|
1759
|
+
barTestID,
|
|
1760
|
+
containerStyle,
|
|
1761
|
+
field,
|
|
1762
|
+
value: asString(raw),
|
|
1763
|
+
onChange: (v) => setField(field.key, v),
|
|
1764
|
+
onSubmit
|
|
1765
|
+
}
|
|
1766
|
+
);
|
|
1767
|
+
}
|
|
1720
1768
|
const body = (() => {
|
|
1721
1769
|
switch (field.kind) {
|
|
1722
1770
|
case "select":
|
|
@@ -1754,15 +1802,15 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1754
1802
|
);
|
|
1755
1803
|
case "dateRange":
|
|
1756
1804
|
return /* @__PURE__ */ jsx(
|
|
1757
|
-
|
|
1805
|
+
DateRangeControl,
|
|
1758
1806
|
{
|
|
1759
|
-
field,
|
|
1760
|
-
|
|
1807
|
+
accessibilityHint: field.accessibilityHint,
|
|
1808
|
+
fromLabel: field.fromLabel ?? strings.fromLabel,
|
|
1809
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1810
|
+
toLabel: field.toLabel ?? strings.toLabel,
|
|
1761
1811
|
value: asRange(raw),
|
|
1762
1812
|
onChange: (v) => setField(field.key, v),
|
|
1763
|
-
onSubmit
|
|
1764
|
-
fromLabel: strings.fromLabel,
|
|
1765
|
-
toLabel: strings.toLabel
|
|
1813
|
+
onSubmit
|
|
1766
1814
|
}
|
|
1767
1815
|
);
|
|
1768
1816
|
default:
|
|
@@ -1778,12 +1826,10 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1778
1826
|
);
|
|
1779
1827
|
}
|
|
1780
1828
|
})();
|
|
1781
|
-
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1782
|
-
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1783
1829
|
return /* @__PURE__ */ jsx(
|
|
1784
1830
|
Field,
|
|
1785
1831
|
{
|
|
1786
|
-
containerStyle
|
|
1832
|
+
containerStyle,
|
|
1787
1833
|
label: field.label,
|
|
1788
1834
|
labelVariant: "control",
|
|
1789
1835
|
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
@@ -1933,6 +1979,14 @@ function usePagedRows(rows, options = {}) {
|
|
|
1933
1979
|
};
|
|
1934
1980
|
}
|
|
1935
1981
|
|
|
1982
|
+
// src/DataTable/rowAction.ts
|
|
1983
|
+
function declaresNoRowAction(action) {
|
|
1984
|
+
return action.rowAction !== void 0;
|
|
1985
|
+
}
|
|
1986
|
+
function pickRowAction(action) {
|
|
1987
|
+
return declaresNoRowAction(action) ? { onRowPress: action.onRowPress, rowAction: action.rowAction } : { onRowPress: action.onRowPress };
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1936
1990
|
// src/StatusLedger/StatusTone.ts
|
|
1937
1991
|
var StatusTone = /* @__PURE__ */ ((StatusTone2) => {
|
|
1938
1992
|
StatusTone2["Bad"] = "bad";
|
|
@@ -2133,7 +2187,7 @@ function LedgerSection({ title, rows, columns, emptyLabel, testID, ledger }) {
|
|
|
2133
2187
|
getRowAccessibilityLabel: ledger.getRowAccessibilityLabel,
|
|
2134
2188
|
getRowDetailAccessibilityLabel: ledger.getRowAccessibilityLabel,
|
|
2135
2189
|
keyExtractor: ledger.keyExtractor,
|
|
2136
|
-
|
|
2190
|
+
...pickRowAction(ledger),
|
|
2137
2191
|
renderRowDetail: ledger.renderRowDetail,
|
|
2138
2192
|
rows,
|
|
2139
2193
|
stackBreakpoint: ledger.breakpoint ?? CARD_STACK_BREAKPOINT,
|
|
@@ -2187,7 +2241,7 @@ function StatusLedger(props) {
|
|
|
2187
2241
|
getRowDetailAccessibilityLabel: props.getRowAccessibilityLabel,
|
|
2188
2242
|
keyExtractor: props.keyExtractor,
|
|
2189
2243
|
loading,
|
|
2190
|
-
|
|
2244
|
+
...pickRowAction(props),
|
|
2191
2245
|
renderRowDetail: props.renderRowDetail,
|
|
2192
2246
|
rows: view.visible,
|
|
2193
2247
|
stackBreakpoint: feed ? breakpoint : 0,
|