@homebound/beam 4.40.1 → 4.42.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.cjs CHANGED
@@ -6937,7 +6937,8 @@ function memoizedTableStyles() {
6937
6937
  vAlign = rowHeight === "fixed" ? "center" : "top",
6938
6938
  cellTypography = "xs",
6939
6939
  highlightOnHover = true,
6940
- roundedHeader = true
6940
+ roundedHeader = true,
6941
+ columnStriping
6941
6942
  } = props;
6942
6943
  const key = safeKeys(props).sort().map((k) => `${k}_${props[k]}`).join("|");
6943
6944
  if (!cache[key]) {
@@ -7246,6 +7247,9 @@ function memoizedTableStyles() {
7246
7247
  paddingTop: "pt_4px",
7247
7248
  paddingBottom: "pb_4px"
7248
7249
  }
7250
+ } : {},
7251
+ ...columnStriping ? {
7252
+ columnStripeColor: columnStriping
7249
7253
  } : {}
7250
7254
  };
7251
7255
  }
@@ -7354,7 +7358,8 @@ var gridStyleDefKeysRecord = {
7354
7358
  vAlign: true,
7355
7359
  cellTypography: true,
7356
7360
  highlightOnHover: true,
7357
- roundedHeader: true
7361
+ roundedHeader: true,
7362
+ columnStriping: true
7358
7363
  };
