@homebound/beam 2.213.0 → 2.215.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.
@@ -19,6 +19,8 @@ export interface BeamContextState {
19
19
  drawerCanCloseChecks: MutableRefObject<CanCloseCheck[]>;
20
20
  /** Checks when closing SuperDrawer Details, a double array to keep per-detail lists. */
21
21
  drawerCanCloseDetailsChecks: MutableRefObject<CanCloseCheck[][]>;
22
+ /** The div for SuperDrawerHeader to portal into. */
23
+ sdHeaderDiv: HTMLDivElement;
22
24
  }
23
25
  /** This is only exported internally, for useModal and useSuperDrawer, it's not a public API. */
24
26
  export declare const BeamContext: import("react").Context<BeamContextState>;
@@ -20,6 +20,7 @@ exports.BeamContext = (0, react_1.createContext)({
20
20
  drawerContentStack: new index_1.EmptyRef(),
21
21
  drawerCanCloseChecks: new index_1.EmptyRef(),
22
22
  drawerCanCloseDetailsChecks: new index_1.EmptyRef(),
23
+ sdHeaderDiv: undefined,
23
24
  });
24
25
  function BeamProvider({ children, ...presentationProps }) {
25
26
  // We want the identity of these to be stable, b/c they end up being used as dependencies
@@ -40,6 +41,7 @@ function BeamProvider({ children, ...presentationProps }) {
40
41
  const drawerContentStackRef = (0, react_1.useRef)([]);
41
42
  const drawerCanCloseChecks = (0, react_1.useRef)([]);
42
43
  const drawerCanCloseDetailsChecks = (0, react_1.useRef)([]);
44
+ const sdHeaderDiv = (0, react_1.useMemo)(() => document.createElement("div"), []);
43
45
  // We essentially expose the refs, but with our own getters/setters so that we can
44
46
  // have the setters call `tick` to re-render this Provider
45
47
  const context = (0, react_1.useMemo)(() => {
@@ -54,6 +56,7 @@ function BeamProvider({ children, ...presentationProps }) {
54
56
  modalFooterDiv,
55
57
  drawerCanCloseChecks,
56
58
  drawerCanCloseDetailsChecks,
59
+ sdHeaderDiv,
57
60
  };
58
61
  }, [modalBodyDiv, modalFooterDiv]);
59
62
  return ((0, jsx_runtime_1.jsx)(exports.BeamContext.Provider, Object.assign({ value: { ...context } }, { children: (0, jsx_runtime_1.jsx)(PresentationContext_1.PresentationProvider, Object.assign({}, presentationProps, { children: (0, jsx_runtime_1.jsx)(form_state_1.AutoSaveStatusProvider, { children: (0, jsx_runtime_1.jsxs)(SnackbarContext_1.SnackbarProvider, { children: [(0, jsx_runtime_1.jsxs)(react_aria_1.OverlayProvider, { children: [children, modalRef.current && (0, jsx_runtime_1.jsx)(Modal_1.Modal, Object.assign({}, modalRef.current), void 0)] }, void 0), (0, jsx_runtime_1.jsx)(SuperDrawer_1.SuperDrawer, {}, void 0)] }, void 0) }, void 0) }), void 0) }), void 0));
@@ -17,6 +17,8 @@ export interface ButtonProps extends BeamButtonProps, BeamFocusableProps {
17
17
  /** Denotes if this button is used to download a resource. Uses the anchor tag with the `download` attribute */
18
18
  download?: boolean;
19
19
  contrast?: boolean;
20
+ /** Additional text to further customize button during an async request is in progress. */
21
+ labelInFlight?: string;
20
22
  }
21
23
  export declare function Button(props: ButtonProps): import("@emotion/react/jsx-runtime").JSX.Element;
22
24
  export declare type ButtonSize = "sm" | "md" | "lg";
@@ -10,7 +10,7 @@ const utils_1 = require("../utils");
10
10
  const getInteractiveElement_1 = require("../utils/getInteractiveElement");
11
11
  const useTestIds_1 = require("../utils/useTestIds");
12
12
  function Button(props) {
13
- const { onClick: onPress, disabled, endAdornment, menuTriggerProps, tooltip, openInNew, download, contrast = false, forceFocusStyles = false, ...otherProps } = props;
13
+ const { onClick: onPress, disabled, endAdornment, menuTriggerProps, tooltip, openInNew, download, contrast = false, forceFocusStyles = false, labelInFlight, ...otherProps } = props;
14
14
  const asLink = typeof onPress === "string";
15
15
  const showExternalLinkIcon = (asLink && (0, utils_1.isAbsoluteUrl)(onPress)) || openInNew;
16
16
  const [asyncInProgress, setAsyncInProgress] = (0, react_1.useState)(false);
@@ -38,7 +38,7 @@ function Button(props) {
38
38
  const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)(ariaProps);
39
39
  const { hoverProps, isHovered } = (0, react_aria_1.useHover)(ariaProps);
40
40
  const { baseStyles, hoverStyles, disabledStyles, pressedStyles, focusStyles } = (0, react_1.useMemo)(() => getButtonStyles(variant, size, contrast), [variant, size, contrast]);
41
- const buttonContent = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [icon && (0, jsx_runtime_1.jsx)(components_1.Icon, { xss: iconStyles[size], icon: icon }, void 0), label, endAdornment && (0, jsx_runtime_1.jsx)("span", Object.assign({ css: Css_1.Css.ml1.$ }, { children: endAdornment }), void 0)] }, void 0));
41
+ const buttonContent = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [icon && (0, jsx_runtime_1.jsx)(components_1.Icon, { xss: iconStyles[size], icon: icon }, void 0), labelInFlight && asyncInProgress ? labelInFlight : label, (endAdornment || asyncInProgress) && ((0, jsx_runtime_1.jsx)("span", Object.assign({ css: Css_1.Css.ml1.$ }, { children: asyncInProgress ? (0, jsx_runtime_1.jsx)(components_1.Loader, { size: "xs", contrast: contrast }, void 0) : endAdornment }), void 0))] }, void 0));
42
42
  const buttonAttrs = {
43
43
  ref: ref,
44
44
  ...buttonProps,
@@ -11,7 +11,7 @@ const defaultTestId_1 = require("../utils/defaultTestId");
11
11
  function ButtonGroup(props) {
12
12
  const { buttons, disabled = false, size = "sm" } = props;
13
13
  const tid = (0, utils_1.useTestIds)(props, "buttonGroup");
14
- return ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.mPx(4).$ }, tid, { children: buttons.map(({ disabled: buttonDisabled, ...buttonProps }, i) => (
14
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, tid, { css: sizeStyles[size] }, { children: buttons.map(({ disabled: buttonDisabled, ...buttonProps }, i) => (
15
15
  // Disable the button if the ButtonGroup is disabled or if the current button is disabled.
16
16
  (0, jsx_runtime_1.jsx)(GroupButton, Object.assign({}, buttonProps, { disabled: disabled || buttonDisabled, size: size }, tid), i))) }), void 0));
17
17
  }
