@homebound/beam 2.124.0 → 2.124.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FieldState } from "@homebound/form-state";
|
|
2
2
|
import { SwitchProps } from "../inputs";
|
|
3
|
-
export declare type BoundSwitchFieldProps = Omit<SwitchProps, "selected" | "onChange" | "label"
|
|
3
|
+
export declare type BoundSwitchFieldProps = Omit<SwitchProps, "selected" | "onChange" | "label"> & {
|
|
4
4
|
field: FieldState<any, boolean | null | undefined>;
|
|
5
5
|
/** Make optional so that callers can override if they want to. */
|
|
6
6
|
onChange?: (value: boolean) => void;
|
|
@@ -8,11 +8,11 @@ const utils_1 = require("../utils");
|
|
|
8
8
|
const defaultLabel_1 = require("../utils/defaultLabel");
|
|
9
9
|
/** Wraps `Switch` and binds it to a form field. */
|
|
10
10
|
function BoundSwitchField(props) {
|
|
11
|
-
const { field, onChange = (value) => field.set(value), label = (0, defaultLabel_1.defaultLabel)(field.key), ...others } = props;
|
|
11
|
+
const { field, onChange = (value) => field.set(value), label = (0, defaultLabel_1.defaultLabel)(field.key), labelStyle = "form", ...others } = props;
|
|
12
12
|
const testId = (0, utils_1.useTestIds)(props, field.key);
|
|
13
13
|
return ((0, jsx_runtime_1.jsx)(mobx_react_1.Observer, { children: () => {
|
|
14
14
|
var _a;
|
|
15
|
-
return ((0, jsx_runtime_1.jsx)(inputs_1.Switch, Object.assign({ label: label, labelStyle:
|
|
15
|
+
return ((0, jsx_runtime_1.jsx)(inputs_1.Switch, Object.assign({ label: label, labelStyle: labelStyle, selected: (_a = field.value) !== null && _a !== void 0 ? _a : false, onChange: (selected) => {
|
|
16
16
|
onChange(selected);
|
|
17
17
|
field.maybeAutoSave();
|
|
18
18
|
} }, testId, others), void 0));
|
package/dist/inputs/Switch.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
1
2
|
export interface SwitchProps {
|
|
2
3
|
/** Whether the element should receive focus on render. */
|
|
3
4
|
autoFocus?: boolean;
|
|
4
5
|
/** Whether to render a compact version of Switch */
|
|
5
6
|
compact?: boolean;
|
|
6
|
-
/** Whether the
|
|
7
|
-
disabled?: boolean;
|
|
7
|
+
/** Whether the field is disabled. If a ReactNode, it's treated as a "disabled reason" that's shown in a tooltip. */
|
|
8
|
+
disabled?: boolean | ReactNode;
|
|
8
9
|
/** Input label */
|
|
9
10
|
label: string;
|
|
10
11
|
/** Where to put the label. */
|
|
11
12
|
labelStyle?: "form" | "inline" | "filter";
|
|
13
|
+
/** Whether or not to hide the label */
|
|
14
|
+
hideLabel?: boolean;
|
|
12
15
|
/** Handler when the interactive element state changes. */
|
|
13
16
|
onChange: (value: boolean) => void;
|
|
14
17
|
/** Whether the switch is selected */
|
package/dist/inputs/Switch.js
CHANGED
|
@@ -4,39 +4,46 @@ exports.switchSelectedHoverStyles = exports.switchFocusStyles = exports.switchHo
|
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_aria_1 = require("react-aria");
|
|
7
|
+
const components_1 = require("../components");
|
|
7
8
|
const Label_1 = require("../components/Label");
|
|
8
9
|
const Css_1 = require("../Css");
|
|
9
10
|
const Icon_1 = require("../components/Icon");
|
|
10
11
|
const utils_1 = require("../utils");
|
|
11
12
|
function Switch(props) {
|
|
12
|
-
const { selected: isSelected, disabled
|
|
13
|
+
const { selected: isSelected, disabled = false, onChange, withIcon, compact = false, label, labelStyle = "inline", hideLabel = false, ...otherProps } = props;
|
|
14
|
+
const isDisabled = !!disabled;
|
|
13
15
|
const ariaProps = { isSelected, isDisabled, ...otherProps };
|
|
14
16
|
const state = (0, utils_1.toToggleState)(isSelected, onChange);
|
|
15
17
|
const ref = (0, react_1.useRef)(null);
|
|
16
18
|
const { inputProps } = (0, react_aria_1.useSwitch)({ ...ariaProps, "aria-label": label }, state, ref);
|
|
17
19
|
const { isFocusVisible: isKeyboardFocus, focusProps } = (0, react_aria_1.useFocusRing)(otherProps);
|
|
18
20
|
const { hoverProps, isHovered } = (0, react_aria_1.useHover)(ariaProps);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...
|
|
34
|
-
...(
|
|
35
|
-
...(isSelected &&
|
|
36
|
-
} }, { children:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
const tooltip = (0, components_1.resolveTooltip)(disabled);
|
|
22
|
+
return (0, components_1.maybeTooltip)({
|
|
23
|
+
title: tooltip,
|
|
24
|
+
placement: "top",
|
|
25
|
+
children: ((0, jsx_runtime_1.jsxs)("label", Object.assign({}, hoverProps, { css: {
|
|
26
|
+
...Css_1.Css.relative.cursorPointer.df.w("max-content").smEm.selectNone.$,
|
|
27
|
+
...(labelStyle === "form" && Css_1.Css.fdc.$),
|
|
28
|
+
...(labelStyle === "inline" && Css_1.Css.childGap2.aic.$),
|
|
29
|
+
...(labelStyle === "filter" && Css_1.Css.jcsb.aic.w("auto").sm.$),
|
|
30
|
+
...(isDisabled && Css_1.Css.cursorNotAllowed.gray400.$),
|
|
31
|
+
}, "aria-label": label }, { children: [!hideLabel && labelStyle === "form" && (0, jsx_runtime_1.jsx)(Label_1.Label, { label: label }, void 0), !hideLabel && labelStyle === "filter" && (0, jsx_runtime_1.jsx)("span", { children: label }, void 0), (0, jsx_runtime_1.jsx)("div", Object.assign({ "aria-hidden": "true", css: {
|
|
32
|
+
...Css_1.Css.wPx(toggleWidth(compact)).hPx(toggleHeight(compact)).bgGray200.br12.relative.transition.$,
|
|
33
|
+
...(isHovered && exports.switchHoverStyles),
|
|
34
|
+
...(isKeyboardFocus && exports.switchFocusStyles),
|
|
35
|
+
...(isDisabled && Css_1.Css.bgGray300.$),
|
|
36
|
+
...(isSelected && Css_1.Css.bgLightBlue700.$),
|
|
37
|
+
...(isSelected && isHovered && exports.switchSelectedHoverStyles),
|
|
38
|
+
} }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ css: {
|
|
39
|
+
...switchCircleDefaultStyles(compact),
|
|
40
|
+
...(isDisabled && Css_1.Css.bgGray100.$),
|
|
41
|
+
...(isSelected && switchCircleSelectedStyles(compact)),
|
|
42
|
+
} }, { children: withIcon && ((0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: isSelected ? "check" : "x", color: isSelected ? Css_1.Palette.LightBlue700 : Css_1.Palette.Gray400 }, void 0)) }), void 0) }), void 0), !hideLabel && labelStyle === "inline" && ((0, jsx_runtime_1.jsx)("span", Object.assign({ css: {
|
|
43
|
+
// LineHeight is conditionally applied to handle compact version text alignment
|
|
44
|
+
...Css_1.Css.if(compact).add("lineHeight", "1").$,
|
|
45
|
+
} }, { children: label }), void 0)), (0, jsx_runtime_1.jsx)(react_aria_1.VisuallyHidden, { children: (0, jsx_runtime_1.jsx)("input", Object.assign({ ref: ref }, inputProps, focusProps), void 0) }, void 0)] }), void 0)),
|
|
46
|
+
});
|
|
40
47
|
}
|
|
41
48
|
exports.Switch = Switch;
|
|
42
49
|
/** Styles */
|