@homebound/beam 2.260.0 → 2.262.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/{Avatar.js → Avatar/Avatar.js} +9 -8
- package/dist/components/{AvatarButton.d.ts → Avatar/AvatarButton.d.ts} +1 -1
- package/dist/components/{AvatarButton.js → Avatar/AvatarButton.js} +9 -9
- package/dist/components/Avatar/AvatarGroup.d.ts +9 -0
- package/dist/components/Avatar/AvatarGroup.js +31 -0
- package/dist/components/Avatar/index.d.ts +3 -0
- package/dist/components/Avatar/index.js +19 -0
- package/dist/components/Filters/MultiFilter.js +2 -2
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -1
- package/dist/components/internal/OverlayTrigger.d.ts +1 -1
- package/dist/components/internal/OverlayTrigger.js +1 -1
- package/dist/inputs/MultiLineSelectField.d.ts +2 -2
- package/dist/inputs/MultiSelectField.d.ts +2 -2
- package/dist/inputs/MultiSelectField.js +2 -2
- package/dist/inputs/SelectField.d.ts +2 -2
- package/dist/inputs/SelectField.js +3 -3
- package/dist/inputs/TextFieldBase.d.ts +4 -0
- package/dist/inputs/TextFieldBase.js +5 -3
- package/dist/inputs/internal/{SelectFieldBase.d.ts → ComboBoxBase.d.ts} +4 -5
- package/dist/inputs/internal/{SelectFieldBase.js → ComboBoxBase.js} +8 -6
- package/dist/inputs/internal/{SelectFieldInput.d.ts → ComboBoxInput.d.ts} +2 -1
- package/dist/inputs/internal/{SelectFieldInput.js → ComboBoxInput.js} +3 -3
- package/package.json +1 -1
- /package/dist/components/{Avatar.d.ts → Avatar/Avatar.d.ts} +0 -0
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Avatar = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
const Icon_1 = require("
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const Icon_1 = require("../Icon");
|
|
7
|
+
const Tooltip_1 = require("../Tooltip");
|
|
8
|
+
const Css_1 = require("../../Css");
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
9
10
|
function Avatar({ src, name, size = "md", showName = false, ...others }) {
|
|
10
11
|
const tid = (0, utils_1.useTestIds)(others, "avatar");
|
|
11
12
|
const px = sizeToPixel[size];
|
|
@@ -13,7 +14,7 @@ function Avatar({ src, name, size = "md", showName = false, ...others }) {
|
|
|
13
14
|
// Define min-width as well as width to prevent the image from shrinking when displayed within a flex-child that allows shrinking.
|
|
14
15
|
const styles = Css_1.Css.br100.wPx(px).hPx(px).mwPx(px).overflowHidden.$;
|
|
15
16
|
const img = showFallback ? ((0, jsx_runtime_1.jsx)("div", { css: { ...styles, ...Css_1.Css[sizeToFallbackTypeScale[size]].bgGray400.gray100.df.aic.jcc.$ }, ...tid, children: name ? nameToInitials(name) : (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: "userCircle", inc: sizeToIconInc[size] }) })) : ((0, jsx_runtime_1.jsx)("img", { src: src, alt: name, css: { ...styles, ...Css_1.Css.objectCover.$ }, onError: () => setShowFallback(true), loading: "lazy", ...tid }));
|
|
16
|
-
return showName && name ? ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.dif.aic.gap1.if(size === "lg" || size === "xl").fdc.$, children: [img, (0, jsx_runtime_1.jsx)("span", { css: Css_1.Css[sizeToTypeScale[size]].$, children: name })] })) : (img);
|
|
17
|
+
return showName && name ? ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.dif.aic.gap1.if(size === "lg" || size === "xl").fdc.$, children: [img, (0, jsx_runtime_1.jsx)("span", { css: Css_1.Css[sizeToTypeScale[size]].$, children: name })] })) : ((0, Tooltip_1.maybeTooltip)({ title: name, children: img, placement: "top" }));
|
|
17
18
|
}
|
|
18
19
|
exports.Avatar = Avatar;
|
|
19
20
|
const sizeToPixel = {
|
|
@@ -35,10 +36,10 @@ const sizeToIconInc = {
|
|
|
35
36
|
xl: 8,
|
|
36
37
|
};
|
|
37
38
|
const sizeToTypeScale = {
|
|
38
|
-
sm: "
|
|
39
|
-
md: "
|
|
40
|
-
lg: "
|
|
41
|
-
xl: "
|
|
39
|
+
sm: "smMd",
|
|
40
|
+
md: "smMd",
|
|
41
|
+
lg: "base",
|
|
42
|
+
xl: "base",
|
|
42
43
|
};
|
|
43
44
|
function nameToInitials(name) {
|
|
44
45
|
return (name
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AriaButtonProps } from "@react-types/button";
|
|
2
2
|
import { RefObject } from "react";
|
|
3
3
|
import { AvatarProps } from "./Avatar";
|
|
4
|
-
import { BeamButtonProps, BeamFocusableProps } from "
|
|
4
|
+
import { BeamButtonProps, BeamFocusableProps } from "../../interfaces";
|
|
5
5
|
export interface AvatarButtonProps extends AvatarProps, BeamButtonProps, BeamFocusableProps {
|
|
6
6
|
menuTriggerProps?: AriaButtonProps;
|
|
7
7
|
buttonRef?: RefObject<HTMLButtonElement>;
|
|
@@ -4,13 +4,13 @@ exports.pressedStyles = exports.hoverStyles = exports.AvatarButton = void 0;
|
|
|
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("./");
|
|
8
7
|
const Avatar_1 = require("./Avatar");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
8
|
+
const index_1 = require("../index");
|
|
9
|
+
const Css_1 = require("../../Css");
|
|
10
|
+
const useGetRef_1 = require("../../hooks/useGetRef");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const getInteractiveElement_1 = require("../../utils/getInteractiveElement");
|
|
13
|
+
const useTestIds_1 = require("../../utils/useTestIds");
|
|
14
14
|
function AvatarButton(props) {
|
|
15
15
|
const { onClick: onPress, disabled, autoFocus, buttonRef, tooltip, menuTriggerProps, openInNew, forceFocusStyles = false, ...avatarProps } = props;
|
|
16
16
|
const isDisabled = !!disabled;
|
|
@@ -36,13 +36,13 @@ function AvatarButton(props) {
|
|
|
36
36
|
...buttonProps,
|
|
37
37
|
...focusProps,
|
|
38
38
|
...hoverProps,
|
|
39
|
-
className: typeof onPress === "string" ?
|
|
39
|
+
className: typeof onPress === "string" ? index_1.navLink : undefined,
|
|
40
40
|
ref: ref,
|
|
41
41
|
css: styles,
|
|
42
42
|
};
|
|
43
43
|
// If we're disabled b/c of a non-boolean ReactNode, or the caller specified tooltip text, then show it in a tooltip
|
|
44
|
-
return (0,
|
|
45
|
-
title: (0,
|
|
44
|
+
return (0, index_1.maybeTooltip)({
|
|
45
|
+
title: (0, index_1.resolveTooltip)(disabled, tooltip),
|
|
46
46
|
placement: "top",
|
|
47
47
|
children: (0, getInteractiveElement_1.getButtonOrLink)((0, jsx_runtime_1.jsx)(Avatar_1.Avatar, { ...avatarProps, ...tid }), onPress, buttonAttrs, openInNew),
|
|
48
48
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AvatarSize } from "./Avatar";
|
|
2
|
+
export interface AvatarGroupProps {
|
|
3
|
+
avatars: {
|
|
4
|
+
src: string | undefined;
|
|
5
|
+
name?: string;
|
|
6
|
+
}[];
|
|
7
|
+
size?: AvatarSize;
|
|
8
|
+
}
|
|
9
|
+
export declare function AvatarGroup(props: AvatarGroupProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvatarGroup = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
+
const Avatar_1 = require("./Avatar");
|
|
6
|
+
const ButtonModal_1 = require("../ButtonModal");
|
|
7
|
+
const Css_1 = require("../../Css");
|
|
8
|
+
function AvatarGroup(props) {
|
|
9
|
+
const { avatars, size = "md" } = props;
|
|
10
|
+
// If there are 8 or fewer avatars, show them all. Otherwise, show the first 7 and a menu with the rest.
|
|
11
|
+
const maxVisibleAvatars = avatars.length <= 8 ? 8 : 7;
|
|
12
|
+
const visibleAvatars = avatars.slice(0, maxVisibleAvatars);
|
|
13
|
+
const menuAvatars = avatars.slice(maxVisibleAvatars);
|
|
14
|
+
return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.df.aic.gap1.xsSb.$, children: [(0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.df.aic.$, children: visibleAvatars.map((avatar, idx) => {
|
|
15
|
+
var _a;
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.br100.ba.bWhite
|
|
17
|
+
.add("borderWidth", "3px")
|
|
18
|
+
.if(idx > 0)
|
|
19
|
+
.mlPx(-1 * sizeToOverlap[size]).$, children: (0, jsx_runtime_1.jsx)(Avatar_1.Avatar, { src: avatar.src, name: avatar.name, size: size }) }, (_a = avatar.src) !== null && _a !== void 0 ? _a : idx));
|
|
20
|
+
}) }), menuAvatars.length > 0 && ((0, jsx_runtime_1.jsx)(ButtonModal_1.ButtonModal, { trigger: { label: `+ ${menuAvatars.length} more`, variant: "text" }, hideEndAdornment: true, content: (0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.df.fdc.gap1.mPx(-12).$, children: menuAvatars.map((a, idx) => {
|
|
21
|
+
var _a;
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(Avatar_1.Avatar, { src: a.src, name: a.name, showName: true, size: "md" }, (_a = a.src) !== null && _a !== void 0 ? _a : idx));
|
|
23
|
+
}) }) }))] }));
|
|
24
|
+
}
|
|
25
|
+
exports.AvatarGroup = AvatarGroup;
|
|
26
|
+
const sizeToOverlap = {
|
|
27
|
+
sm: 9,
|
|
28
|
+
md: 9,
|
|
29
|
+
lg: 15,
|
|
30
|
+
xl: 22,
|
|
31
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Avatar"), exports);
|
|
18
|
+
__exportStar(require("./AvatarButton"), exports);
|
|
19
|
+
__exportStar(require("./AvatarGroup"), exports);
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.multiFilter = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const BaseFilter_1 = require("./BaseFilter");
|
|
6
|
-
const
|
|
6
|
+
const ComboBoxBase_1 = require("../../inputs/internal/ComboBoxBase");
|
|
7
7
|
const MultiSelectField_1 = require("../../inputs/MultiSelectField");
|
|
8
8
|
const ToggleChipGroup_1 = require("../../inputs/ToggleChipGroup");
|
|
9
9
|
const defaultTestId_1 = require("../../utils/defaultTestId");
|
|
@@ -16,7 +16,7 @@ class MultiFilter extends BaseFilter_1.BaseFilter {
|
|
|
16
16
|
var _a;
|
|
17
17
|
if (inModal && this.props.options.length > 0 && this.props.options.length <= 8) {
|
|
18
18
|
const { disabledOptions } = this.props;
|
|
19
|
-
const disabledOptionsWithReasons = Object.fromEntries((_a = disabledOptions === null || disabledOptions === void 0 ? void 0 : disabledOptions.map(
|
|
19
|
+
const disabledOptionsWithReasons = Object.fromEntries((_a = disabledOptions === null || disabledOptions === void 0 ? void 0 : disabledOptions.map(ComboBoxBase_1.disabledOptionToKeyedTuple)) !== null && _a !== void 0 ? _a : []);
|
|
20
20
|
const disabledKeys = Object.keys(disabledOptionsWithReasons);
|
|
21
21
|
return ((0, jsx_runtime_1.jsx)(ToggleChipGroup_1.ToggleChipGroup, { label: this.label, options: this.props.options.map((o) => {
|
|
22
22
|
const value = this.props.getOptionValue(o);
|
|
@@ -7,7 +7,6 @@ export * from "./Accordion";
|
|
|
7
7
|
export * from "./AccordionList";
|
|
8
8
|
export * from "./AutoSaveIndicator";
|
|
9
9
|
export * from "./Avatar";
|
|
10
|
-
export * from "./AvatarButton";
|
|
11
10
|
export { BeamProvider } from "./BeamContext";
|
|
12
11
|
export * from "./Button";
|
|
13
12
|
export * from "./ButtonDatePicker";
|
package/dist/components/index.js
CHANGED
|
@@ -24,7 +24,6 @@ __exportStar(require("./Accordion"), exports);
|
|
|
24
24
|
__exportStar(require("./AccordionList"), exports);
|
|
25
25
|
__exportStar(require("./AutoSaveIndicator"), exports);
|
|
26
26
|
__exportStar(require("./Avatar"), exports);
|
|
27
|
-
__exportStar(require("./AvatarButton"), exports);
|
|
28
27
|
var BeamContext_1 = require("./BeamContext");
|
|
29
28
|
Object.defineProperty(exports, "BeamProvider", { enumerable: true, get: function () { return BeamContext_1.BeamProvider; } });
|
|
30
29
|
__exportStar(require("./Button"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AriaButtonProps } from "@react-types/button";
|
|
2
2
|
import { MutableRefObject, ReactElement, ReactNode } from "react";
|
|
3
3
|
import { MenuTriggerState } from "react-stately";
|
|
4
|
-
import { AvatarButtonProps } from "../AvatarButton";
|
|
4
|
+
import { AvatarButtonProps } from "../Avatar/AvatarButton";
|
|
5
5
|
import { ButtonProps, ButtonVariant } from "../Button";
|
|
6
6
|
import { IconButtonProps } from "../IconButton";
|
|
7
7
|
import { NavLinkProps } from "../NavLink";
|
|
@@ -4,7 +4,7 @@ exports.labelOr = exports.isNavLinkButton = exports.isIconButton = exports.isTex
|
|
|
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 AvatarButton_1 = require("../AvatarButton");
|
|
7
|
+
const AvatarButton_1 = require("../Avatar/AvatarButton");
|
|
8
8
|
const Button_1 = require("../Button");
|
|
9
9
|
const Icon_1 = require("../Icon");
|
|
10
10
|
const IconButton_1 = require("../IconButton");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Value } from "./";
|
|
3
|
-
import {
|
|
3
|
+
import { ComboBoxBaseProps } from "./internal/ComboBoxBase";
|
|
4
4
|
import { Optional } from "../types";
|
|
5
|
-
export interface MultiLineSelectFieldProps<O, V extends Value> extends Exclude<
|
|
5
|
+
export interface MultiLineSelectFieldProps<O, V extends Value> extends Exclude<ComboBoxBaseProps<O, V>, "unsetLabel"> {
|
|
6
6
|
values: V[];
|
|
7
7
|
options: O[];
|
|
8
8
|
getOptionValue: (opt: O) => V;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { Value } from "./";
|
|
3
|
-
import {
|
|
3
|
+
import { ComboBoxBaseProps } from "./internal/ComboBoxBase";
|
|
4
4
|
import { HasIdAndName, Optional } from "../types";
|
|
5
|
-
export interface MultiSelectFieldProps<O, V extends Value> extends Exclude<
|
|
5
|
+
export interface MultiSelectFieldProps<O, V extends Value> extends Exclude<ComboBoxBaseProps<O, V>, "unsetLabel"> {
|
|
6
6
|
/** Renders `opt` in the dropdown menu, defaults to the `getOptionLabel` prop. */
|
|
7
7
|
getOptionMenuLabel?: (opt: O) => string | ReactNode;
|
|
8
8
|
getOptionValue: (opt: O) => V;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MultiSelectField = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const
|
|
5
|
+
const ComboBoxBase_1 = require("./internal/ComboBoxBase");
|
|
6
6
|
function MultiSelectField(props) {
|
|
7
7
|
const { getOptionValue = (opt) => opt.id, // if unset, assume O implements HasId
|
|
8
8
|
getOptionLabel = (opt) => opt.name, // if unset, assume O implements HasName
|
|
9
9
|
options, onSelect, values, ...otherProps } = props;
|
|
10
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)(ComboBoxBase_1.ComboBoxBase, { multiselect: true, ...otherProps, options: options, getOptionLabel: getOptionLabel, getOptionValue: getOptionValue, values: values, onSelect: (values) => {
|
|
11
11
|
const [selectedValues, selectedOptions] = options
|
|
12
12
|
.filter((o) => values.includes(getOptionValue(o)))
|
|
13
13
|
.reduce((acc, o) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Value } from "./";
|
|
3
|
-
import {
|
|
3
|
+
import { ComboBoxBaseProps } from "./internal/ComboBoxBase";
|
|
4
4
|
import { HasIdAndName, Optional } from "../types";
|
|
5
|
-
export interface SelectFieldProps<O, V extends Value> extends Omit<
|
|
5
|
+
export interface SelectFieldProps<O, V extends Value> extends Omit<ComboBoxBaseProps<O, V>, "values" | "onSelect" | "multiselect"> {
|
|
6
6
|
/** The current value; it can be `undefined`, even if `V` cannot be. */
|
|
7
7
|
value: V | undefined;
|
|
8
8
|
onSelect: (value: V | undefined, opt: O | undefined) => void;
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SelectField = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const
|
|
5
|
+
const ComboBoxBase_1 = require("./internal/ComboBoxBase");
|
|
6
6
|
function SelectField(props) {
|
|
7
7
|
const { getOptionValue = (opt) => opt.id, // if unset, assume O implements HasId
|
|
8
8
|
getOptionLabel = (opt) => opt.name, // if unset, assume O implements HasName
|
|
9
9
|
options, onSelect, value, ...otherProps } = props;
|
|
10
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)(ComboBoxBase_1.ComboBoxBase, { ...otherProps, options: options, getOptionLabel: getOptionLabel, getOptionValue: getOptionValue, values: [value], onSelect: (values, options) => {
|
|
11
11
|
if (values.length > 0 && options.length > 0) {
|
|
12
12
|
const option = options[0];
|
|
13
|
-
onSelect(values[0], option ===
|
|
13
|
+
onSelect(values[0], option === ComboBoxBase_1.unsetOption ? undefined : option);
|
|
14
14
|
}
|
|
15
15
|
} }));
|
|
16
16
|
}
|
|
@@ -17,5 +17,9 @@ export interface TextFieldBaseProps<X> extends Pick<BeamTextFieldProps<X>, "labe
|
|
|
17
17
|
tooltip?: ReactNode;
|
|
18
18
|
hideErrorMessage?: boolean;
|
|
19
19
|
alwaysShowHelperText?: boolean;
|
|
20
|
+
/** Used by ComboBoxInput to decide whether we should allow the user to type to filter the options.
|
|
21
|
+
* This is admittedly a hack, as we really should not use a TextField at all in this instance. How we're currently implementing breaks all sorts of accessibility best practices.
|
|
22
|
+
* But for now it is the quickest way to get the desired behavior. Will updating to use a proper select field at another point. */
|
|
23
|
+
typeToFilter?: boolean;
|
|
20
24
|
}
|
|
21
25
|
export declare function TextFieldBase<X extends Only<TextFieldXss, X>>(props: TextFieldBaseProps<X>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -18,7 +18,7 @@ const useTestIds_1 = require("../utils/useTestIds");
|
|
|
18
18
|
function TextFieldBase(props) {
|
|
19
19
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
20
20
|
const { fieldProps, wrap = false } = (0, PresentationContext_1.usePresentationContext)();
|
|
21
|
-
const { label, required, labelProps, inputProps, inputRef, inputWrapRef, groupProps, compact = (_a = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.compact) !== null && _a !== void 0 ? _a : false, errorMsg, helperText, multiline = false, onChange, onBlur, onFocus, xss, endAdornment, startAdornment, labelStyle = (_b = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.labelStyle) !== null && _b !== void 0 ? _b : "above", contrast = false, borderless = (_c = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.borderless) !== null && _c !== void 0 ? _c : false, textAreaMinHeight = 96, clearable = false, tooltip, visuallyDisabled = (_d = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.visuallyDisabled) !== null && _d !== void 0 ? _d : true, errorInTooltip = (_e = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.errorInTooltip) !== null && _e !== void 0 ? _e : false, hideErrorMessage = false, alwaysShowHelperText = false, } = props;
|
|
21
|
+
const { label, required, labelProps, inputProps, inputRef, inputWrapRef, groupProps, compact = (_a = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.compact) !== null && _a !== void 0 ? _a : false, errorMsg, helperText, multiline = false, onChange, onBlur, onFocus, xss, endAdornment, startAdornment, labelStyle = (_b = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.labelStyle) !== null && _b !== void 0 ? _b : "above", contrast = false, borderless = (_c = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.borderless) !== null && _c !== void 0 ? _c : false, textAreaMinHeight = 96, clearable = false, tooltip, visuallyDisabled = (_d = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.visuallyDisabled) !== null && _d !== void 0 ? _d : true, errorInTooltip = (_e = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.errorInTooltip) !== null && _e !== void 0 ? _e : false, hideErrorMessage = false, alwaysShowHelperText = false, typeToFilter = true, } = props;
|
|
22
22
|
const typeScale = (_f = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.typeScale) !== null && _f !== void 0 ? _f : (inputProps.readOnly && labelStyle !== "hidden" ? "smMd" : "sm");
|
|
23
23
|
const internalProps = props.internalProps || {};
|
|
24
24
|
const { compound = false, forceFocus = false, forceHover = false } = internalProps;
|
|
@@ -89,7 +89,7 @@ function TextFieldBase(props) {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
const onFocusChained = (0, react_aria_1.chain)((e) => {
|
|
92
|
-
e.target.select();
|
|
92
|
+
typeToFilter && e.target.select();
|
|
93
93
|
}, onFocus);
|
|
94
94
|
const showFocus = (isFocused && !inputProps.readOnly) || forceFocus;
|
|
95
95
|
const showHover = (isHovered && !inputProps.disabled && !inputProps.readOnly && !isFocused) || forceHover;
|
|
@@ -111,7 +111,9 @@ function TextFieldBase(props) {
|
|
|
111
111
|
// Only show error styles if the field is not disabled, following the pattern that the error message is also hidden
|
|
112
112
|
...(errorMsg && !inputProps.disabled ? fieldStyles.error : {}),
|
|
113
113
|
...Css_1.Css.if(multiline).aifs.px0.mhPx(textAreaMinHeight).$,
|
|
114
|
-
}, ...hoverProps, ref: inputWrapRef, children: [!multiline && labelStyle === "inline" && label && ((0, jsx_runtime_1.jsx)(Label_1.InlineLabel, { labelProps: labelProps, label: label, ...tid.label })), !multiline && startAdornment && (0, jsx_runtime_1.jsx)("span", { css: Css_1.Css.df.aic.fs0.br4.pr1.$, children: startAdornment }), (0, jsx_runtime_1.jsx)(ElementType, { ...(0, react_aria_1.mergeProps)(inputProps, { onBlur, onFocus: onFocusChained, onChange: onDomChange }, { "aria-invalid": Boolean(errorMsg), ...(labelStyle === "hidden" ? { "aria-label": label } : {}) }), ...(errorMsg ? { "aria-errormessage": errorMessageId } : {}), ref: fieldRef, rows: multiline ? 1 : undefined,
|
|
114
|
+
}, ...hoverProps, ref: inputWrapRef, children: [!multiline && labelStyle === "inline" && label && ((0, jsx_runtime_1.jsx)(Label_1.InlineLabel, { labelProps: labelProps, label: label, ...tid.label })), !multiline && startAdornment && (0, jsx_runtime_1.jsx)("span", { css: Css_1.Css.df.aic.fs0.br4.pr1.$, children: startAdornment }), (0, jsx_runtime_1.jsx)(ElementType, { ...(0, react_aria_1.mergeProps)(inputProps, { onBlur, onFocus: onFocusChained, onChange: onDomChange }, { "aria-invalid": Boolean(errorMsg), ...(labelStyle === "hidden" ? { "aria-label": label } : {}) }), ...(errorMsg ? { "aria-errormessage": errorMessageId } : {}), ref: fieldRef, rows: multiline ? 1 : undefined,
|
|
115
|
+
// Make the input field readOnly if the field explicitly sets it to `true`, otherwise base it on whether we should allow `typeToFilter`
|
|
116
|
+
readOnly: inputProps.readOnly || typeToFilter === false, css: {
|
|
115
117
|
...fieldStyles.input,
|
|
116
118
|
...(inputProps.disabled ? fieldStyles.disabled : {}),
|
|
117
119
|
...(showHover ? fieldStyles.hover : {}),
|
|
@@ -2,7 +2,7 @@ import React, { ReactNode } from "react";
|
|
|
2
2
|
import { PresentationFieldProps } from "../../components/PresentationContext";
|
|
3
3
|
import { Value } from "../Value";
|
|
4
4
|
import { BeamFocusableProps } from "../../interfaces";
|
|
5
|
-
export interface
|
|
5
|
+
export interface ComboBoxBaseProps<O, V extends Value> extends BeamFocusableProps, PresentationFieldProps {
|
|
6
6
|
/** Renders `opt` in the dropdown menu, defaults to the `getOptionLabel` prop. `isUnsetOpt` is only defined for single SelectField */
|
|
7
7
|
getOptionMenuLabel?: (opt: O, isUnsetOpt?: boolean) => string | ReactNode;
|
|
8
8
|
getOptionValue: (opt: O) => V;
|
|
@@ -40,7 +40,7 @@ export interface BeamSelectFieldBaseProps<O, V extends Value> extends BeamFocusa
|
|
|
40
40
|
hideErrorMessage?: boolean;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Provides a non-native select/dropdown widget.
|
|
43
|
+
* Provides a non-native select/dropdown widget that allows the user to type to filter the options.
|
|
44
44
|
*
|
|
45
45
|
* The `O` type is a list of options to show, the `V` is the primitive value of a
|
|
46
46
|
* given `O` (i.e. it's id) that you want to use as the current/selected value.
|
|
@@ -48,8 +48,8 @@ export interface BeamSelectFieldBaseProps<O, V extends Value> extends BeamFocusa
|
|
|
48
48
|
* Note that the `V extends Key` constraint come from react-aria,
|
|
49
49
|
* and so we cannot easily change them.
|
|
50
50
|
*/
|
|
51
|
-
export declare function
|
|
52
|
-
type OptionsOrLoad<O> = O[] | {
|
|
51
|
+
export declare function ComboBoxBase<O, V extends Value>(props: ComboBoxBaseProps<O, V>): JSX.Element;
|
|
52
|
+
export type OptionsOrLoad<O> = O[] | {
|
|
53
53
|
initial: O[];
|
|
54
54
|
load: () => Promise<{
|
|
55
55
|
options: O[];
|
|
@@ -61,4 +61,3 @@ export declare function disabledOptionToKeyedTuple(disabledOption: Value | {
|
|
|
61
61
|
value: Value;
|
|
62
62
|
reason: string;
|
|
63
63
|
}): [React.Key, string | undefined];
|
|
64
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.disabledOptionToKeyedTuple = exports.unsetOption = exports.initializeOptions = exports.
|
|
3
|
+
exports.disabledOptionToKeyedTuple = exports.unsetOption = exports.initializeOptions = exports.ComboBoxBase = void 0;
|
|
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");
|
|
@@ -9,12 +9,12 @@ const components_1 = require("../../components");
|
|
|
9
9
|
const internal_1 = require("../../components/internal");
|
|
10
10
|
const PresentationContext_1 = require("../../components/PresentationContext");
|
|
11
11
|
const Css_1 = require("../../Css");
|
|
12
|
+
const ComboBoxInput_1 = require("./ComboBoxInput");
|
|
12
13
|
const ListBox_1 = require("./ListBox");
|
|
13
|
-
const SelectFieldInput_1 = require("./SelectFieldInput");
|
|
14
14
|
const Value_1 = require("../Value");
|
|
15
15
|
const utils_1 = require("../../utils");
|
|
16
16
|
/**
|
|
17
|
-
* Provides a non-native select/dropdown widget.
|
|
17
|
+
* Provides a non-native select/dropdown widget that allows the user to type to filter the options.
|
|
18
18
|
*
|
|
19
19
|
* The `O` type is a list of options to show, the `V` is the primitive value of a
|
|
20
20
|
* given `O` (i.e. it's id) that you want to use as the current/selected value.
|
|
@@ -22,7 +22,7 @@ const utils_1 = require("../../utils");
|
|
|
22
22
|
* Note that the `V extends Key` constraint come from react-aria,
|
|
23
23
|
* and so we cannot easily change them.
|
|
24
24
|
*/
|
|
25
|
-
function
|
|
25
|
+
function ComboBoxBase(props) {
|
|
26
26
|
var _a, _b, _c, _d;
|
|
27
27
|
const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
|
|
28
28
|
const { disabled, readOnly, onSelect, options, multiselect = false, values = [], nothingSelectedText = "", contrast, disabledOptions, borderless, unsetLabel, ...otherProps } = props;
|
|
@@ -250,9 +250,11 @@ function SelectFieldBase(props) {
|
|
|
250
250
|
// Ensures the menu never gets too small.
|
|
251
251
|
minWidth: 200,
|
|
252
252
|
};
|
|
253
|
-
return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.df.fdc.w100.maxw((0, Css_1.px)(550)).if(labelStyle === "left").maxw100.$, ref: comboBoxRef, children: [(0, jsx_runtime_1.jsx)(
|
|
253
|
+
return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.df.fdc.w100.maxw((0, Css_1.px)(550)).if(labelStyle === "left").maxw100.$, ref: comboBoxRef, children: [(0, jsx_runtime_1.jsx)(ComboBoxInput_1.ComboBoxInput, { ...otherProps, buttonProps: buttonProps, buttonRef: triggerRef, inputProps: inputProps, inputRef: inputRef, inputWrapRef: inputWrapRef, state: state, labelProps: labelProps, selectedOptions: fieldState.selectedOptions, getOptionValue: getOptionValue, getOptionLabel: getOptionLabel, contrast: contrast, nothingSelectedText: nothingSelectedText, borderless: borderless, tooltip: (0, components_1.resolveTooltip)(disabled, undefined, readOnly), resetField: resetField,
|
|
254
|
+
// If there are 10 or fewer options and it is not the multiselect, then we disable the typeahead filter for a better UX.
|
|
255
|
+
typeToFilter: !(!multiselect && Array.isArray(options) && options.length <= 10) }), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, { triggerRef: triggerRef, popoverRef: popoverRef, positionProps: positionProps, onClose: () => state.close(), isOpen: state.isOpen, minWidth: 200, children: (0, jsx_runtime_1.jsx)(ListBox_1.ListBox, { ...listBoxProps, positionProps: positionProps, state: state, listBoxRef: listBoxRef, selectedOptions: fieldState.selectedOptions, getOptionLabel: getOptionLabel, getOptionValue: (o) => (0, Value_1.valueToKey)(getOptionValue(o)), contrast: contrast, horizontalLayout: labelStyle === "left", loading: fieldState.optionsLoading, disabledOptionsWithReasons: disabledOptionsWithReasons }) }))] }));
|
|
254
256
|
}
|
|
255
|
-
exports.
|
|
257
|
+
exports.ComboBoxBase = ComboBoxBase;
|
|
256
258
|
function getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText) {
|
|
257
259
|
return selectedOptions.length === 1
|
|
258
260
|
? getOptionLabel(selectedOptions[0])
|
|
@@ -26,6 +26,7 @@ interface SelectFieldInputProps<O, V extends Value> extends PresentationFieldPro
|
|
|
26
26
|
tooltip?: ReactNode;
|
|
27
27
|
resetField: VoidFunction;
|
|
28
28
|
hideErrorMessage?: boolean;
|
|
29
|
+
typeToFilter: boolean;
|
|
29
30
|
}
|
|
30
|
-
export declare function
|
|
31
|
+
export declare function ComboBoxInput<O, V extends Value>(props: SelectFieldInputProps<O, V>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
31
32
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ComboBoxInput = void 0;
|
|
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");
|
|
@@ -8,7 +8,7 @@ const components_1 = require("../../components");
|
|
|
8
8
|
const Css_1 = require("../../Css");
|
|
9
9
|
const TextFieldBase_1 = require("../TextFieldBase");
|
|
10
10
|
const utils_1 = require("../../utils");
|
|
11
|
-
function
|
|
11
|
+
function ComboBoxInput(props) {
|
|
12
12
|
const { inputProps, buttonProps, buttonRef, errorMsg, state, fieldDecoration, onBlur, onFocus, selectedOptions, getOptionValue, getOptionLabel, sizeToContent = false, contrast = false, nothingSelectedText, resetField, ...otherProps } = props;
|
|
13
13
|
const [isFocused, setIsFocused] = (0, react_1.useState)(false);
|
|
14
14
|
const isMultiSelect = state.selectionManager.selectionMode === "multiple";
|
|
@@ -99,4 +99,4 @@ function SelectFieldInput(props) {
|
|
|
99
99
|
},
|
|
100
100
|
} }));
|
|
101
101
|
}
|
|
102
|
-
exports.
|
|
102
|
+
exports.ComboBoxInput = ComboBoxInput;
|
package/package.json
CHANGED
|
File without changes
|