@homebound/beam 2.154.0 → 2.156.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.
@@ -11,9 +11,11 @@ const getInteractiveElement_1 = require("../utils/getInteractiveElement");
11
11
  const useTestIds_1 = require("../utils/useTestIds");
12
12
  function Button(props) {
13
13
  const { onClick: onPress, disabled, endAdornment, menuTriggerProps, tooltip, openInNew, download, contrast = false, ...otherProps } = props;
14
- const showExternalLinkIcon = (typeof onPress === "string" && (0, utils_1.isAbsoluteUrl)(onPress)) || openInNew;
14
+ const asLink = typeof onPress === "string";
15
+ const showExternalLinkIcon = (asLink && (0, utils_1.isAbsoluteUrl)(onPress)) || openInNew;
16
+ const [asyncInProgress, setAsyncInProgress] = (0, react_1.useState)(false);
15
17
  const isDisabled = !!disabled;
16
- const ariaProps = { onPress, isDisabled, ...otherProps, ...menuTriggerProps };
18
+ const ariaProps = { onPress, isDisabled: isDisabled || asyncInProgress, ...otherProps, ...menuTriggerProps };
17
19
  const { label,
18
20
  // Default the icon based on other properties.
19
21
  icon = download ? "download" : showExternalLinkIcon ? "linkExternal" : undefined, variant = "primary", size = "sm", buttonRef, } = ariaProps;
@@ -21,8 +23,17 @@ function Button(props) {
21
23
  const tid = (0, useTestIds_1.useTestIds)(props, label);
22
24
  const { buttonProps, isPressed } = (0, react_aria_1.useButton)({
23
25
  ...ariaProps,
24
- onPress: typeof onPress === "string" ? utils_1.noop : onPress,
25
- elementType: typeof onPress === "string" ? "a" : "button",
26
+ onPress: asLink
27
+ ? utils_1.noop
28
+ : (e) => {
29
+ const result = onPress(e);
30
+ if (isPromise(result)) {
31
+ setAsyncInProgress(true);
32
+ result.finally(() => setAsyncInProgress(false));
33
+ }
34
+ return result;
35
+ },
36
+ elementType: asLink ? "a" : "button",
26
37
  }, ref);
27
38
  const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)(ariaProps);
28
39
  const { hoverProps, isHovered } = (0, react_aria_1.useHover)(ariaProps);
@@ -33,13 +44,13 @@ function Button(props) {
33
44
  ...buttonProps,
34
45
  ...focusProps,
35
46
  ...hoverProps,
36
- className: typeof onPress === "string" ? components_1.navLink : undefined,
47
+ className: asLink ? components_1.navLink : undefined,
37
48
  css: {
38
49
  ...Css_1.Css.buttonBase.tt("inherit").$,
39
50
  ...baseStyles,
40
51
  ...(isHovered && !isPressed ? hoverStyles : {}),
41
52
  ...(isPressed ? pressedStyles : {}),
42
- ...(isDisabled ? { ...disabledStyles, ...Css_1.Css.cursorNotAllowed.$ } : {}),
53
+ ...(isDisabled || asyncInProgress ? { ...disabledStyles, ...Css_1.Css.cursorNotAllowed.$ } : {}),
43
54
  ...(isFocusVisible ? focusStyles : {}),
44
55
  },
45
56
  ...tid,
@@ -119,3 +130,6 @@ const iconStyles = {
119
130
  md: Css_1.Css.mr1.$,
120
131
  lg: Css_1.Css.mrPx(10).$,
121
132
  };
133
+ function isPromise(obj) {
134
+ return typeof obj === "object" && "then" in obj && typeof obj.then === "function";
135
+ }
@@ -4,10 +4,9 @@ export interface Step {
4
4
  disabled?: boolean;
5
5
  value: string;
6
6
  }
7
- interface StepperBarProps {
7
+ export interface StepperProps {
8
8
  steps: Step[];
9
9
  currentStep: Step["value"];
10
10
  onChange: (stepValue: string) => void;
11
11
  }
12
- export declare function Stepper({ steps, currentStep, onChange }: StepperBarProps): import("@emotion/react/jsx-runtime").JSX.Element;
13
- export {};
12
+ export declare function Stepper({ steps, currentStep, onChange }: StepperProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -56,7 +56,7 @@ function SuperDrawer() {
56
56
  const { content } = currentContent;
57
57
  // Also get the first / non-detail element on the stack
58
58
  const firstContent = contentStack.current[0].opts;
59
- const { onPrevClick, onNextClick, titleRightContent, titleLeftContent } = firstContent;
59
+ const { onPrevClick, onNextClick, titleRightContent, titleLeftContent, hideControls } = firstContent;
60
60
  const isDetail = currentContent !== firstContent;
61
61
  const title = currentContent.title || firstContent.title;
62
62
  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,
@@ -80,7 +80,7 @@ function SuperDrawer() {
80
80
  // Preventing clicks from triggering parent onClick
81
81
  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.xl2Em.gray900.mr2.$ }, testId.title, { ref: drawerHeaderRef }, { children: !modalState.current && (title || null) }), void 0), !modalState.current && (titleLeftContent || null)] }), void 0), !modalState.current && (
82
82
  // Forcing height to 32px to match title height
83
- (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.df.childGap3.aic.hPx(32).fs0.$ }, { children: [titleRightContent || null, (0, jsx_runtime_1.jsx)(components_1.ButtonGroup, Object.assign({ buttons: [
83
+ (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.df.childGap3.aic.hPx(32).fs0.$ }, { children: [titleRightContent || null, !hideControls && ((0, jsx_runtime_1.jsx)(components_1.ButtonGroup, Object.assign({ buttons: [
84
84
  {
85
85
  icon: "chevronLeft",
86
86
  onClick: () => onPrevClick && onPrevClick(),
@@ -91,7 +91,7 @@ function SuperDrawer() {
91
91
  onClick: () => onNextClick && onNextClick(),
92
92
  disabled: !onNextClick || isDetail,
93
93
  },
94
- ] }, 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, modalState.current && (
94
+ ] }, 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, modalState.current && (
95
95
  // Forcing some design constraints on the modal component
96
96
  (0, jsx_runtime_1.jsxs)("div", Object.assign({ css:
97
97
  // topPX(81) is the offset from the header
@@ -11,6 +11,8 @@ export interface OpenInDrawerOpts {
11
11
  onPrevClick?: () => void;
12
12
  /** Invokes right, disabled if undefined. */
13
13
  onNextClick?: () => void;
14
+ /** Hides the pagination controls for `onNextClick` and `onPrevClick` */
15
+ hideControls?: true;
14
16
  /** Adds a callback that is called _after_ close has definitely happened. */
15
17
  onClose?: () => void;
16
18
  content: ReactNode;
@@ -23,6 +23,7 @@ export { NavLink } from "./NavLink";
23
23
  export { PresentationProvider } from "./PresentationContext";
24
24
  export * from "./Snackbar";
25
25
  export * from "./Stepper";
26
+ export type { Step, StepperProps } from "./Stepper";
26
27
  export * from "./SuperDrawer";
27
28
  export * from "./Table";
28
29
  export { TabContent, Tabs, TabsWithContent } from "./Tabs";
@@ -15,7 +15,7 @@ export interface BeamButtonProps {
15
15
  */
16
16
  disabled?: boolean | ReactNode;
17
17
  /** If function, then it is the handler that is called when the press is released over the target. Otherwise if string, it is the URL path for the link */
18
- onClick: ((e: PressEvent) => void) | string;
18
+ onClick: ((e: PressEvent) => void) | ((e: PressEvent) => Promise<void>) | string;
19
19
  /** Text to be shown via a tooltip when the user hovers over the button */
20
20
  tooltip?: ReactNode;
21
21
  /** Whether to open link in a new tab. This only effects the element if the `onClick` is a `string`/URL. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.154.0",
3
+ "version": "2.156.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",