@@ -1,5 +1,5 @@
1
1
  interface LoaderProps {
2
- size?: "sm" | "md" | "lg";
2
+ size?: "xs" | "sm" | "md" | "lg";
3
3
  contrast?: boolean;
4
4
  }
5
5
  export declare function Loader({ size, contrast }: LoaderProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -21,6 +21,7 @@ function Loader({ size = "lg", contrast = false }) {
21
21
  }
22
22
  exports.Loader = Loader;
23
23
  const sizeToPixels = {
24
+ xs: [16, 2],
24
25
  sm: [32, 4],
25
26
  md: [64, 8],
26
27
  lg: [96, 12],
@@ -35,10 +35,9 @@ const utils_2 = require("./utils");
35
35
  */
36
36
  function SuperDrawer() {
37
37
  var _a, _b;
38
- const { drawerContentStack: contentStack } = (0, BeamContext_1.useBeamContext)();
38
+ const { drawerContentStack: contentStack, sdHeaderDiv } = (0, BeamContext_1.useBeamContext)();
39
39
  const { closeDrawer } = (0, components_1.useSuperDrawer)();
40
- const modalBodyRef = (0, react_3.useRef)(null);
41
- const modalFooterRef = (0, react_3.useRef)(null);
40
+ const headerRef = (0, react_3.useRef)(null);
42
41
  const testId = (0, utils_1.useTestIds)({}, "superDrawer");
43
42
  // Get the latest element on the stack
44
43
  // We use undefined, nullish operators and empty object here to allow AnimatePresence
@@ -47,10 +46,13 @@ function SuperDrawer() {
47
46
  const { content } = currentContent !== null && currentContent !== void 0 ? currentContent : {};
48
47
  // Also get the first / non-detail element on the stack
49
48
  const firstContent = (_b = contentStack.current[0]) === null || _b === void 0 ? void 0 : _b.opts;
50
- const { onPrevClick, onNextClick, titleRightContent, titleLeftContent, hideControls } = firstContent !== null && firstContent !== void 0 ? firstContent : {};
51
- const isDetail = currentContent !== firstContent;
52
- const title = content === undefined ? "" : currentContent.title || firstContent.title;
53
49
  const { width = utils_2.SuperDrawerWidth.Normal } = firstContent !== null && firstContent !== void 0 ? firstContent : {};
50
+ (0, react_3.useEffect)(() => {
51
+ var _a;
52
+ if (((_a = headerRef.current) === null || _a === void 0 ? void 0 : _a.childNodes.length) === 0 && content) {
53
+ headerRef.current.appendChild(sdHeaderDiv);
54
+ }
55
+ }, [headerRef, content]);
54
56
  return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: content && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_2.Global, { styles: { body: Css_1.Css.overflowHidden.$ } }, void 0), (0, react_1.createElement)(framer_motion_1.motion.div, { ...testId,
55
57
  // Key is required for framer-motion animations
56
58
  key: "superDrawer",
@@ -70,17 +72,6 @@ function SuperDrawer() {
70
72
  // Custom transitions settings for the translateX animation
71
73
  transition: { ease: "linear", duration: 0.2, delay: 0.2 }, exit: { transition: { ease: "linear", duration: 0.2 }, x: width },
72
74
  // Preventing clicks from triggering parent onClick
73
- onClick: (e) => e.stopPropagation() }, { children: (0, jsx_runtime_1.jsxs)(form_state_1.AutoSaveStatusProvider, { children: [(0, jsx_runtime_1.jsxs)("header", Object.assign({ css: Css_1.Css.df.p3.bb.bGray200.df.aic.jcsb.gap2.$ }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.df.aic.$ }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.xl2Sb.gray900.mr2.$ }, testId.title, { children: title !== null && title !== void 0 ? title : null }), void 0), titleLeftContent !== null && titleLeftContent !== void 0 ? titleLeftContent : null] }), void 0), (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.df.gap3.aic.hPx(32).fs0.$ }, { children: [titleRightContent || null, !hideControls && ((0, jsx_runtime_1.jsx)(components_1.ButtonGroup, Object.assign({ buttons: [
74
- {
75
- icon: "chevronLeft",
76
- onClick: () => onPrevClick && onPrevClick(),
77
- disabled: !onPrevClick || isDetail,
78
- },
79
- {
80
- icon: "chevronRight",
81
- onClick: () => onNextClick && onNextClick(),
82
- disabled: !onNextClick || isDetail,
83
- },
84
- ] }, testId.headerActions), void 0)), (0, jsx_runtime_1.jsx)(components_1.IconButton, Object.assign({ icon: "x", onClick: closeDrawer }, testId.close), void 0)] }), void 0)] }), void 0), content] }, void 0) }), "superDrawerContainer"))] }, void 0)) }, void 0), document.body);
75
+ onClick: (e) => e.stopPropagation() }, { children: (0, jsx_runtime_1.jsxs)(form_state_1.AutoSaveStatusProvider, { children: [(0, jsx_runtime_1.jsxs)("header", Object.assign({ css: Css_1.Css.p3.bb.bGray200.df.aic.jcsb.gap3.$ }, { children: [(0, jsx_runtime_1.jsx)("div", { ref: headerRef, css: Css_1.Css.gray900.fg1.addIn("h1", Css_1.Css.xl2Sb.$).$ }, void 0), (0, jsx_runtime_1.jsx)(components_1.IconButton, Object.assign({ icon: "x", onClick: closeDrawer }, testId.close), void 0)] }), void 0), content] }, void 0) }), "superDrawerContainer"))] }, void 0)) }, void 0), document.body);
85
76
  }
