@dloizides/ui-tables 2.0.0 → 3.0.1

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.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 { DateRangeControl, Field, controlStyles, DateField, TypeaheadControl, DEFAULT_TYPEAHEAD_MIN_CHARS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, SelectControl } from '@dloizides/ui-forms';
8
+ import { DateRangeControl, DateInput, Field, controlStyles, 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
 
@@ -453,23 +453,33 @@ var HEX_RGB2 = /^#[0-9a-f]{6}$/i;
453
453
  var FOCUS_RING_WIDTH = 2;
454
454
  var FOCUS_RING_OFFSET = -2;
455
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
+ }
456
459
  function rowInteractionStyle(state, tokens) {
457
460
  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
- ];
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 };
463
468
  }
464
469
  var TAB_INDEX_INACTIVE = -1;
465
470
  function webKeyProps(onKeyDown) {
466
471
  return onKeyDown === void 0 ? {} : { onKeyDown };
467
472
  }
468
- function focusProps(keyboard) {
473
+ function focusProps(keyboard, frame) {
469
474
  if (keyboard === void 0) return {};
475
+ const onFocus = frame === void 0 ? keyboard.onFocus : (event) => {
476
+ keyboard.onFocus();
477
+ frame.onFocus(event);
478
+ };
470
479
  return {
471
480
  tabIndex: keyboard.tabIndex,
472
- onFocus: keyboard.onFocus,
481
+ onFocus,
482
+ onBlur: frame?.onBlur,
473
483
  ref: (node) => keyboard.registerNode(node),
474
484
  ...webKeyProps(keyboard.onKeyDown)
475
485
  };
@@ -489,21 +499,23 @@ function TableRow({
489
499
  }) {
490
500
  const interactive = onPress !== void 0;
491
501
  const hover = interactive ? { onHoverIn, onHoverOut } : null;
502
+ const frame = useFrameFocus();
503
+ const frameStyle = [style, focusRingStyle(frame.focused, interaction)];
492
504
  if (selectionSlot === void 0) {
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 });
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 });
494
506
  }
495
507
  const contentStyle = stacked ? selectionStyles.cardContent : selectionStyles.rowContent;
496
508
  const content = interactive ? /* @__PURE__ */ jsx(
497
509
  Pressable,
498
510
  {
499
- style: (state) => [contentStyle, rowInteractionStyle(state, interaction)],
511
+ style: (state) => [contentStyle, rowInteractionStyle(keyboard === void 0 ? state : { pressed: state.pressed }, interaction)],
500
512
  tabIndex: keyboard === void 0 ? void 0 : TAB_INDEX_INACTIVE,
501
513
  onPress,
502
514
  ...hover,
503
515
  children
504
516
  }
505
517
  ) : /* @__PURE__ */ jsx(View, { style: contentStyle, children });
