@dloizides/ui-tables 1.21.1 → 1.23.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
@@ -1,4 +1,4 @@
1
- import React2, { memo, useState, useMemo, useCallback, useEffect, useRef, useLayoutEffect } from 'react';
1
+ import React2, { memo, createContext, useState, useMemo, useCallback, useEffect, useRef, useContext, useLayoutEffect } from 'react';
2
2
  import { StyleSheet, View, Text, Platform, useWindowDimensions, Pressable, Switch, TextInput } from 'react-native';
3
3
  import { useUi } from '@dloizides/ui-feedback';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
@@ -376,6 +376,9 @@ function RowCells({
376
376
  col.key
377
377
  )) });
378
378
  }
379
+ var RowPressContext = createContext(void 0);
380
+ var RowPressProvider = RowPressContext.Provider;
381
+ var useRowPress = () => useContext(RowPressContext);
379
382
  var CHECK_GLYPH = "\u2713";
380
383
  var MIXED_GLYPH = "\u2013";
381
384
  var TRANSPARENT = "transparent";
@@ -483,6 +486,7 @@ function DataTableRow({
483
486
  onRowPress,
484
487
  getRowAccessibilityLabel,
485
488
  renderRowDetail,
489
+ getRowDetailAccessibilityLabel,
486
490
  expanded,
487
491
  onHoverIn,
488
492
  onHoverOut,
@@ -494,6 +498,7 @@ function DataTableRow({
494
498
  const isExpandable = renderRowDetail !== void 0;
495
499
  const { selectable } = selection;
496
500
  const isSelected = selectable && selection.isSelected(rowKey);
501
+ const pressRow = onRowPress === void 0 ? void 0 : () => onRowPress(row);
497
502
  const a11y = {
498
503
  accessibilityLabel: getRowAccessibilityLabel?.(row) ?? t(TABLE_I18N.rowLabel),
499
504
  accessibilityHint: t(TABLE_I18N.rowHint),
@@ -533,8 +538,8 @@ function DataTableRow({
533
538
  testID: rowID,
534
539
  onHoverIn,
535
540
  onHoverOut,
536
- onPress: onRowPress === void 0 ? void 0 : () => onRowPress(row),
537
- children: /* @__PURE__ */ jsx(
541
+ onPress: pressRow,
542
+ children: /* @__PURE__ */ jsx(RowPressProvider, { value: pressRow, children: /* @__PURE__ */ jsx(
538
543
  RowCells,
539
544
  {
540
545
  columns,
@@ -546,7 +551,7 @@ function DataTableRow({
546
551
  styleOverrides: o,
547
552
  textColor: colors.text
548
553
  }
549
- )
554
+ ) })
550
555
  }
551
556
  );
552
557
  if (!isExpandable || !expanded) return rowNode;
@@ -555,7 +560,7 @@ function DataTableRow({
555
560
  /* @__PURE__ */ jsx(
556
561
  View,
557
562
  {
558
- accessibilityLabel: t(TABLE_I18N.rowDetail),
563
+ accessibilityLabel: getRowDetailAccessibilityLabel?.(row) ?? t(TABLE_I18N.rowDetail),
559
564
  accessibilityRole: "summary",
560
565
  style: [tableStyles.rowDetail, { borderTopColor: colors.border, backgroundColor: colors.background }, o?.rowDetail],
561
566
  testID: rowDetailTestID(tableTestID, rowKey),
@@ -853,6 +858,7 @@ function DataTable(props) {
853
858
  loadingLabel,
854
859
  emptyLabel,
855
860
  renderRowDetail,
861
+ getRowDetailAccessibilityLabel,
856
862
  expandedRowKeys,
857
863
  styleOverrides: o,
858
864
  selectedRowKeys,
@@ -917,6 +923,7 @@ function DataTable(props) {
917
923
  columns,
918
924
  expanded: expandedRowKeys?.includes(key) ?? false,
919
925
  getRowAccessibilityLabel,
926
+ getRowDetailAccessibilityLabel,
920
927
  keyboardNavigation,
921
928
  renderRowDetail,
922
929
  roving,
@@ -2010,6 +2017,7 @@ var LedgerLayout = /* @__PURE__ */ ((LedgerLayout2) => {
2010
2017
  var GAP = 12;
2011
2018
  var HEADING_FONT = 15;
2012
2019
  var HEADING_WEIGHT = "700";
2020
+ var expandedKeys = (key) => key === null || key === void 0 ? void 0 : [key];
2013
2021
  var styles3 = StyleSheet.create({
2014
2022
  root: { gap: GAP },
2015
2023
  heading: { fontSize: HEADING_FONT, fontWeight: HEADING_WEIGHT },
@@ -2023,9 +2031,12 @@ function LedgerSection({ title, rows, columns, emptyLabel, testID, ledger }) {
2023
2031
  DataTable,
2024
2032
  {
2025
2033
  columns,
2034
+ expandedRowKeys: expandedKeys(ledger.expandedRowKey),
2026
2035
  getRowAccessibilityLabel: ledger.getRowAccessibilityLabel,
2036
+ getRowDetailAccessibilityLabel: ledger.getRowAccessibilityLabel,
2027
2037
  keyExtractor: ledger.keyExtractor,
2028
2038
  onRowPress: ledger.onRowPress,
2039
+ renderRowDetail: ledger.renderRowDetail,
2029
2040
  rows,
2030
2041
  stackBreakpoint: ledger.breakpoint ?? CARD_STACK_BREAKPOINT,
2031
2042
  testID: `${testID}-table`
@@ -2073,10 +2084,13 @@ function StatusLedger(props) {
2073
2084
  {
2074
2085
  columns: view.tableColumns,
2075
2086
  emptyLabel: labels.empty,
2087
+ expandedRowKeys: expandedKeys(props.expandedRowKey),
2076
2088
  getRowAccessibilityLabel: props.getRowAccessibilityLabel,
2089
+ getRowDetailAccessibilityLabel: props.getRowAccessibilityLabel,
2077
2090
  keyExtractor: props.keyExtractor,
2078
2091
  loading,
2079
2092
  onRowPress: props.onRowPress,
2093
+ renderRowDetail: props.renderRowDetail,
2080
2094
  rows: view.visible,
2081
2095
  stackBreakpoint: feed ? breakpoint : 0,
2082
2096
  testID: `${testID}-table`
@@ -2118,6 +2132,7 @@ var defaultAbsolute = (ms) => new Date(ms).toLocaleString();
2118
2132
  function RelativeTime({ value, nowMs, strings, hint, formatAbsolute = defaultAbsolute, testID }) {
2119
2133
  const { theme } = useUi();
2120
2134
  const [showAbsolute, setShowAbsolute] = useState(false);
2135
+ const pressRow = useRowPress();
2121
2136
  const ms = toEpochMs(value);
2122
2137
  const relative = formatRelativeTime(value, nowMs, strings);
2123
2138
  const absolute = ms === null ? relative : formatAbsolute(ms);
@@ -2128,7 +2143,10 @@ function RelativeTime({ value, nowMs, strings, hint, formatAbsolute = defaultAbs
2128
2143
  accessibilityLabel: absolute,
2129
2144
  accessibilityRole: "button",
2130
2145
  disabled: ms === null,
2131
- onPress: () => setShowAbsolute((current) => !current),
2146
+ onPress: () => {
2147
+ setShowAbsolute((current) => !current);
2148
+ pressRow?.();
2149
+ },
2132
2150
  style: styles4.target,
2133
2151
  testID,
2134
2152
  children: /* @__PURE__ */ jsx(Text, { style: { color: theme.colors.text }, children: showAbsolute ? absolute : relative })