@homebound/beam 2.273.0 → 2.275.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.
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from "react";
2
+ import { Palette, Properties } from "..";
3
+ interface ScrollShadowsProps {
4
+ children: ReactNode;
5
+ /** Allows for styling the container */
6
+ xss?: Properties;
7
+ /** Set to true if the container scrolls horizontally */
8
+ horizontal?: boolean;
9
+ /** Defines the background color for the shadows */
10
+ bgColor?: Palette;
11
+ }
12
+ export declare function ScrollShadows(props: ScrollShadowsProps): import("@emotion/react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScrollShadows = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const utils_1 = require("@react-aria/utils");
6
+ const react_1 = require("react");
7
+ const src_1 = require("..");
8
+ function ScrollShadows(props) {
9
+ const { children, xss, horizontal = false, bgColor = src_1.Palette.White } = props;
10
+ const { height = "auto", width = "auto" } = xss !== null && xss !== void 0 ? xss : {};
11
+ const tid = (0, src_1.useTestIds)(props);
12
+ // This is admittedly extremely hacky. It expects the background color to be in the format "rgba(255, 255, 255, 1)".
13
+ // If we ever change how we define our color palette in Beam, then this will break and will need to be fixed.
14
+ if (!bgColor.includes("rgba")) {
15
+ throw new Error("ScrollShadows: bgColor prop must be in the format 'rgba(255, 255, 255, 1)'");
16
+ }
17
+ const transparentBgColor = bgColor.replace(/,1\)$/, ",0)");
18
+ const startShadowStyles = !horizontal ? src_1.Css.top0.left0.right0.hPx(40).$ : src_1.Css.left0.top0.bottom0.wPx(25).$;
19
+ const endShadowStyles = !horizontal ? src_1.Css.bottom0.left0.right0.hPx(40).$ : src_1.Css.right0.top0.bottom0.wPx(25).$;
20
+ const startGradientDeg = !horizontal ? 180 : 90;
21
+ const endGradientDeg = !horizontal ? 0 : 270;
22
+ const [showStartShadow, setShowStartShadow] = (0, react_1.useState)(false);
23
+ const [showEndShadow, setShowEndShadow] = (0, react_1.useState)(false);
24
+ const scrollRef = (0, react_1.useRef)(null);
25
+ const updateScrollProps = (0, react_1.useCallback)((el) => {
26
+ const { scrollTop, scrollHeight, clientHeight, scrollWidth, scrollLeft, clientWidth } = el;
27
+ const start = horizontal ? scrollLeft : scrollTop;
28
+ const end = horizontal ? scrollWidth : scrollHeight;
29
+ const boxSize = horizontal ? clientWidth : clientHeight;
30
+ setShowStartShadow(start > 0);
31
+ setShowEndShadow(start + boxSize < end);
32
+ }, []);
33
+ // Initially set the state dimensions on render to put the shadows in the correct position
34
+ (0, utils_1.useLayoutEffect)(() => {
35
+ scrollRef.current && updateScrollProps(scrollRef.current);
36
+ }, []);
37
+ return ((0, jsx_runtime_1.jsxs)("div", { css: src_1.Css.relative.overflowHidden
38
+ .h(height)
39
+ .w(width)
40
+ .df.fd(!horizontal ? "column" : "row").$, ...tid, children: [showStartShadow && ((0, jsx_runtime_1.jsx)("div", { css: {
41
+ ...startShadowStyles,
42
+ ...src_1.Css.absolute.add("background", `linear-gradient(${startGradientDeg}deg, ${bgColor} 0%, ${transparentBgColor} 92%);`).$,
43
+ } })), showEndShadow && ((0, jsx_runtime_1.jsx)("div", { css: {
44
+ ...endShadowStyles,
45
+ ...src_1.Css.absolute.add("background", `linear-gradient(${endGradientDeg}deg, ${bgColor} 0%, ${transparentBgColor} 92%)`).$,
46
+ } })), (0, jsx_runtime_1.jsx)("div", { css: {
47
+ ...xss,
48
+ ...src_1.Css.overflowAuto.fg1.addIn("&::-webkit-scrollbar", { display: "none" }).add("scrollbarWidth", "none").$,
49
+ }, onScroll: (e) => updateScrollProps(e.currentTarget), ref: scrollRef, children: children })] }));
50
+ }
51
+ exports.ScrollShadows = ScrollShadows;
@@ -42,7 +42,6 @@ export type GridTableApi<R extends Kinded> = {
42
42
  isCollapsedRow: (id: string) => boolean;
43
43
  setVisibleColumns: (ids: string[]) => void;
44
44
  getVisibleColumnIds: () => string[];
45
- refetchExpandedColumns: () => void;
46
45
  };