7359
7364
  function isGridStyleDef(style) {
7360
7365
  const keys = safeKeys(style);
@@ -9599,7 +9604,6 @@ function groupColumns(opts) {
9599
9604
  const {
9600
9605
  id,
9601
9606
  header,
9602
- bgColor,
9603
9607
  columns
9604
9608
  } = opts;
9605
9609
  return columns.map((column2) => ({
@@ -9609,7 +9613,6 @@ function groupColumns(opts) {
9609
9613
  groupId: id,
9610
9614
  groupLabel: header,
9611
9615
  groupHeader: header,
9612
- bgColor: column2.bgColor ?? bgColor,
9613
9616
  name: prefixGroupColumnName(header, column2.name)
9614
9617
  }));
9615
9618
  }
@@ -10960,6 +10963,7 @@ function RowImpl(props) {
10960
10963
  setResizedWidth,
10961
10964
  disableColumnResizing = true,
10962
10965
  calculatePreviewWidth,
10966
+ stripedColumnIds,
10963
10967
  onDragStart,
10964
10968
  onDragEnd,
10965
10969
  onDrop,
@@ -10974,6 +10978,7 @@ function RowImpl(props) {
10974
10978
  api,
10975
10979
  visibleColumns: columns
10976
10980
  } = tableState;
10981
+ const columnStripeColor = style.columnStripeColor;
10977
10982
  const {
10978
10983
  row,
10979
10984
  api: rowApi,
@@ -11171,6 +11176,12 @@ function RowImpl(props) {
11171
11176
  // Add right border on expandable header cells except the last column
11172
11177
  ...isExpandableHeader && columnIndex + currentColspan < columns.length && style.expandableHeaderNonLastColumnCss,
11173
11178
  ...isGroupHeader && style.groupHeaderCss,
11179
+ ...columnStripeColor && stripedColumnIds?.has(column2.id) && {
11180
+ backgroundColor: ["bgColor_var", {
11181
+ "--backgroundColor": (0, import_runtime24.maybeCssVar)(maybeCssVar(columnStripeColor))
11182
+ }]
11183
+ },
11184
+ // A leaf background is explicit and wins over the stripe.
11174
11185
  ...column2.bgColor && {
11175
11186
  backgroundColor: ["bgColor_var", {
11176
11187
  "--backgroundColor": (0, import_runtime24.maybeCssVar)(column2.bgColor)
@@ -14624,6 +14635,7 @@ function GridTable(props) {
14624
14635
  const columns = useComputed(() => {
14625
14636
  return tableState.visibleColumns;
14626
14637
  }, [tableState]);
14638
+ const stripedColumnIds = (0, import_react51.useMemo)(() => style.columnStripeColor ? getStripedColumnIds(columns) : void 0, [columns, style.columnStripeColor]);
14627
14639
  tableState.initSortState(props.sorting, columns);
14628
14640
  const {
14629
14641
  getCount
@@ -14753,7 +14765,8 @@ function GridTable(props) {
14753
14765
  resizedWidths,
14754
14766
  setResizedWidth: handleColumnResize,
14755
14767
  disableColumnResizing,
14756
- calculatePreviewWidth
14768
+ calculatePreviewWidth,
14769
+ stripedColumnIds
14757
14770
  } }, rs.key);
14758
14771
  const makeCompanionRow = (rs, resolved, isFirstBodyRow, isLastBodyRow) => {
14759
14772
  const levelStyle = style.levels && (typeof style.levels === "function" ? style.levels(rs.level) : style.levels[rs.level]);
@@ -14804,7 +14817,7 @@ function GridTable(props) {
14804
14817
  visibleDataRows2 = visibleDataRows2.slice(0, filterMaxRows);
14805
14818
  }
14806
14819
  return [tableHeadRows2, visibleDataRows2, keptSelectedRows2, pinnedRows2, tooManyClientSideRows2];
14807
- }, [as, api, style, rowStyles, maybeStyle, columnSizes, columns.length, getCount, filterMaxRows, cardHeight, cardImageFit]);
14820
+ }, [as, api, style, rowStyles, maybeStyle, columnSizes, columns.length, stripedColumnIds, getCount, filterMaxRows, cardHeight, cardImageFit]);
14808
14821
  if (props.rowLookup) props.rowLookup.current = api.lookup;
14809
14822
  const noData = visibleDataRows.length === 0 && pinnedRows.length === 0;
14810
14823
  const firstRowMessage = noData && !emptyState && fallbackMessage || tooManyClientSideRows && "Hiding some rows, use filter..." || infoMessage;
@@ -15213,6 +15226,32 @@ function useColumnMeasureWidth() {
15213
15226
  return void 0;
15214
15227
  }
15215
15228
  var CARD_MIN_WIDTH_PX = 330;
15229
+ function getStripedColumnIds(columns) {
15230
+ const ids = /* @__PURE__ */ new Set();
15231
+ const contentColumns = columns.filter(isContentColumn);
15232
+ if (contentColumns.some((column2) => column2.groupId)) {
15233
+ const firstGroupStripes = contentColumns.findIndex((column2) => column2.groupId) > 0;
15234
+ const ordinals = /* @__PURE__ */ new Map();
15235
+ for (const column2 of contentColumns) {
15236
+ const {
15237
+ groupId
15238
+ } = column2;
15239
+ if (!groupId) continue;
15240
+ let ordinal = ordinals.get(groupId);
15241
+ if (ordinal === void 0) {
15242
+ ordinal = ordinals.size;
15243
+ ordinals.set(groupId, ordinal);
15244
+ }
15245
+ const stripes = firstGroupStripes ? ordinal % 2 === 0 : ordinal % 2 === 1;
15246
+ if (stripes) ids.add(column2.id);
15247
+ }
15248
+ return ids;
15249
+ }
15250
+ contentColumns.forEach((column2, ordinal) => {
15251
+ if (ordinal % 2 === 1) ids.add(column2.id);
15252
+ });
15253
+ return ids;
15254
+ }
15216
15255
 
15217
15256
  // src/components/ToggleChip.tsx
15218
15257
  var import_runtime44 = require("@homebound/truss/runtime");
@@ -25630,7 +25669,8 @@ function EditColumnsButton(props) {
25630
25669
  defaultOpen,
25631
25670
  disabled,
25632
25671
  columns,
25633
- api
25672
+ api,
25673
+ shareColumnVisibility = false
25634
25674
  } = props;
25635
25675
  const state = (0, import_react_stately17.useMenuTriggerState)({
25636
25676
  defaultOpen
@@ -25645,26 +25685,13 @@ function EditColumnsButton(props) {
25645
25685
  const {
25646
25686
  sm
25647
25687
  } = useBreakpoint();
25648
- const options = (0, import_react117.useMemo)(() => columns.filter((column2) => column2.canHide).filter((column2) => {
25649
- if (!column2.name || column2.name.length === 0 || !column2.id || column2.id.length === 0) {
25650
- console.warn("Column is missing 'name' and/or 'id' property required by the Edit Columns button", column2);
25651
- return false;
25652
- }
25653
- return true;
25654
- }).map((column2) => ({
25655
- label: column2.name,
25656
- value: column2.id,
25657
- tooltip: column2.tooltip
25658
- })), [columns]);
25688
+ const options = (0, import_react117.useMemo)(() => buildColumnOptions(columns, shareColumnVisibility), [columns, shareColumnVisibility]);
25659
25689
  const selectedValues = useComputed(() => api.getVisibleColumnIds(), [api]);
25660
25690
  const setSelectedValues = (0, import_react117.useCallback)((ids) => {
25661
25691
  api.resetColumnWidths();
25662
25692
  api.setVisibleColumns(columns.filter((column2) => column2.canHide ? ids.includes(column2.id) : true).map((c) => c.id));
25663
25693
  }, [columns, api]);
25664
- const hasHiddenColumn = (0, import_react117.useMemo)(() => {
25665
- const selectableOptionValues = options.map((option) => option.value);
25666
- return selectableOptionValues.some((option) => !selectedValues.includes(option));
25667
- }, [options, selectedValues]);
25694
+ const hasHiddenColumn = (0, import_react117.useMemo)(() => options.some((option) => option.ids.some((id) => !selectedValues.includes(id))), [options, selectedValues]);
25668
25695
  return /* @__PURE__ */ (0, import_jsx_runtime179.jsx)(OverlayTrigger, { ...props, trigger: sm ? {
25669
25696
  icon: hasHiddenColumn ? "columnsBadged" : "columns",
25670
25697
  variant: "outline"
@@ -25692,7 +25719,7 @@ function EditColumnsButton(props) {
25692
25719
  /* @__PURE__ */ (0, import_jsx_runtime179.jsx)("span", { className: "fw4 fz_14px lh_20px mw0", children: option.label }),
25693
25720
  option.tooltip ? /* @__PURE__ */ (0, import_jsx_runtime179.jsx)(ColumnTooltipIcon, { ...tid[`tooltip_${option.value}`], tooltip: closeMenuOnClickTooltip(option.tooltip, state.close), color: "--b-text-link-default" /* TextLinkDefault */, label: option.label }) : null
25694
25721
  ] }),
25695
- /* @__PURE__ */ (0, import_jsx_runtime179.jsx)(Switch, { compact: true, selected: selectedValues.includes(option.value), onChange: (value) => setSelectedValues(value ? [...selectedValues, option.value] : selectedValues.filter((v) => v !== option.value)), labelStyle: "hidden", label: option.label, ...tid[`option${option.value}`] })
25722
+ /* @__PURE__ */ (0, import_jsx_runtime179.jsx)(Switch, { compact: true, selected: option.ids.every((id) => selectedValues.includes(id)), onChange: (value) => setSelectedValues(value ? [...selectedValues, ...option.ids] : selectedValues.filter((id) => !option.ids.includes(id))), labelStyle: "hidden", label: option.label, ...tid[`option${option.value}`] })
25696
25723
  ] }, option.value)) }),
25697
25724
  /* @__PURE__ */ (0, import_jsx_runtime179.jsx)("div", { ...(0, import_runtime119.trussProps)({
25698
25725
  display: "df",
@@ -25709,6 +25736,54 @@ function EditColumnsButton(props) {
25709
25736
  }), children: /* @__PURE__ */ (0, import_jsx_runtime179.jsx)(Button, { variant: "tertiary", label: "Reset Column Widths", onClick: () => api.resetColumnWidths() }) })
25710
25737
  ] }) });
