@dloizides/ui-tables 1.29.0 → 2.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
@@ -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, DateRangeControl, TypeaheadControl, DEFAULT_TYPEAHEAD_MIN_CHARS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, SelectControl } from '@dloizides/ui-forms';
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
 
@@ -328,23 +328,6 @@ var chromeStyles = StyleSheet.create({
328
328
  sizeOption: { minHeight: MIN_TARGET_PX, justifyContent: "center", paddingHorizontal: CONTROL_PAD_H, paddingVertical: MENU_OPT_PAD_V },
329
329
  sizeOptionText: { fontSize: CONTROL_FONT, fontVariant: ["tabular-nums"] }
330
330
  });
331
-
332
- // src/DataTable/joinedFrameContext.ts
333
- var SQUARE = 0;
334
- var INNER_RADIUS = BORDER_RADIUS - BORDER_WIDTH;
335
- var NO_OUTER_BORDER = { borderTopWidth: 0, borderRightWidth: 0, borderBottomWidth: 0, borderLeftWidth: 0 };
336
- function cornerRadii(top, bottom) {
337
- return { borderTopLeftRadius: top, borderTopRightRadius: top, borderBottomLeftRadius: bottom, borderBottomRightRadius: bottom };
338
- }
339
- var AT_FRAME_TOP = { ...NO_OUTER_BORDER, ...cornerRadii(INNER_RADIUS, SQUARE) };
340
- var AT_FRAME_BOTTOM = { ...NO_OUTER_BORDER, ...cornerRadii(SQUARE, INNER_RADIUS) };
341
- var JOINED_FRAME_STYLES = {
342
- toolbar: { wrap: AT_FRAME_BOTTOM },
343
- spaced: null,
344
- footer: { wrap: AT_FRAME_TOP },
345
- panel: { wrap: AT_FRAME_BOTTOM, filters: AT_FRAME_TOP }
346
- };
347
- var JoinedFrameContext = createContext(null);
348
331
  function cellContent(column, row, textColor, overrides) {
349
332
  const content = column.render(row);
350
333
  if (typeof content === "string" || typeof content === "number") {
@@ -463,6 +446,21 @@ function SelectionCheckbox({
463
446
  }
464
447
  );
465
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 rowInteractionStyle(state, tokens) {
457
+ 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
+ ];
463
+ }
466
464
  var TAB_INDEX_INACTIVE = -1;
467
465
  function webKeyProps(onKeyDown) {
468
466
  return onKeyDown === void 0 ? {} : { onKeyDown };
@@ -486,18 +484,19 @@ function TableRow({
486
484
  onHoverOut,
487
485
  selectionSlot,
488
486
  stacked,
489
- keyboard
487
+ keyboard,
488
+ interaction
490
489
  }) {
491
490
  const interactive = onPress !== void 0;
492
491
  const hover = interactive ? { onHoverIn, onHoverOut } : null;
493
492
  if (selectionSlot === void 0) {
494
- return interactive ? /* @__PURE__ */ jsx(Pressable, { style, testID, onPress, ...hover, ...a11y, ...focusProps(keyboard), children }) : /* @__PURE__ */ jsx(View, { style, testID, ...a11y, ...focusProps(keyboard), children });
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 });
495
494
  }
496
495
  const contentStyle = stacked ? selectionStyles.cardContent : selectionStyles.rowContent;
497
496
  const content = interactive ? /* @__PURE__ */ jsx(
498
497
  Pressable,
499
498
  {
500
- style: contentStyle,
499
+ style: (state) => [contentStyle, rowInteractionStyle(state, interaction)],
501
500
  tabIndex: keyboard === void 0 ? void 0 : TAB_INDEX_INACTIVE,
502
501
  onPress,
503
502
  ...hover,
@@ -574,6 +573,7 @@ function DataTableRow({
574
573
  testID: rowID,
575
574
  onHoverIn,
576
575
  onHoverOut,
576
+ interaction: { brand: theme.palette.primary["500"], fallbackTint: colors.border },
577
577
  onPress: pressRow,
578
578
  children: /* @__PURE__ */ jsx(RowPressProvider, { value: pressRow, children: /* @__PURE__ */ jsx(
579
579
  RowCells,
@@ -600,11 +600,37 @@ function DataTableRow({
600
600
  accessibilityRole: "summary",
601
601
  style: [tableStyles.rowDetail, { borderTopColor: colors.border, backgroundColor: colors.background }, o?.rowDetail],
602
602
  testID: rowDetailTestID(tableTestID, rowKey),
603
- children: /* @__PURE__ */ jsx(JoinedFrameContext.Provider, { value: null, children: renderRowDetail(row) })
603
+ children: renderRowDetail(row)
604
604
  }
605
605
  )
606
606
  ] });
607
607
  }
608
+
609
+ // src/DataTable/PagedTableLayoutKind.ts
610
+ var PagedTableLayoutKind = /* @__PURE__ */ ((PagedTableLayoutKind2) => {
611
+ PagedTableLayoutKind2["Toolbar"] = "toolbar";
612
+ PagedTableLayoutKind2["Spaced"] = "spaced";
613
+ PagedTableLayoutKind2["Footer"] = "footer";
614
+ PagedTableLayoutKind2["Panel"] = "panel";
615
+ return PagedTableLayoutKind2;
616
+ })(PagedTableLayoutKind || {});
617
+
618
+ // src/DataTable/joinedFrameContext.ts
619
+ var SQUARE = 0;
620
+ var INNER_RADIUS = BORDER_RADIUS - BORDER_WIDTH;
621
+ var NO_OUTER_BORDER = { borderTopWidth: 0, borderRightWidth: 0, borderBottomWidth: 0, borderLeftWidth: 0 };
622
+ function cornerRadii(top, bottom) {
623
+ return { borderTopLeftRadius: top, borderTopRightRadius: top, borderBottomLeftRadius: bottom, borderBottomRightRadius: bottom };
624
+ }
625
+ var AT_FRAME_TOP = { ...NO_OUTER_BORDER, ...cornerRadii(INNER_RADIUS, SQUARE) };
626
+ var AT_FRAME_BOTTOM = { ...NO_OUTER_BORDER, ...cornerRadii(SQUARE, INNER_RADIUS) };
627
+ var JOINED_FRAME_STYLES = {
628
+ ["toolbar" /* Toolbar */]: { wrap: AT_FRAME_BOTTOM },
629
+ ["spaced" /* Spaced */]: null,
630
+ ["footer" /* Footer */]: { wrap: AT_FRAME_TOP },
631
+ ["panel" /* Panel */]: { wrap: AT_FRAME_BOTTOM, filters: AT_FRAME_TOP }
632
+ };
633
+ var JoinedFrameContext = createContext(null);
608
634
  function SelectAllBanner({
609
635
  mode,
610
636
  pageCount,
@@ -976,8 +1002,9 @@ function DataTable(props) {
976
1002
  onRowPress
977
1003
  }
978
1004
  );
979
- if (!animateRowEntrance) return /* @__PURE__ */ jsx(React2.Fragment, { children: node }, key);
980
- return /* @__PURE__ */ jsx(FadeIn, { delay: rowEntranceDelayMs(index), testID: rowFadeTestID(testID, key), children: node }, key);
1005
+ const detachedFromFrame = /* @__PURE__ */ jsx(JoinedFrameContext.Provider, { value: null, children: node });
1006
+ if (!animateRowEntrance) return /* @__PURE__ */ jsx(React2.Fragment, { children: detachedFromFrame }, key);
1007
+ return /* @__PURE__ */ jsx(FadeIn, { delay: rowEntranceDelayMs(index), testID: rowFadeTestID(testID, key), children: detachedFromFrame }, key);
981
1008
  };
982
1009
  const banner = /* @__PURE__ */ jsx(
983
1010
  SelectAllBanner,
@@ -1448,28 +1475,28 @@ var PAGER_SLOT_PAD_V = 8;
1448
1475
  var PAGER_IN_FRAME = { paddingHorizontal: ROW_PAD_H, paddingVertical: PAGER_SLOT_PAD_V };
1449
1476
  var FRAME = { borderWidth: BORDER_WIDTH, borderRadius: BORDER_RADIUS };
1450
1477
  var SLOT_STYLES = {
1451
- toolbar: { filters: { marginBottom: LAYOUT_GAP }, pager: { ...PAGER_IN_FRAME, borderBottomWidth: BORDER_WIDTH } },
1452
- spaced: { filters: {}, pager: { marginTop: LAYOUT_GAP, marginBottom: LAYOUT_GAP } },
1453
- footer: { filters: { marginBottom: LAYOUT_GAP }, pager: { ...PAGER_IN_FRAME, borderTopWidth: BORDER_WIDTH } },
1454
- panel: { filters: { borderBottomWidth: BORDER_WIDTH }, pager: { ...PAGER_IN_FRAME, borderBottomWidth: BORDER_WIDTH } }
1478
+ ["toolbar" /* Toolbar */]: { filters: { marginBottom: LAYOUT_GAP }, pager: { ...PAGER_IN_FRAME, borderBottomWidth: BORDER_WIDTH } },
1479
+ ["spaced" /* Spaced */]: { filters: {}, pager: { marginTop: LAYOUT_GAP, marginBottom: LAYOUT_GAP } },
1480
+ ["footer" /* Footer */]: { filters: { marginBottom: LAYOUT_GAP }, pager: { ...PAGER_IN_FRAME, borderTopWidth: BORDER_WIDTH } },
1481
+ ["panel" /* Panel */]: { filters: { borderBottomWidth: BORDER_WIDTH }, pager: { ...PAGER_IN_FRAME, borderBottomWidth: BORDER_WIDTH } }
1455
1482
  };
1456
1483
  function PagedTableLayout({
1457
1484
  filters,
1458
1485
  pager,
1459
1486
  table,
1460
- layout = "toolbar",
1487
+ layout = "toolbar" /* Toolbar */,
1461
1488
  testID = TABLE_TEST_IDS.pagedLayout
1462
1489
  }) {
1463
1490
  const { colors } = useUi().theme;
1464
1491
  const slots = SLOT_STYLES[layout];
1465
1492
  const line = { borderColor: colors.border };
1466
1493
  const hasFilters = filters !== void 0 && filters !== null && filters !== false;
1467
- const filtersInFrame = layout === "panel";
1468
- const isJoined = layout !== "spaced";
1494
+ const filtersInFrame = layout === "panel" /* Panel */;
1495
+ const isJoined = layout !== "spaced" /* Spaced */;
1469
1496
  const filtersSlot = hasFilters ? /* @__PURE__ */ jsx(View, { style: [slots.filters, line], testID: `${testID}-filters`, children: filters }) : null;
1470
1497
  const pagerSlot = /* @__PURE__ */ jsx(View, { style: [slots.pager, line], testID: `${testID}-pager`, children: pager });
1471
1498
  const tableSlot = /* @__PURE__ */ jsx(View, { testID: `${testID}-table`, children: table });
1472
- const pagerAndTable = layout === "footer" ? /* @__PURE__ */ jsxs(Fragment, { children: [
1499
+ const pagerAndTable = layout === "footer" /* Footer */ ? /* @__PURE__ */ jsxs(Fragment, { children: [
1473
1500
  tableSlot,
1474
1501
  pagerSlot
1475
1502
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -1543,6 +1570,7 @@ var FIELD_MIN_WIDTH = {
1543
1570
  select: 150,
1544
1571
  text: 200,
1545
1572
  number: 130,
1573
+ date: 160,
1546
1574
  dateRange: 260,
1547
1575
  typeahead: 200,
1548
1576
  boolean: 150
@@ -1601,22 +1629,6 @@ function BooleanField({ field, barTestID, value, onChange }) {
1601
1629
  )
1602
1630
  ] });
1603
1631
  }
1604
- function DateRangeField({ field, barTestID, value, onChange, onSubmit, fromLabel, toLabel }) {
1605
- return /* @__PURE__ */ jsx(
1606
- DateRangeControl,
1607
- {
1608
- accessibilityHint: field.accessibilityHint,
1609
- fromLabel: field.fromLabel ?? fromLabel,
1610
- fromPlaceholder: field.fromPlaceholder,
1611
- testID: field.testID ?? fieldTestID(barTestID, field.key),
1612
- toLabel: field.toLabel ?? toLabel,
1613
- toPlaceholder: field.toPlaceholder,
1614
- value,
1615
- onChange,
1616
- onSubmit
1617
- }
1618
- );
1619
- }
1620
1632
  function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
1621
1633
  const { t } = useUi();
1622
1634
  const testID = field.testID ?? fieldTestID(barTestID, field.key);
@@ -1641,6 +1653,21 @@ function SelectField({ field, barTestID, value, onChange, placeholder, dropdownH
1641
1653
  }
1642
1654
  );
1643
1655
  }
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
+ }
1644
1671
  function TextField({ field, barTestID, value, onChange, onSubmit }) {
1645
1672
  const { theme } = useUi();
1646
1673
  const { colors } = theme;
@@ -1702,11 +1729,30 @@ function asRange(value) {
1702
1729
  if (typeof value === "object" && value !== null && "from" in value && "to" in value) return value;
1703
1730
  return EMPTY_RANGE;
1704
1731
  }
1732
+ function fieldContainerStyle(field) {
1733
+ const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
1734
+ const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
1735
+ return [filterStyles.fieldInBar, { minWidth: clampedMinWidth(minWidth), maxWidth: "100%" }, grow, field.style];
1736
+ }
1705
1737
  function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings, renderSelect }) {
1706
1738
  const raw = values[field.key];
1707
1739
  if (field.kind === "boolean") {
1708
1740
  return /* @__PURE__ */ jsx(BooleanField, { field, barTestID, value: asBool(raw), onChange: (v) => setField(field.key, v) });
1709
1741
  }
1742
+ 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
+ }
1710
1756
  const body = (() => {
1711
1757
  switch (field.kind) {
1712
1758
  case "select":
@@ -1744,15 +1790,15 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
1744
1790
  );
1745
1791
  case "dateRange":
1746
1792
  return /* @__PURE__ */ jsx(
1747
- DateRangeField,
1793
+ DateRangeControl,
1748
1794
  {
1749
- field,
1750
- barTestID,
1795
+ accessibilityHint: field.accessibilityHint,
1796
+ fromLabel: field.fromLabel ?? strings.fromLabel,
1797
+ testID: field.testID ?? fieldTestID(barTestID, field.key),
1798
+ toLabel: field.toLabel ?? strings.toLabel,
1751
1799
  value: asRange(raw),
1752
1800
  onChange: (v) => setField(field.key, v),
1753
- onSubmit,
1754
- fromLabel: strings.fromLabel,
1755
- toLabel: strings.toLabel
1801
+ onSubmit
1756
1802
  }
1757
1803
  );
1758
1804
  default:
@@ -1768,12 +1814,10 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
1768
1814
  );
1769
1815
  }
1770
1816
  })();
1771
- const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
1772
- const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
1773
1817
  return /* @__PURE__ */ jsx(
1774
1818
  Field,
1775
1819
  {
1776
- containerStyle: [filterStyles.fieldInBar, { minWidth: clampedMinWidth(minWidth), maxWidth: "100%" }, grow, field.style],
1820
+ containerStyle,
1777
1821
  label: field.label,
1778
1822
  labelVariant: "control",
1779
1823
  testID: field.testID ?? fieldTestID(barTestID, field.key),
@@ -2102,6 +2146,7 @@ var LedgerLayout = /* @__PURE__ */ ((LedgerLayout2) => {
2102
2146
  LedgerLayout2["Feed"] = "feed";
2103
2147
  return LedgerLayout2;
2104
2148
  })(LedgerLayout || {});
2149
+ var LEDGER_ROW_ACTION_FALLBACK = { none: "status ledger caller passed no onRowPress" };
2105
2150
  var GAP = 12;
2106
2151
  var HEADING_FONT = 15;
2107
2152
  var HEADING_WEIGHT = "700";
@@ -2124,6 +2169,7 @@ function LedgerSection({ title, rows, columns, emptyLabel, testID, ledger }) {
2124
2169
  getRowDetailAccessibilityLabel: ledger.getRowAccessibilityLabel,
2125
2170
  keyExtractor: ledger.keyExtractor,
2126
2171
  onRowPress: ledger.onRowPress,
2172
+ rowAction: LEDGER_ROW_ACTION_FALLBACK,
2127
2173
  renderRowDetail: ledger.renderRowDetail,
2128
2174
  rows,
2129
2175
  stackBreakpoint: ledger.breakpoint ?? CARD_STACK_BREAKPOINT,
@@ -2178,6 +2224,7 @@ function StatusLedger(props) {
2178
2224
  keyExtractor: props.keyExtractor,
2179
2225
  loading,
2180
2226
  onRowPress: props.onRowPress,
2227
+ rowAction: LEDGER_ROW_ACTION_FALLBACK,
2181
2228
  renderRowDetail: props.renderRowDetail,
2182
2229
  rows: view.visible,
2183
2230
  stackBreakpoint: feed ? breakpoint : 0,
@@ -2350,6 +2397,6 @@ var MonthStatusGrid = ({
2350
2397
  ] }, row[0]?.id)) });
2351
2398
  };
2352
2399
 
2353
- export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, LedgerLayout, MONTH_STATUS_GRID_TEST_ID, MonthGridColumns, MonthStatusGrid, PagedTableLayout, Pager, RelativeTime, STATUS_LEDGER_TEST_ID, SortDirection, StatCard, StatTone, StatusLedger, StatusPill, StatusTone, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, distinctValues, fieldTestID, filterLedgerRows, fitMonthGridColumns, formatRelativeTime, isAttentionTone, ledgerSectionTestID, ledgerSortDirectionTestID, monthCellTestID, resolveStatToneColor, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, sortLedgerRows, splitNeedsLook, toEpochMs, useFilterDraft, usePagedRows };
2400
+ export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, LedgerLayout, MONTH_STATUS_GRID_TEST_ID, MonthGridColumns, MonthStatusGrid, PagedTableLayout, PagedTableLayoutKind, Pager, RelativeTime, STATUS_LEDGER_TEST_ID, SortDirection, StatCard, StatTone, StatusLedger, StatusPill, StatusTone, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, distinctValues, fieldTestID, filterLedgerRows, fitMonthGridColumns, formatRelativeTime, isAttentionTone, ledgerSectionTestID, ledgerSortDirectionTestID, monthCellTestID, resolveStatToneColor, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, sortLedgerRows, splitNeedsLook, toEpochMs, useFilterDraft, usePagedRows };
2354
2401
  //# sourceMappingURL=index.mjs.map
2355
2402
  //# sourceMappingURL=index.mjs.map