@homebound/beam 2.274.0 → 2.275.1

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;
@@ -27,6 +27,7 @@ export * from "./Modal/useModal";
27
27
  export { NavLink } from "./NavLink";
28
28
  export * from "./Pagination";
29
29
  export { PresentationProvider } from "./PresentationContext";
30
+ export * from "./ScrollShadows";
30
31
  export * from "./Snackbar";
31
32
  export * from "./Stepper";
32
33
  export type { Step, StepperProps } from "./Stepper";
@@ -51,6 +51,7 @@ Object.defineProperty(exports, "NavLink", { enumerable: true, get: function () {
51
51
  __exportStar(require("./Pagination"), exports);
52
52
  var PresentationContext_1 = require("./PresentationContext");
53
53
  Object.defineProperty(exports, "PresentationProvider", { enumerable: true, get: function () { return PresentationContext_1.PresentationProvider; } });
54
+ __exportStar(require("./ScrollShadows"), exports);
54
55
  __exportStar(require("./Snackbar"), exports);
55
56
  __exportStar(require("./Stepper"), exports);
56
57
  __exportStar(require("./SuperDrawer"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.274.0",
3
+ "version": "2.275.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",