506
- return /* @__PURE__ */ jsxs(View, { style, testID, ...a11y, ...focusProps(keyboard), children: [
518
+ return /* @__PURE__ */ jsxs(View, { style: frameStyle, testID, ...a11y, ...focusProps(keyboard, frame), children: [
507
519
  /* @__PURE__ */ jsx(View, { style: selectionStyles.selectCell, children: selectionSlot }),
508
520
  content
509
521
  ] });
@@ -1653,21 +1665,6 @@ function SelectField({ field, barTestID, value, onChange, placeholder, dropdownH
1653
1665
  }
1654
1666
  );
1655
1667
  }
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
- }
1671
1668
  function TextField({ field, barTestID, value, onChange, onSubmit }) {
1672
1669
  const { theme } = useUi();
1673
1670
  const { colors } = theme;
@@ -1719,6 +1716,7 @@ function clampedMinWidth(minWidth) {
1719
1716
  }
1720
1717
  var EMPTY_RANGE = { from: "", to: "" };
1721
1718
  var GROW_FLEX = 1;
1719
+ var NO_HINT = "";
1722
1720
  function asString(value) {
1723
1721
  return typeof value === "string" ? value : "";
1724
1722
  }
@@ -1740,21 +1738,26 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
1740
1738
  return /* @__PURE__ */ jsx(BooleanField, { field, barTestID, value: asBool(raw), onChange: (v) => setField(field.key, v) });
1741
1739
  }
1742
1740
  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
- }
1741
+ const testID = field.testID ?? fieldTestID(barTestID, field.key);
1756
1742
  const body = (() => {
1757
1743
  switch (field.kind) {
1744
+ case "date":
1745
+ return function renderDateInput(context) {
1746
+ return /* @__PURE__ */ jsx(
1747
+ DateInput,
1748
+ {
1749
+ context,
1750
+ fieldProps: {
1751
+ accessibilityHint: field.accessibilityHint ?? NO_HINT,
1752
+ label: field.label,
1753
+ testID: `${testID}-input`,
1754
+ value: asString(raw),
1755
+ onChange: (v) => setField(field.key, v),
1756
+ onSubmit
1757
+ }
1758
+ }
1759
+ );
1760
+ };
1758
1761
  case "select":
1759
1762
  if (renderSelect !== void 0) {
1760
1763
  return renderSelect({
@@ -1820,7 +1823,7 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
1820
1823
  containerStyle,
1821
1824
  label: field.label,
1822
1825
  labelVariant: "control",
1823
- testID: field.testID ?? fieldTestID(barTestID, field.key),
1826
+ testID,
1824
1827
  children: body
1825
1828
  }
1826
1829
  );
@@ -1967,6 +1970,14 @@ function usePagedRows(rows, options = {}) {
1967
1970
  };
1968
1971
  }
1969
1972
 
1973
+ // src/DataTable/rowAction.ts
1974
+ function declaresNoRowAction(action) {
1975
+ return action.rowAction !== void 0;
1976
+ }
1977
+ function pickRowAction(action) {
1978
+ return declaresNoRowAction(action) ? { onRowPress: action.onRowPress, rowAction: action.rowAction } : { onRowPress: action.onRowPress };
1979
+ }
1980
+
1970
1981
  // src/StatusLedger/StatusTone.ts
1971
1982
  var StatusTone = /* @__PURE__ */ ((StatusTone2) => {
1972
1983
  StatusTone2["Bad"] = "bad";
@@ -2146,7 +2157,6 @@ var LedgerLayout = /* @__PURE__ */ ((LedgerLayout2) => {
2146
2157
  LedgerLayout2["Feed"] = "feed";
2147
2158
  return LedgerLayout2;
2148
2159
  })(LedgerLayout || {});
2149
- var LEDGER_ROW_ACTION_FALLBACK = { none: "status ledger caller passed no onRowPress" };
2150
2160
  var GAP = 12;
2151
2161
  var HEADING_FONT = 15;
2152
2162
  var HEADING_WEIGHT = "700";
@@ -2168,8 +2178,7 @@ function LedgerSection({ title, rows, columns, emptyLabel, testID, ledger }) {
2168
2178
  getRowAccessibilityLabel: ledger.getRowAccessibilityLabel,
2169
2179
  getRowDetailAccessibilityLabel: ledger.getRowAccessibilityLabel,
2170
2180
  keyExtractor: ledger.keyExtractor,
2171
- onRowPress: ledger.onRowPress,
2172
- rowAction: LEDGER_ROW_ACTION_FALLBACK,
2181
+ ...pickRowAction(ledger),
2173
2182
  renderRowDetail: ledger.renderRowDetail,
2174
2183
  rows,
2175
2184
  stackBreakpoint: ledger.breakpoint ?? CARD_STACK_BREAKPOINT,
@@ -2223,8 +2232,7 @@ function StatusLedger(props) {
2223
2232
  getRowDetailAccessibilityLabel: props.getRowAccessibilityLabel,
2224
2233
  keyExtractor: props.keyExtractor,
2225
2234
  loading,
2226
- onRowPress: props.onRowPress,
2227
- rowAction: LEDGER_ROW_ACTION_FALLBACK,
2235
+ ...pickRowAction(props),
2228
2236
  renderRowDetail: props.renderRowDetail,
2229
2237
  rows: view.visible,
2230
2238
  stackBreakpoint: feed ? breakpoint : 0,