@homebound/beam 2.154.0 → 2.155.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.
- package/dist/components/Button.js +20 -6
- package/dist/interfaces.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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:
|
|
25
|
-
|
|
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:
|
|
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
|
+
}
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -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. */
|