@dloizides/ui-tables 2.0.0 → 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 CHANGED
@@ -874,7 +874,7 @@ interface StatusLedgerLabels {
874
874
  actions: string;
875
875
  }
876
876
  type ToneColors = Partial<Record<StatusTone, string>>;
877
- interface StatusLedgerProps<T> {
877
+ interface StatusLedgerBaseProps<T> {
878
878
  rows: readonly T[];
879
879
  columns: ReadonlyArray<StatusLedgerColumn<T>>;
880
880
  keyExtractor: (row: T) => string;
@@ -887,7 +887,6 @@ interface StatusLedgerProps<T> {
887
887
  getSearchText?: (row: T) => string;
888
888
  needsLook?: (row: T) => boolean;
889
889
  getRowAccessibilityLabel?: (row: T) => string;
890
- onRowPress?: (row: T) => void;
891
890
  renderActions?: (row: T) => React.ReactNode;
892
891
  /** Renders a detail region directly under the expanded row (table and card layouts); labelled by `getRowAccessibilityLabel`. */
893
892
  renderRowDetail?: (row: T) => React.ReactNode;
@@ -899,6 +898,7 @@ interface StatusLedgerProps<T> {
899
898
  loading?: boolean;
900
899
  testID?: string;
901
900
  }
901
+ type StatusLedgerProps<T> = StatusLedgerBaseProps<T> & DataTableRowAction<T>;
902
902
  interface LedgerFilter {
903
903
  status: string;
904
904
  group: string;
package/dist/index.d.ts CHANGED
@@ -874,7 +874,7 @@ interface StatusLedgerLabels {
874
874
  actions: string;
875
875
  }
876
876
  type ToneColors = Partial<Record<StatusTone, string>>;
877
- interface StatusLedgerProps<T> {
877
+ interface StatusLedgerBaseProps<T> {
878
878
  rows: readonly T[];
879
879
  columns: ReadonlyArray<StatusLedgerColumn<T>>;
880
880
  keyExtractor: (row: T) => string;
@@ -887,7 +887,6 @@ interface StatusLedgerProps<T> {
887
887
  getSearchText?: (row: T) => string;
888
888
  needsLook?: (row: T) => boolean;
889
889
  getRowAccessibilityLabel?: (row: T) => string;
890
- onRowPress?: (row: T) => void;
891
890
  renderActions?: (row: T) => React.ReactNode;
892
891
  /** Renders a detail region directly under the expanded row (table and card layouts); labelled by `getRowAccessibilityLabel`. */
893
892
  renderRowDetail?: (row: T) => React.ReactNode;
@@ -899,6 +898,7 @@ interface StatusLedgerProps<T> {
899
898
  loading?: boolean;
900
899
  testID?: string;
901
900
  }
901
+ type StatusLedgerProps<T> = StatusLedgerBaseProps<T> & DataTableRowAction<T>;
902
902
  interface LedgerFilter {
903
903
  status: string;
904
904
  group: string;
package/dist/index.js CHANGED
@@ -458,23 +458,33 @@ var HEX_RGB2 = /^#[0-9a-f]{6}$/i;
458
458
  var FOCUS_RING_WIDTH = 2;
459
459
  var FOCUS_RING_OFFSET = -2;
460
460
  var POINTER = { cursor: "pointer" };
461
+ function focusRingStyle(focused, tokens) {
462
+ return focused === true ? { outlineStyle: "solid", outlineWidth: FOCUS_RING_WIDTH, outlineColor: tokens.brand, outlineOffset: FOCUS_RING_OFFSET } : null;
463
+ }
461
464
  function rowInteractionStyle(state, tokens) {
462
465
  const pressedTint = HEX_RGB2.test(tokens.brand) ? `${tokens.brand}${PRESSED_TINT_ALPHA}` : tokens.fallbackTint;
463
- return [
464
- POINTER,
465
- state.pressed ? { backgroundColor: pressedTint } : null,
466
- state.focused === true ? { outlineStyle: "solid", outlineWidth: FOCUS_RING_WIDTH, outlineColor: tokens.brand, outlineOffset: FOCUS_RING_OFFSET } : null
467
- ];
466
+ return [POINTER, state.pressed ? { backgroundColor: pressedTint } : null, focusRingStyle(state.focused, tokens)];
467
+ }
468
+ function useFrameFocus() {
469
+ const [focused, setFocused] = React2.useState(false);
470
+ const onFocus = React2.useCallback((event) => setFocused(event.target === event.currentTarget), []);
471
+ const onBlur = React2.useCallback(() => setFocused(false), []);
472
+ return { focused, onFocus, onBlur };
468
473
  }
469
474
  var TAB_INDEX_INACTIVE = -1;
470
475
  function webKeyProps(onKeyDown) {
471
476
  return onKeyDown === void 0 ? {} : { onKeyDown };
472
477
  }
473
- function focusProps(keyboard) {
478
+ function focusProps(keyboard, frame) {
474
479
  if (keyboard === void 0) return {};
480
+ const onFocus = frame === void 0 ? keyboard.onFocus : (event) => {
481
+ keyboard.onFocus();
482
+ frame.onFocus(event);
483
+ };
475
484
  return {
476
485
  tabIndex: keyboard.tabIndex,
477
- onFocus: keyboard.onFocus,
486
+ onFocus,
487
+ onBlur: frame?.onBlur,
478
488
  ref: (node) => keyboard.registerNode(node),
479
489
  ...webKeyProps(keyboard.onKeyDown)
480
490
  };
@@ -494,21 +504,23 @@ function TableRow({
494
504
  }) {
495
505
  const interactive = onPress !== void 0;
496
506
  const hover = interactive ? { onHoverIn, onHoverOut } : null;
507
+ const frame = useFrameFocus();
508
+ const frameStyle = [style, focusRingStyle(frame.focused, interaction)];
497
509
  if (selectionSlot === void 0) {
498
- return interactive ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { style: (state) => [style, rowInteractionStyle(state, interaction)], testID, onPress, ...hover, ...a11y, ...focusProps(keyboard), children }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style, testID, ...a11y, ...focusProps(keyboard), children });
510
+ return interactive ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { style: (state) => [style, rowInteractionStyle(state, interaction)], testID, onPress, ...hover, ...a11y, ...focusProps(keyboard), children }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: frameStyle, testID, ...a11y, ...focusProps(keyboard, frame), children });
499
511
  }
500
512
  const contentStyle = stacked ? selectionStyles.cardContent : selectionStyles.rowContent;
501
513
  const content = interactive ? /* @__PURE__ */ jsxRuntime.jsx(
502
514
  reactNative.Pressable,
503
515
  {
504
- style: (state) => [contentStyle, rowInteractionStyle(state, interaction)],
516
+ style: (state) => [contentStyle, rowInteractionStyle(keyboard === void 0 ? state : { pressed: state.pressed }, interaction)],
505
517
  tabIndex: keyboard === void 0 ? void 0 : TAB_INDEX_INACTIVE,
506
518
  onPress,
507
519
  ...hover,
508
520
  children
509
521
  }
510
522
  ) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: contentStyle, children });
511
- return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style, testID, ...a11y, ...focusProps(keyboard), children: [
523
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: frameStyle, testID, ...a11y, ...focusProps(keyboard, frame), children: [
512
524
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: selectionStyles.selectCell, children: selectionSlot }),
513
525
  content
514
526
  ] });
@@ -1972,6 +1984,14 @@ function usePagedRows(rows, options = {}) {
1972
1984
  };
1973
1985
  }
1974
1986
 
1987
+ // src/DataTable/rowAction.ts
1988
+ function declaresNoRowAction(action) {
1989
+ return action.rowAction !== void 0;
1990
+ }
1991
+ function pickRowAction(action) {
1992
+ return declaresNoRowAction(action) ? { onRowPress: action.onRowPress, rowAction: action.rowAction } : { onRowPress: action.onRowPress };
1993
+ }
1994
+
1975
1995
  // src/StatusLedger/StatusTone.ts
1976
1996
  var StatusTone = /* @__PURE__ */ ((StatusTone2) => {
1977
1997
  StatusTone2["Bad"] = "bad";
@@ -2151,7 +2171,6 @@ var LedgerLayout = /* @__PURE__ */ ((LedgerLayout2) => {
2151
2171
  LedgerLayout2["Feed"] = "feed";
2152
2172
  return LedgerLayout2;
2153
2173
  })(LedgerLayout || {});
2154
- var LEDGER_ROW_ACTION_FALLBACK = { none: "status ledger caller passed no onRowPress" };
2155
2174
  var GAP = 12;
2156
2175
  var HEADING_FONT = 15;
2157
2176
  var HEADING_WEIGHT = "700";
@@ -2173,8 +2192,7 @@ function LedgerSection({ title, rows, columns, emptyLabel, testID, ledger }) {
2173
2192
  getRowAccessibilityLabel: ledger.getRowAccessibilityLabel,
2174
2193
  getRowDetailAccessibilityLabel: ledger.getRowAccessibilityLabel,
2175
2194
  keyExtractor: ledger.keyExtractor,
2176
- onRowPress: ledger.onRowPress,
2177
- rowAction: LEDGER_ROW_ACTION_FALLBACK,
2195
+ ...pickRowAction(ledger),
2178
2196
  renderRowDetail: ledger.renderRowDetail,
2179
2197
  rows,
2180
2198
  stackBreakpoint: ledger.breakpoint ?? CARD_STACK_BREAKPOINT,
@@ -2228,8 +2246,7 @@ function StatusLedger(props) {
2228
2246
  getRowDetailAccessibilityLabel: props.getRowAccessibilityLabel,
2229
2247
  keyExtractor: props.keyExtractor,
2230
2248
  loading,
2231
- onRowPress: props.onRowPress,
2232
- rowAction: LEDGER_ROW_ACTION_FALLBACK,
2249
+ ...pickRowAction(props),
2233
2250
  renderRowDetail: props.renderRowDetail,
2234
2251
  rows: view.visible,
2235
2252
  stackBreakpoint: feed ? breakpoint : 0,