47
46
  export declare class GridTableApiImpl<R extends Kinded> implements GridTableApi<R> {
48
47
  readonly tableState: TableState;
@@ -60,5 +59,4 @@ export declare class GridTableApiImpl<R extends Kinded> implements GridTableApi<
60
59
  isCollapsedRow(id: string): boolean;
61
60
  setVisibleColumns(ids: string[]): void;
62
61
  getVisibleColumnIds(): string[];
63
- refetchExpandedColumns(): void;
64
62
  }
@@ -77,8 +77,5 @@ class GridTableApiImpl {
77
77
  getVisibleColumnIds() {
78
78
  return this.tableState.visibleColumnIds;
79
79
  }
80
- refetchExpandedColumns() {
81
- this.tableState.refetchExpandedColumns();
82
- }
83
80
  }
84
81
  exports.GridTableApiImpl = GridTableApiImpl;
@@ -47,7 +47,6 @@ export declare class TableState {
47
47
  get sortState(): SortState | undefined;
48
48
  setRows(rows: GridDataRow<any>[]): void;
49
49
  setColumns(columns: GridColumnWithId<any>[], visibleColumnsStorageKey: string | undefined): void;
50
- refetchExpandedColumns(): void;
51
50
  /** Determines which columns to expand immediately vs async */
52
51
  parseAndUpdateExpandedColumns(columnsToExpand: GridColumnWithId<any>[]): Promise<void>;
53
52
  /** Updates the state of which columns are expanded */
@@ -188,22 +188,19 @@ class TableState {
188
188
  // Figure out which columns need to be expanded when rendering a new set of columns
189
189
  const localStorageColumns = this.persistCollapse ? readExpandedColumnsStorage(this.persistCollapse) : [];
190
190
  // On initial render the columns we start with is whatever is in local storage.
191
- // On any subsequent render, we start with an empty array.
192
- // (We'll add to this after figuring out which columns are new vs existing.)
193
- const columnIdsToExpand = isInitial ? localStorageColumns : [];
191
+ // On subsequent renders we want to keep the columns that were previously expanded.
192
+ const columnIdsToExpand = isInitial ? localStorageColumns : this.expandedColumnIds;
194
193
  // Create a list of all existing column ids. (We ignore the `initExpanded` property for existing columns)
195
194
  const existingColumnIds = this.columns.map((c) => c.id);
196
195
  // Add any columns to our array that are new columns that should be initially expanded.
197
196
  columnIdsToExpand.push(...columns.filter((c) => !existingColumnIds.includes(c.id) && c.initExpanded).map((c) => c.id));
197
+ // Clear the cache to force to re-fetch the expanded columns.
198
+ this.loadedColumns.clear();
198
199
  // Send the new array of columns along to be parsed and expanded.
199
200
  this.parseAndUpdateExpandedColumns(columns.filter((c) => columnIdsToExpand.includes(c.id)));
200
201
  this.columns = columns;
201
202
  }
202
203
  }
203
- refetchExpandedColumns() {
204
- this.loadedColumns.clear();
205
- this.parseAndUpdateExpandedColumns(this.columns.filter((c) => this.expandedColumnIds.includes(c.id)));
206
- }
207
204
  /** Determines which columns to expand immediately vs async */
208
205
  async parseAndUpdateExpandedColumns(columnsToExpand) {
209
206
  // Separate out which columns need to be loaded async vs which can be loaded immediately.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.273.0",
3
+ "version": "2.275.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",