25711
25738
  }
25739
+ function buildColumnOptions(columns, shareColumnVisibility) {
25740
+ const hideable = columns.filter((column2) => {
25741
+ if (!column2.canHide) return false;
25742
+ if (!column2.name || column2.name.length === 0 || !column2.id || column2.id.length === 0) {
25743
+ console.warn("Column is missing 'name' and/or 'id' property required by the Edit Columns button", column2);
25744
+ return false;
25745
+ }
25746
+ return true;
25747
+ });
25748
+ if (!shareColumnVisibility) {
25749
+ return hideable.map((column2) => ({
25750
+ label: column2.name,
25751
+ value: column2.id,
25752
+ ids: [column2.id],
25753
+ tooltip: column2.tooltip
25754
+ }));
25755
+ }
25756
+ const byLabel = /* @__PURE__ */ new Map();
25757
+ const warnedLabels = /* @__PURE__ */ new Set();
25758
+ for (const column2 of hideable) {
25759
+ const label = leafColumnName(column2);
25760
+ const existing = byLabel.get(label);
25761
+ if (!existing) {
25762
+ byLabel.set(label, {
25763
+ label,
25764
+ value: column2.id,
25765
+ ids: [column2.id],
25766
+ tooltip: column2.tooltip
25767
+ });
25768
+ continue;
25769
+ }
25770
+ existing.ids.push(column2.id);
25771
+ if (existing.tooltip !== column2.tooltip && !warnedLabels.has(label)) {
25772
+ warnedLabels.add(label);
25773
+ console.warn(`Edit Columns columns labeled "${label}" have different tooltips. Using the first.`);
25774
+ }
25775
+ }
25776
+ return [...byLabel.values()];
25777
+ }
25778
+ function leafColumnName(column2) {
25779
+ const {
25780
+ name,
25781
+ groupLabel
25782
+ } = column2;
25783
+ const prefix = groupLabel ? `${groupLabel}: ` : void 0;
25784
+ if (name && prefix && name.startsWith(prefix)) return name.slice(prefix.length);
25785
+ return name;
25786
+ }
25712
25787
  function closeMenuOnClickTooltip(tooltip, closeMenu) {
25713
25788
  if (typeof tooltip !== "function") return tooltip;
25714
25789
  return () => {
@@ -25933,6 +26008,7 @@ function GridTableLayoutActionsComponent(props) {
25933
26008
  searchProps,
25934
26009
  hasHideableColumns,
25935
26010
  columns,
26011
+ shareColumnVisibility,
25936
26012
  api,
25937
26013
  withCardView,
25938
26014
  view,
@@ -26026,7 +26102,7 @@ function GridTableLayoutActionsComponent(props) {
26026
26102
  ] }),
26027
26103
  (hasHideableColumns || withCardView || !!actions?.length || selectionSummary) && /* @__PURE__ */ (0, import_jsx_runtime184.jsxs)("div", { className: "df aic g_12px", children: [
26028
26104
  selectionSummary && api && /* @__PURE__ */ (0, import_jsx_runtime184.jsx)(SelectionSummaryAction, { api, numberOnly: sm }),
26029
- hasHideableColumns && view === "list" && columns && api && /* @__PURE__ */ (0, import_jsx_runtime184.jsx)(EditColumnsButton, { columns, api, tooltip: "Display columns" }),
26105
+ hasHideableColumns && view === "list" && columns && api && /* @__PURE__ */ (0, import_jsx_runtime184.jsx)(EditColumnsButton, { columns, api, shareColumnVisibility, tooltip: "Display columns" }),
26030
26106
  withCardView && view !== void 0 && setView && /* @__PURE__ */ (0, import_jsx_runtime184.jsx)(ViewToggleButton, { view, onChange: setView }),
26031
26107
  !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime184.jsx)(HeaderActions, { actions, ...testId.actions })
26032
26108
  ] })
@@ -26905,6 +26981,7 @@ function GridTableLayoutComponent(props) {
26905
26981
  actions,
26906
26982
  selectionSummary = false,
26907
26983
  hideEditColumns = false,
26984
+ shareColumnVisibility = false,
26908
26985
  withCardView,
26909
26986
  defaultView = "list",
26910
26987
  emptyFallback: layoutEmptyFallback,
@@ -26959,6 +27036,7 @@ function GridTableLayoutComponent(props) {
26959
27036
  searchProps: filterSearchProps,
26960
27037
  hasHideableColumns,
26961
27038
  columns,
27039
+ shareColumnVisibility,
26962
27040
  api,
26963
27041
  withCardView,
26964
27042
  view,