86
77
  exports.SuperDrawer = SuperDrawer;
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from "react";
2
+ interface SuperDrawerHeaderProps {
3
+ children: ReactNode;
4
+ hideControls?: boolean;
5
+ }
6
+ interface SuperDrawerHeaderStructuredProps {
7
+ title: string;
8
+ left?: ReactNode;
9
+ right?: ReactNode;
10
+ hideControls?: boolean;
11
+ }
12
+ export declare function SuperDrawerHeader(props: SuperDrawerHeaderProps | SuperDrawerHeaderStructuredProps): JSX.Element;
13
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SuperDrawerHeader = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const react_dom_1 = require("react-dom");
6
+ const BeamContext_1 = require("../../BeamContext");
7
+ const ButtonGroup_1 = require("../../ButtonGroup");
8
+ const Css_1 = require("../../../Css");
9
+ const utils_1 = require("../../../utils");
10
+ function SuperDrawerHeader(props) {
11
+ var _a, _b;
12
+ const { hideControls } = props;
13
+ const { sdHeaderDiv, drawerContentStack: contentStack } = (0, BeamContext_1.useBeamContext)();
14
+ const firstContent = (_a = contentStack.current[0]) === null || _a === void 0 ? void 0 : _a.opts;
15
+ const { onPrevClick, onNextClick } = firstContent !== null && firstContent !== void 0 ? firstContent : {};
16
+ const currentContent = (_b = contentStack.current[contentStack.current.length - 1]) === null || _b === void 0 ? void 0 : _b.opts;
17
+ const isDetail = currentContent !== firstContent;
18
+ const tid = (0, utils_1.useTestIds)({}, "superDrawerHeader");
19
+ return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.df.aic.jcsb.gap3.$ }, tid, { children: [isStructuredProps(props) ? ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.df.jcsb.aic.gap2.fg1.$ }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.fg1.df.aic.gap2.$ }, { children: [(0, jsx_runtime_1.jsx)("h1", { children: props.title }, void 0), props.left] }), void 0), props.right && (0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.fs0.$ }, { children: props.right }), void 0)] }), void 0)) : ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.fg1.$ }, { children: props.children }), void 0)), !hideControls && ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.fs0.if(isDetail).invisible.$ }, { children: (0, jsx_runtime_1.jsx)(ButtonGroup_1.ButtonGroup, Object.assign({ buttons: [
20
+ { icon: "chevronLeft", onClick: () => onPrevClick && onPrevClick(), disabled: !onPrevClick },
21
+ { icon: "chevronRight", onClick: () => onNextClick && onNextClick(), disabled: !onNextClick },
22
+ ] }, tid.actions), void 0) }), void 0))] }), void 0), sdHeaderDiv);
23
+ }
24
+ exports.SuperDrawerHeader = SuperDrawerHeader;
25
+ function isStructuredProps(props) {
26
+ return typeof props === "object" && "title" in props;
27
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./components/SuperDrawerHeader";
1
2
  export * from "./ConfirmCloseModal";
2
3
  export * from "./SuperDrawerContent";
3
4
  export * from "./useSuperDrawer";
@@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  // These are our public APIs
14
+ __exportStar(require("./components/SuperDrawerHeader"), exports);
14
15
  __exportStar(require("./ConfirmCloseModal"), exports);
15
16
  __exportStar(require("./SuperDrawerContent"), exports);
16
17
  __exportStar(require("./useSuperDrawer"), exports);
@@ -2,18 +2,10 @@ import { ReactNode } from "react";
2
2
  import { CanCloseCheck } from "../../types";
3
3
  import { SuperDrawerWidth } from "./utils";
4
4
  export interface OpenInDrawerOpts {
5
- /** Title of the SuperDrawer */
6
- title: string;
7
- /** Optional content to place left of the prev/next buttons, i.e. a "Manage" link. */
8
- titleRightContent?: ReactNode;
9
- /** Optional content to place right of the title, i.e. a status badge. */
10
- titleLeftContent?: ReactNode;
11
5
  /** Invokes left, disabled if undefined. */
12
6
  onPrevClick?: () => void;
13
7
  /** Invokes right, disabled if undefined. */
14
8
  onNextClick?: () => void;
15
- /** Hides the pagination controls for `onNextClick` and `onPrevClick` */
16
- hideControls?: true;
17
9
  /** Adds a callback that is called _after_ close has definitely happened. */
18
10
  onClose?: () => void;
19
11
  content: ReactNode;
@@ -21,8 +13,6 @@ export interface OpenInDrawerOpts {
21
13
  width?: SuperDrawerWidth;
22
14
  }
23
15
  export interface OpenDetailOpts {
24
- /** Title of the SuperDrawer for this detail page (replaces the original title). */
25
- title?: string;
26
16
  content: ReactNode;
27
17
  }
28
18
  export declare type ContentStack = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.213.0",
3
+ "version": "2.215.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",