@homebound/beam 2.147.1 → 2.149.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.
@@ -222,6 +222,7 @@ export declare type DiscriminateUnion<T, K extends keyof T, V extends T[K]> = T
222
222
  declare type GridRowKind<R extends Kinded, P extends R["kind"]> = DiscriminateUnion<R, "kind", P> & {
223
223
  id: string;
224
224
  children: GridDataRow<R>[];
225
+ selectable?: false;
225
226
  };
226
227
  /**
227
228
  * Defines how a single column will render each given row `kind` in `R`.
@@ -333,6 +334,8 @@ export declare type GridDataRow<R extends Kinded> = {
333
334
  data: unknown;
334
335
  /** Whether to have the row collapsed (children not visible) on initial load. This will be ignore in subsequent re-renders of the table */
335
336
  initCollapsed?: boolean;
337
+ /** Whether row can be selected */
338
+ selectable?: false;
336
339
  } & IfAny<R, {}, DiscriminateUnion<R, "kind", R["kind"]>>;
337
340
  declare type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
338
341
  /** Return the content for a given column def applied to a given row. */
@@ -814,14 +814,13 @@ function filterRows(api, columns, rows, filter) {
814
814
  const matches = row.kind === "header" ||
815
815
  row.kind === "totals" ||
816
816
  filters.length === 0 ||
817
- !!row.pin ||
818
817
  filters.every((f) => columns.map((c) => applyRowFn(c, row, api, 0)).some((maybeContent) => matchesFilter(maybeContent, f)));
819
818
  if (matches) {
820
819
  return acc.concat([[row, (_b = (_a = row.children) === null || _a === void 0 ? void 0 : _a.reduce(acceptAll, [])) !== null && _b !== void 0 ? _b : []]]);
821
820
  }
822
821
  else {
823
822
  const matchedChildren = (_d = (_c = row.children) === null || _c === void 0 ? void 0 : _c.reduce(filterFn, [])) !== null && _d !== void 0 ? _d : [];
824
- if (matchedChildren.length > 0) {
823
+ if (matchedChildren.length > 0 || row.pin) {
825
824
  return acc.concat([[row, matchedChildren]]);
826
825
  }
827
826
  else {
@@ -39,19 +39,14 @@ class GridTableApiImpl {
39
39
  this.virtuosoRef.current && this.virtuosoRef.current.scrollToIndex(index);
40
40
  }
41
41
  getSelectedRowIds(kind) {
42
- if (kind === undefined) {
43
- return this.rowState.selectedIds;
44
- }
45
- else {
46
- return this.getSelectedRows(kind).map((row) => row.id);
47
- }
42
+ return this.getSelectedRows(kind).map((row) => row.id);
48
43
  }
49
44
  // The any is not great, but getting the overload to handle the optional kind is annoying
50
45
  getSelectedRows(kind) {
51
46
  const ids = this.rowState.selectedIds;
52
47
  const selected = [];
53
48
  (0, visitor_1.visit)(this.rowState.rows, (row) => {
54
- if (ids.includes(row.id) && (!kind || row.kind === kind)) {
49
+ if (row.selectable !== false && ids.includes(row.id) && (!kind || row.kind === kind)) {
55
50
  selected.push(row);
56
51
  }
57
52
  });
@@ -1,4 +1,7 @@
1
- /** Provides a checkbox to show/drive this row's selected state. */
2
- export declare function SelectToggle({ id }: {
1
+ interface SelectToggleProps {
3
2
  id: string;
4
- }): import("@emotion/react/jsx-runtime").JSX.Element;
3
+ disabled?: boolean;
4
+ }
5
+ /** Provides a checkbox to show/drive this row's selected state. */
6
+ export declare function SelectToggle({ id, disabled }: SelectToggleProps): import("@emotion/react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -7,12 +7,12 @@ const RowState_1 = require("./RowState");
7
7
  const index_1 = require("../../hooks/index");
8
8
  const index_2 = require("../../inputs/index");
9
9
  /** Provides a checkbox to show/drive this row's selected state. */
10
- function SelectToggle({ id }) {
10
+ function SelectToggle({ id, disabled }) {
11
11
  const { rowState } = (0, react_1.useContext)(RowState_1.RowStateContext);
12
12
  const state = (0, index_1.useComputed)(() => rowState.getSelected(id), [rowState]);
13
13
  const selected = state === "checked" ? true : state === "unchecked" ? false : "indeterminate";
14
- return ((0, jsx_runtime_1.jsx)(index_2.Checkbox, { label: "Select", checkboxOnly: true, selected: selected, onChange: (selected) => {
14
+ return ((0, jsx_runtime_1.jsx)(index_2.Checkbox, { checkboxOnly: true, disabled: disabled, label: "Select", onChange: (selected) => {
15
15
  rowState.selectRow(id, selected);
16
- } }, void 0));
16
+ }, selected: selected }, void 0));
17
17
  }
18
18
  exports.SelectToggle = SelectToggle;
@@ -47,7 +47,9 @@ function selectColumn(columnDef) {
47
47
  ...columnDef,
48
48
  };
49
49
  return (0, index_1.newMethodMissingProxy)(base, (key) => {
50
- return (data, { row }) => ({ content: (0, jsx_runtime_1.jsx)(SelectToggle_1.SelectToggle, { id: row.id }, void 0) });
50
+ return (data, { row }) => ({
51
+ content: (0, jsx_runtime_1.jsx)(SelectToggle_1.SelectToggle, { id: row.id, disabled: row.selectable === false }, void 0),
52
+ });
51
53
  });
52
54
  }
53
55
  exports.selectColumn = selectColumn;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./Css";
2
- export type { HasIdAndName, CheckFn } from "./types";
2
+ export type { HasIdAndName, CheckFn, DateRange } from "./types";
3
3
  export * from "./components";
4
4
  export * from "./forms";
5
5
  export * from "./hooks";
@@ -25,9 +25,10 @@ function CheckboxBase(props) {
25
25
  .maxw((0, Css_1.px)(344))
26
26
  .if(isDisabled).cursorNotAllowed.$, "aria-label": label }, { children: [(0, jsx_runtime_1.jsx)(react_aria_1.VisuallyHidden, { children: (0, jsx_runtime_1.jsx)("input", Object.assign({ ref: ref }, (0, react_aria_1.mergeProps)(inputProps, focusProps), tid), void 0) }, void 0), (0, jsx_runtime_1.jsx)("span", Object.assign({}, hoverProps, { css: {
27
27
  ...baseStyles,
28
- ...((isSelected || isIndeterminate) && filledBoxStyles),
29
- ...((isSelected || isIndeterminate) && isHovered && filledBoxHoverStyles),
28
+ ...(((isSelected && !isDisabled) || isIndeterminate) && filledBoxStyles),
29
+ ...(((isSelected && !isDisabled) || isIndeterminate) && isHovered && filledBoxHoverStyles),
30
30
  ...(isDisabled && disabledBoxStyles),
31
+ ...(isDisabled && isSelected && disabledSelectedBoxStyles),
31
32
  ...(isFocusVisible && focusRingStyles),
32
33
  ...(isHovered && hoverBorderStyles),
33
34
  ...markStyles,
@@ -40,7 +41,8 @@ exports.CheckboxBase = CheckboxBase;
40
41
  const baseStyles = Css_1.Css.hPx(16).mw((0, Css_1.px)(16)).relative.ba.bGray300.br4.bgWhite.transition.$;
41
42
  const filledBoxStyles = Css_1.Css.bLightBlue700.bgLightBlue700.$;
42
43
  const filledBoxHoverStyles = Css_1.Css.bgLightBlue900.$;
43
- const disabledBoxStyles = Css_1.Css.bGray400.bGray100.$;
44
+ const disabledBoxStyles = Css_1.Css.bgGray50.bGray100.$;
45
+ const disabledSelectedBoxStyles = Css_1.Css.bgGray400.bGray400.$;
44
46
  const disabledColor = Css_1.Css.gray300.$;
45
47
  const focusRingStyles = Css_1.Css.bshFocus.$;
46
48
  const hoverBorderStyles = Css_1.Css.bLightBlue900.$;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.147.1",
3
+ "version": "2.149.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",