@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.mjs CHANGED
@@ -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
  ] });
@@ -1967,6 +1979,14 @@ function usePagedRows(rows, options = {}) {
1967
1979
  };
1968
1980
  }
1969
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
+
1970
1990
  // src/StatusLedger/StatusTone.ts
1971
1991
  var StatusTone = /* @__PURE__ */ ((StatusTone2) => {
1972
1992
  StatusTone2["Bad"] = "bad";
@@ -2146,7 +2166,6 @@ var LedgerLayout = /* @__PURE__ */ ((LedgerLayout2) => {
2146
2166
  LedgerLayout2["Feed"] = "feed";
2147
2167
  return LedgerLayout2;
2148
2168
  })(LedgerLayout || {});
2149
- var LEDGER_ROW_ACTION_FALLBACK = { none: "status ledger caller passed no onRowPress" };
2150
2169
  var GAP = 12;
2151
2170
  var HEADING_FONT = 15;
2152
2171
  var HEADING_WEIGHT = "700";
@@ -2168,8 +2187,7 @@ function LedgerSection({ title, rows, columns, emptyLabel, testID, ledger }) {
2168
2187
  getRowAccessibilityLabel: ledger.getRowAccessibilityLabel,
2169
2188
  getRowDetailAccessibilityLabel: ledger.getRowAccessibilityLabel,
2170
2189
  keyExtractor: ledger.keyExtractor,
2171
- onRowPress: ledger.onRowPress,
2172
- rowAction: LEDGER_ROW_ACTION_FALLBACK,
2190
+ ...pickRowAction(ledger),
2173
2191
  renderRowDetail: ledger.renderRowDetail,
2174
2192
  rows,
2175
2193
  stackBreakpoint: ledger.breakpoint ?? CARD_STACK_BREAKPOINT,
@@ -2223,8 +2241,7 @@ function StatusLedger(props) {
2223
2241
  getRowDetailAccessibilityLabel: props.getRowAccessibilityLabel,
2224
2242
  keyExtractor: props.keyExtractor,
2225
2243
  loading,
2226
- onRowPress: props.onRowPress,
2227
- rowAction: LEDGER_ROW_ACTION_FALLBACK,
2244
+ ...pickRowAction(props),
2228
2245
  renderRowDetail: props.renderRowDetail,
2229
2246
  rows: view.visible,
2230
2247
  stackBreakpoint: feed ? breakpoint : 0,