@homebound/beam 2.153.0 → 2.154.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.
|
@@ -20,4 +20,4 @@ export interface ButtonProps extends BeamButtonProps, BeamFocusableProps {
|
|
|
20
20
|
}
|
|
21
21
|
export declare function Button(props: ButtonProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
22
22
|
export declare type ButtonSize = "sm" | "md" | "lg";
|
|
23
|
-
export declare type ButtonVariant = "primary" | "secondary" | "tertiary" | "danger" | "text";
|
|
23
|
+
export declare type ButtonVariant = "primary" | "secondary" | "tertiary" | "tertiaryDanger" | "danger" | "text";
|
|
@@ -11,12 +11,8 @@ 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
|
|
15
|
-
const
|
|
16
|
-
const [isDisabled, setIsDisabled] = (0, react_1.useState)(!!disabled);
|
|
17
|
-
(0, react_1.useEffect)(() => {
|
|
18
|
-
setIsDisabled(!!disabled);
|
|
19
|
-
}, [disabled]);
|
|
14
|
+
const showExternalLinkIcon = (typeof onPress === "string" && (0, utils_1.isAbsoluteUrl)(onPress)) || openInNew;
|
|
15
|
+
const isDisabled = !!disabled;
|
|
20
16
|
const ariaProps = { onPress, isDisabled, ...otherProps, ...menuTriggerProps };
|
|
21
17
|
const { label,
|
|
22
18
|
// Default the icon based on other properties.
|
|
@@ -25,33 +21,19 @@ function Button(props) {
|
|
|
25
21
|
const tid = (0, useTestIds_1.useTestIds)(props, label);
|
|
26
22
|
const { buttonProps, isPressed } = (0, react_aria_1.useButton)({
|
|
27
23
|
...ariaProps,
|
|
28
|
-
onPress:
|
|
29
|
-
|
|
30
|
-
: (e) => {
|
|
31
|
-
const result = onPress(e);
|
|
32
|
-
if (isPromise(result)) {
|
|
33
|
-
setIsDisabled(true);
|
|
34
|
-
result.finally(() => setIsDisabled(false));
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
},
|
|
38
|
-
elementType: asLink ? "a" : "button",
|
|
24
|
+
onPress: typeof onPress === "string" ? utils_1.noop : onPress,
|
|
25
|
+
elementType: typeof onPress === "string" ? "a" : "button",
|
|
39
26
|
}, ref);
|
|
40
27
|
const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)(ariaProps);
|
|
41
28
|
const { hoverProps, isHovered } = (0, react_aria_1.useHover)(ariaProps);
|
|
42
|
-
const { baseStyles, hoverStyles, disabledStyles, pressedStyles } = (0, react_1.useMemo)(() => getButtonStyles(variant, size, contrast), [variant, size, contrast]);
|
|
43
|
-
const focusStyles = (0, react_1.useMemo)(() => !contrast
|
|
44
|
-
? variant === "danger"
|
|
45
|
-
? Css_1.Css.bshDanger.$
|
|
46
|
-
: Css_1.Css.bshFocus.$
|
|
47
|
-
: Css_1.Css.boxShadow(`0 0 0 2px ${variant === "tertiary" ? Css_1.Palette.LightBlue700 : Css_1.Palette.White}`).if(variant === "tertiary").bgGray700.white.$, [variant, contrast]);
|
|
29
|
+
const { baseStyles, hoverStyles, disabledStyles, pressedStyles, focusStyles } = (0, react_1.useMemo)(() => getButtonStyles(variant, size, contrast), [variant, size, contrast]);
|
|
48
30
|
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));
|
|
49
31
|
const buttonAttrs = {
|
|
50
32
|
ref: ref,
|
|
51
33
|
...buttonProps,
|
|
52
34
|
...focusProps,
|
|
53
35
|
...hoverProps,
|
|
54
|
-
className:
|
|
36
|
+
className: typeof onPress === "string" ? components_1.navLink : undefined,
|
|
55
37
|
css: {
|
|
56
38
|
...Css_1.Css.buttonBase.tt("inherit").$,
|
|
57
39
|
...baseStyles,
|
|
@@ -87,30 +69,44 @@ const variantStyles = (contrast) => ({
|
|
|
87
69
|
hoverStyles: Css_1.Css.bgLightBlue900.if(contrast).bgLightBlue500.$,
|
|
88
70
|
pressedStyles: Css_1.Css.bgLightBlue500.if(contrast).bgLightBlue900.$,
|
|
89
71
|
disabledStyles: Css_1.Css.bgLightBlue200.if(contrast).gray600.bgLightBlue900.$,
|
|
72
|
+
focusStyles: Css_1.Css.bshFocus.if(contrast).boxShadow(`0 0 0 2px ${Css_1.Palette.White}`).$,
|
|
90
73
|
},
|
|
91
74
|
secondary: {
|
|
92
75
|
baseStyles: Css_1.Css.bgWhite.bGray300.bw1.ba.gray800.$,
|
|
93
76
|
hoverStyles: Css_1.Css.bgGray100.if(contrast).bgGray300.$,
|
|
94
77
|
pressedStyles: Css_1.Css.bgGray200.if(contrast).bgGray100.$,
|
|
95
78
|
disabledStyles: Css_1.Css.bgWhite.gray400.$,
|
|
79
|
+
focusStyles: Css_1.Css.bshFocus.if(contrast).boxShadow(`0 0 0 2px ${Css_1.Palette.White}`).$,
|
|
96
80
|
},
|
|
97
81
|
tertiary: {
|
|
98
82
|
baseStyles: Css_1.Css.bgTransparent.lightBlue700.if(contrast).lightBlue400.$,
|
|
99
83
|
hoverStyles: Css_1.Css.bgGray100.if(contrast).bgGray700.white.$,
|
|
100
84
|
pressedStyles: Css_1.Css.lightBlue900.if(contrast).bgWhite.gray900.$,
|
|
101
85
|
disabledStyles: Css_1.Css.gray400.if(contrast).gray700.$,
|
|
86
|
+
focusStyles: Css_1.Css.bshFocus.if(contrast).boxShadow(`0 0 0 2px ${Css_1.Palette.LightBlue700}`).bgGray700.white.$,
|
|
87
|
+
},
|
|
88
|
+
tertiaryDanger: {
|
|
89
|
+
baseStyles: Css_1.Css.bgTransparent.red500.if(contrast).red500.$,
|
|
90
|
+
hoverStyles: Css_1.Css.bgGray100.if(contrast).bgGray700.white.$,
|
|
91
|
+
pressedStyles: Css_1.Css.red900.if(contrast).bgWhite.gray900.$,
|
|
92
|
+
disabledStyles: Css_1.Css.gray400.if(contrast).gray700.$,
|
|
93
|
+
focusStyles: Css_1.Css.boxShadow(`0px 0px 0px 2px ${Css_1.Palette.White}, 0px 0px 0px 4px ${Css_1.Palette.Red500}`)
|
|
94
|
+
.if(contrast)
|
|
95
|
+
.boxShadow(`0px 0px 0px 2px ${Css_1.Palette.Red500}`).$,
|
|
102
96
|
},
|
|
103
97
|
danger: {
|
|
104
98
|
baseStyles: Css_1.Css.bgRed900.white.if(contrast).bgRed800.$,
|
|
105
99
|
hoverStyles: Css_1.Css.bgRed500.if(contrast).bgRed600.$,
|
|
106
100
|
pressedStyles: Css_1.Css.bgRed900.if(contrast).bgRed800.$,
|
|
107
101
|
disabledStyles: Css_1.Css.bgRed200.if(contrast).bgRed900.gray600.$,
|
|
102
|
+
focusStyles: Css_1.Css.bshDanger.if(contrast).boxShadow(`0 0 0 2px ${Css_1.Palette.White}`).$,
|
|
108
103
|
},
|
|
109
104
|
text: {
|
|
110
105
|
baseStyles: Css_1.Css.lightBlue700.add("fontSize", "inherit").if(contrast).lightBlue400.$,
|
|
111
106
|
hoverStyles: Css_1.Css.lightBlue600.if(contrast).lightBlue300.$,
|
|
112
107
|
pressedStyles: Css_1.Css.lightBlue700.if(contrast).lightBlue200.$,
|
|
113
108
|
disabledStyles: Css_1.Css.lightBlue300.if(contrast).lightBlue700.$,
|
|
109
|
+
focusStyles: Css_1.Css.bshFocus.if(contrast).boxShadow(`0 0 0 2px ${Css_1.Palette.White}`).$,
|
|
114
110
|
},
|
|
115
111
|
});
|
|
116
112
|
const sizeStyles = {
|
|
@@ -123,6 +119,3 @@ const iconStyles = {
|
|
|
123
119
|
md: Css_1.Css.mr1.$,
|
|
124
120
|
lg: Css_1.Css.mrPx(10).$,
|
|
125
121
|
};
|
|
126
|
-
function isPromise(obj) {
|
|
127
|
-
return typeof obj === "object" && "then" in obj && typeof obj.then === "function";
|
|
128
|
-
}
|
|
@@ -21,6 +21,7 @@ export interface DateFieldBaseProps extends Pick<TextFieldBaseProps<{}>, "border
|
|
|
21
21
|
placeholder?: string;
|
|
22
22
|
format?: keyof typeof dateFormats;
|
|
23
23
|
iconLeft?: boolean;
|
|
24
|
+
hideCalendarIcon?: boolean;
|
|
24
25
|
/**
|
|
25
26
|
* Set custom logic for individual dates or date ranges to be disabled in the picker
|
|
26
27
|
* exposed from `react-day-picker`: https://react-day-picker.js.org/api/DayPicker#modifiers
|
|
@@ -18,7 +18,7 @@ function DateFieldBase(props) {
|
|
|
18
18
|
var _a;
|
|
19
19
|
const { label, disabled, required, value, onFocus, onBlur,
|
|
20
20
|
// Pull `onChange` out of the props, but we're not directly using it. Do not want to keep it in `...others`
|
|
21
|
-
onChange: _onChange, errorMsg, helperText, inlineLabel = false, readOnly, format = "short", iconLeft = false, disabledDays, onEnter, defaultOpen, mode, ...others } = props;
|
|
21
|
+
onChange: _onChange, errorMsg, helperText, inlineLabel = false, readOnly, format = "short", iconLeft = false, hideCalendarIcon = false, disabledDays, onEnter, defaultOpen, mode, ...others } = props;
|
|
22
22
|
const inputRef = (0, react_1.useRef)(null);
|
|
23
23
|
const inputWrapRef = (0, react_1.useRef)(null);
|
|
24
24
|
const buttonRef = (0, react_1.useRef)(null);
|
|
@@ -156,7 +156,7 @@ function DateFieldBase(props) {
|
|
|
156
156
|
const parsed = mode === "range" ? (0, utils_1.parseDateRange)(v, utils_1.dateFormats.short) : (0, utils_1.parseDate)(v, utils_1.dateFormats.short);
|
|
157
157
|
onChange(parsed);
|
|
158
158
|
}
|
|
159
|
-
}, endAdornment: !iconLeft && calendarButton, startAdornment: iconLeft && calendarButton, tooltip: (0, components_1.resolveTooltip)(disabled, undefined, readOnly) }, others), void 0), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, Object.assign({ triggerRef: inputWrapRef, popoverRef: overlayRef, positionProps: positionProps, onClose: state.close, isOpen: state.isOpen }, { children: (0, jsx_runtime_1.jsx)(DatePickerOverlay_1.DatePickerOverlay, Object.assign({ overlayProps: overlayProps }, { children: props.mode === "range" ? ((0, jsx_runtime_1.jsx)(internal_1.DateRangePicker, Object.assign({ range: wipValue, disabledDays: disabledDays, onSelect: (dr) => {
|
|
159
|
+
}, endAdornment: (!hideCalendarIcon && !iconLeft) && calendarButton, startAdornment: (!hideCalendarIcon && iconLeft) && calendarButton, tooltip: (0, components_1.resolveTooltip)(disabled, undefined, readOnly) }, others), void 0), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, Object.assign({ triggerRef: inputWrapRef, popoverRef: overlayRef, positionProps: positionProps, onClose: state.close, isOpen: state.isOpen }, { children: (0, jsx_runtime_1.jsx)(DatePickerOverlay_1.DatePickerOverlay, Object.assign({ overlayProps: overlayProps }, { children: props.mode === "range" ? ((0, jsx_runtime_1.jsx)(internal_1.DateRangePicker, Object.assign({ range: wipValue, disabledDays: disabledDays, onSelect: (dr) => {
|
|
160
160
|
var _a;
|
|
161
161
|
// Note: Do not close date range picker on select to allow the user to select multiple dates at a time
|
|
162
162
|
setInputValue((_a = (0, utils_1.formatDateRange)(dr, utils_1.dateFormats.short)) !== null && _a !== void 0 ? _a : "");
|
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) |
|
|
18
|
+
onClick: ((e: PressEvent) => 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. */
|