@homebound/beam 2.135.0 → 2.136.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/ButtonGroup.d.ts +1 -2
- package/dist/components/ButtonMenu.d.ts +1 -2
- package/dist/components/Filters/Filters.js +1 -1
- package/dist/components/Modal/Modal.d.ts +1 -2
- package/dist/components/Modal/Modal.js +2 -2
- package/dist/components/Modal/useModal.d.ts +2 -2
- package/dist/components/internal/Menu.d.ts +1 -2
- package/dist/components/internal/MenuItem.d.ts +1 -2
- package/dist/components/internal/MenuSection.d.ts +1 -2
- package/dist/forms/BoundTextField.d.ts +1 -1
- package/dist/forms/BoundTextField.js +8 -2
- package/dist/hooks/useHover.d.ts +2 -3
- package/dist/index.d.ts +1 -1
- package/dist/inputs/DateField.d.ts +1 -2
- package/dist/inputs/MultiSelectField.d.ts +1 -1
- package/dist/inputs/NumberField.d.ts +1 -2
- package/dist/inputs/SelectField.d.ts +1 -1
- package/dist/inputs/SelectField.js +2 -1
- package/dist/inputs/TextAreaField.d.ts +1 -2
- package/dist/inputs/TextField.d.ts +2 -3
- package/dist/inputs/internal/SelectFieldBase.d.ts +14 -8
- package/dist/inputs/internal/SelectFieldBase.js +27 -3
- package/dist/inputs/internal/SelectFieldInput.d.ts +1 -2
- package/dist/interfaces.d.ts +3 -4
- package/dist/types.d.ts +0 -1
- package/dist/utils/getInteractiveElement.d.ts +1 -1
- package/dist/utils/getInteractiveElement.js +7 -2
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IconProps } from "./Icon";
|
|
2
|
-
import { Callback } from "../types";
|
|
3
2
|
export interface ButtonGroupProps {
|
|
4
3
|
buttons: ButtonGroupButton[];
|
|
5
4
|
/** Disables all buttons in ButtonGroup */
|
|
@@ -9,7 +8,7 @@ export interface ButtonGroupProps {
|
|
|
9
8
|
export declare type ButtonGroupButton = {
|
|
10
9
|
icon?: IconProps["icon"];
|
|
11
10
|
text?: string;
|
|
12
|
-
onClick?:
|
|
11
|
+
onClick?: VoidFunction;
|
|
13
12
|
/** Disables the button. Note we don't support the `disabled: ReactNode`/tooltip for now. */
|
|
14
13
|
disabled?: boolean;
|
|
15
14
|
/** Indicates the active/selected button, as in a tab or toggle. */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IconProps } from "./Icon";
|
|
2
2
|
import { OverlayTriggerProps } from "./internal/OverlayTrigger";
|
|
3
|
-
import { Callback } from "../types";
|
|
4
3
|
interface ButtonMenuProps extends Pick<OverlayTriggerProps, "trigger" | "placement" | "disabled" | "tooltip"> {
|
|
5
4
|
items: MenuItem[];
|
|
6
5
|
persistentItems?: MenuItem[];
|
|
@@ -9,7 +8,7 @@ interface ButtonMenuProps extends Pick<OverlayTriggerProps, "trigger" | "placeme
|
|
|
9
8
|
export declare function ButtonMenu(props: ButtonMenuProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
10
9
|
declare type MenuItemBase = {
|
|
11
10
|
label: string;
|
|
12
|
-
onClick: string |
|
|
11
|
+
onClick: string | VoidFunction;
|
|
13
12
|
disabled?: boolean;
|
|
14
13
|
};
|
|
15
14
|
export declare type IconMenuItemType = MenuItemBase & {
|
|
@@ -29,7 +29,7 @@ function Filters(props) {
|
|
|
29
29
|
return [Object.fromEntries(impls), {}];
|
|
30
30
|
}, [numberOfPageFilters, filterDefs]);
|
|
31
31
|
const numModalFilters = (0, utils_1.safeKeys)(modalFilters).filter((fk) => filter[fk] !== undefined).length;
|
|
32
|
-
const maybeGroupByField = groupBy ? ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(SelectField_1.SelectField, { label: "Group by", compact: !vertical, inlineLabel: !vertical, sizeToContent: !vertical, options: groupBy.options, getOptionValue: (o) => o.id, getOptionLabel: (o) => o.name, value: groupBy.value, onSelect: (g) => groupBy.setValue(g) }, void 0) }, void 0)) : null;
|
|
32
|
+
const maybeGroupByField = groupBy ? ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(SelectField_1.SelectField, { label: "Group by", compact: !vertical, inlineLabel: !vertical, sizeToContent: !vertical, options: groupBy.options, getOptionValue: (o) => o.id, getOptionLabel: (o) => o.name, value: groupBy.value, onSelect: (g) => g && groupBy.setValue(g) }, void 0) }, void 0)) : null;
|
|
33
33
|
// Return list of filter components. `onSelect` should update the `filter`
|
|
34
34
|
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: {
|
|
35
35
|
...(vertical ? Css_1.Css.df.fdc.childGap2.$ : Css_1.Css.df.aic.childGap1.$),
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MutableRefObject, ReactNode } from "react";
|
|
2
2
|
import { Only, Xss } from "../../Css";
|
|
3
|
-
import { Callback } from "../../types";
|
|
4
3
|
export declare type ModalSize = "sm" | "md" | "lg" | "xl";
|
|
5
4
|
export interface ModalProps {
|
|
6
5
|
/**
|
|
@@ -18,7 +17,7 @@ export interface ModalProps {
|
|
|
18
17
|
/** Force scrolling i.e. to avoid content jumping left/right as scroll bar goes away/comes back. */
|
|
19
18
|
forceScrolling?: boolean;
|
|
20
19
|
/** Adds a callback that is called _after_ close has definitely happened. */
|
|
21
|
-
onClose?:
|
|
20
|
+
onClose?: VoidFunction;
|
|
22
21
|
/** Imperative API for interacting with the Modal */
|
|
23
22
|
api?: MutableRefObject<ModalApi | undefined>;
|
|
24
23
|
/** Adds a border for the header. */
|
|
@@ -31,8 +31,8 @@ function Modal(props) {
|
|
|
31
31
|
onClose: closeModal,
|
|
32
32
|
isDismissable: true,
|
|
33
33
|
shouldCloseOnInteractOutside: (el) => {
|
|
34
|
-
// Do not close the Modal if the user is interacting with the Tribute mentions dropdown (via RichTextField).
|
|
35
|
-
return !el.closest(".tribute-container");
|
|
34
|
+
// Do not close the Modal if the user is interacting with the Tribute mentions dropdown (via RichTextField) or with another 3rd party dialog (such as a lightbox) on top of it.
|
|
35
|
+
return !(el.closest(".tribute-container") || el.closest("[role='dialog']"));
|
|
36
36
|
},
|
|
37
37
|
}, ref);
|
|
38
38
|
const { modalProps } = (0, react_aria_1.useModal)();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckFn } from "../../types";
|
|
2
2
|
import { ModalProps } from "./Modal";
|
|
3
3
|
export interface UseModalHook {
|
|
4
4
|
openModal: (props: ModalProps) => void;
|
|
5
|
-
closeModal:
|
|
5
|
+
closeModal: VoidFunction;
|
|
6
6
|
addCanClose: (canClose: CheckFn) => void;
|
|
7
7
|
setSize: (size: ModalProps["size"]) => void;
|
|
8
8
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { HTMLAttributes, PropsWithChildren } from "react";
|
|
2
2
|
import { MenuItem } from "..";
|
|
3
|
-
import { Callback } from "../../types";
|
|
4
3
|
interface MenuProps<T> {
|
|
5
4
|
ariaMenuProps: HTMLAttributes<HTMLElement>;
|
|
6
|
-
onClose:
|
|
5
|
+
onClose: VoidFunction;
|
|
7
6
|
items: MenuItem[];
|
|
8
7
|
persistentItems?: MenuItem[];
|
|
9
8
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Node } from "@react-types/shared";
|
|
2
2
|
import { TreeState } from "react-stately";
|
|
3
3
|
import { MenuItem } from "../ButtonMenu";
|
|
4
|
-
import { Callback } from "../../types";
|
|
5
4
|
interface MenuItemProps {
|
|
6
5
|
item: Node<MenuItem>;
|
|
7
6
|
state: TreeState<MenuItem>;
|
|
8
|
-
onClose:
|
|
7
|
+
onClose: VoidFunction;
|
|
9
8
|
}
|
|
10
9
|
export declare function MenuItemImpl(props: MenuItemProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
11
10
|
export {};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Node } from "@react-types/shared";
|
|
2
2
|
import { TreeState } from "react-stately";
|
|
3
3
|
import { MenuItem } from "../ButtonMenu";
|
|
4
|
-
import { Callback } from "../../types";
|
|
5
4
|
interface MenuSectionProps {
|
|
6
5
|
section: Node<MenuItem>;
|
|
7
6
|
state: TreeState<MenuItem>;
|
|
8
|
-
onClose:
|
|
7
|
+
onClose: VoidFunction;
|
|
9
8
|
}
|
|
10
9
|
export declare function MenuSectionImpl(props: MenuSectionProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
11
10
|
export {};
|
|
@@ -2,7 +2,7 @@ import { FieldState } from "@homebound/form-state";
|
|
|
2
2
|
import { Only } from "../Css";
|
|
3
3
|
import { TextFieldProps } from "../inputs";
|
|
4
4
|
import { TextFieldXss } from "../interfaces";
|
|
5
|
-
export declare type BoundTextFieldProps<X> = Omit<TextFieldProps<X>, "value" | "onChange" | "
|
|
5
|
+
export declare type BoundTextFieldProps<X> = Omit<TextFieldProps<X>, "value" | "onChange" | "label"> & {
|
|
6
6
|
label?: string;
|
|
7
7
|
field: FieldState<any, string | null | undefined>;
|
|
8
8
|
onChange?: (value: string | undefined) => void;
|
|
@@ -8,9 +8,15 @@ const utils_1 = require("../utils");
|
|
|
8
8
|
const defaultLabel_1 = require("../utils/defaultLabel");
|
|
9
9
|
/** Wraps `TextField` and binds it to a form field. */
|
|
10
10
|
function BoundTextField(props) {
|
|
11
|
-
const { field, readOnly, onChange = (value) => field.set(value), label = (0, defaultLabel_1.defaultLabel)(field.key), onEnter, ...others } = props;
|
|
11
|
+
const { field, readOnly, onBlur, onFocus, onChange = (value) => field.set(value), label = (0, defaultLabel_1.defaultLabel)(field.key), onEnter, ...others } = props;
|
|
12
12
|
const testId = (0, utils_1.useTestIds)(props, field.key);
|
|
13
|
-
return ((0, jsx_runtime_1.jsx)(mobx_react_1.Observer, { children: () => ((0, jsx_runtime_1.jsx)(inputs_1.TextField, Object.assign({ label: label, value: field.value || undefined, onChange: onChange, readOnly: readOnly !== null && readOnly !== void 0 ? readOnly : field.readOnly, errorMsg: field.touched ? field.errors.join(" ") : undefined, required: field.required, onBlur: () =>
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(mobx_react_1.Observer, { children: () => ((0, jsx_runtime_1.jsx)(inputs_1.TextField, Object.assign({ label: label, value: field.value || undefined, onChange: onChange, readOnly: readOnly !== null && readOnly !== void 0 ? readOnly : field.readOnly, errorMsg: field.touched ? field.errors.join(" ") : undefined, required: field.required, onBlur: () => {
|
|
14
|
+
(0, utils_1.maybeCall)(onBlur);
|
|
15
|
+
field.blur();
|
|
16
|
+
}, onFocus: () => {
|
|
17
|
+
(0, utils_1.maybeCall)(onFocus);
|
|
18
|
+
field.focus();
|
|
19
|
+
}, onEnter: () => {
|
|
14
20
|
(0, utils_1.maybeCall)(onEnter);
|
|
15
21
|
field.maybeAutoSave();
|
|
16
22
|
} }, testId, others), void 0)) }, void 0));
|
package/dist/hooks/useHover.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { HTMLAttributes } from "react";
|
|
2
|
-
import { Callback } from "../types";
|
|
3
2
|
interface useHoverProps {
|
|
4
|
-
onHoverStart?:
|
|
5
|
-
onHoverEnd?:
|
|
3
|
+
onHoverStart?: VoidFunction;
|
|
4
|
+
onHoverEnd?: VoidFunction;
|
|
6
5
|
onHoverChange?: (isHovering: boolean) => void;
|
|
7
6
|
disabled?: boolean;
|
|
8
7
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { Modifier } from "react-day-picker";
|
|
3
3
|
import { TextFieldBaseProps } from "./TextFieldBase";
|
|
4
|
-
import { Callback } from "../types";
|
|
5
4
|
export interface DateFieldProps extends Pick<TextFieldBaseProps<{}>, "borderless" | "visuallyDisabled" | "hideLabel" | "compact"> {
|
|
6
5
|
value: Date | undefined;
|
|
7
6
|
label: string;
|
|
@@ -27,7 +26,7 @@ export interface DateFieldProps extends Pick<TextFieldBaseProps<{}>, "borderless
|
|
|
27
26
|
* exposed from `react-day-picker`: https://react-day-picker.js.org/api/DayPicker#modifiers
|
|
28
27
|
*/
|
|
29
28
|
disabledDays?: Modifier | Modifier[];
|
|
30
|
-
onEnter?:
|
|
29
|
+
onEnter?: VoidFunction;
|
|
31
30
|
defaultOpen?: boolean;
|
|
32
31
|
}
|
|
33
32
|
export declare function DateField(props: DateFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -2,7 +2,7 @@ import { ReactNode } from "react";
|
|
|
2
2
|
import { Value } from "./";
|
|
3
3
|
import { BeamSelectFieldBaseProps } from "./internal/SelectFieldBase";
|
|
4
4
|
import { HasIdAndName, Optional } from "../types";
|
|
5
|
-
export interface MultiSelectFieldProps<O, V extends Value> extends BeamSelectFieldBaseProps<O, V> {
|
|
5
|
+
export interface MultiSelectFieldProps<O, V extends Value> extends Exclude<BeamSelectFieldBaseProps<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;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { Xss } from "../Css";
|
|
3
|
-
import { Callback } from "../types";
|
|
4
3
|
export declare type NumberFieldType = "cents" | "percent" | "basisPoints" | "days";
|
|
5
4
|
export interface NumberFieldProps {
|
|
6
5
|
label: string;
|
|
@@ -23,7 +22,7 @@ export interface NumberFieldProps {
|
|
|
23
22
|
displayDirection?: boolean;
|
|
24
23
|
numFractionDigits?: number;
|
|
25
24
|
truncate?: boolean;
|
|
26
|
-
onEnter?:
|
|
25
|
+
onEnter?: VoidFunction;
|
|
27
26
|
}
|
|
28
27
|
export declare function NumberField(props: NumberFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
29
28
|
export declare function formatValue(value: number, factor: number, numFractionDigits: number | undefined): number | undefined;
|
|
@@ -4,7 +4,7 @@ import { HasIdAndName, Optional } from "../types";
|
|
|
4
4
|
export interface SelectFieldProps<O, V extends Value> extends Omit<BeamSelectFieldBaseProps<O, V>, "values" | "onSelect"> {
|
|
5
5
|
/** The current value; it can be `undefined`, even if `V` cannot be. */
|
|
6
6
|
value: V | undefined;
|
|
7
|
-
onSelect: (value: V, opt: O) => void;
|
|
7
|
+
onSelect: (value: V | undefined, opt: O | undefined) => void;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Provides a non-native select/dropdown widget.
|
|
@@ -9,7 +9,8 @@ function SelectField(props) {
|
|
|
9
9
|
options, onSelect, value, ...otherProps } = props;
|
|
10
10
|
return ((0, jsx_runtime_1.jsx)(SelectFieldBase_1.SelectFieldBase, Object.assign({}, 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 === SelectFieldBase_1.unsetOption ? undefined : option);
|
|
13
14
|
}
|
|
14
15
|
} }), void 0));
|
|
15
16
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Only } from "../Css";
|
|
2
2
|
import { BeamTextFieldProps, TextFieldXss } from "../interfaces";
|
|
3
|
-
import { Callback } from "../types";
|
|
4
3
|
export interface TextAreaFieldProps<X> extends BeamTextFieldProps<X> {
|
|
5
4
|
preventNewLines?: boolean;
|
|
6
|
-
onEnter?:
|
|
5
|
+
onEnter?: VoidFunction;
|
|
7
6
|
}
|
|
8
7
|
/** Returns a <textarea /> element that auto-adjusts height based on the field's value */
|
|
9
8
|
export declare function TextAreaField<X extends Only<TextFieldXss, X>>(props: TextAreaFieldProps<X>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { MutableRefObject, ReactNode } from "react";
|
|
2
2
|
import { Only } from "../Css";
|
|
3
3
|
import { BeamTextFieldProps, TextFieldXss } from "../interfaces";
|
|
4
|
-
import { Callback } from "../types";
|
|
5
4
|
export interface TextFieldProps<X> extends BeamTextFieldProps<X> {
|
|
6
5
|
compact?: boolean;
|
|
7
6
|
inlineLabel?: boolean;
|
|
8
7
|
clearable?: boolean;
|
|
9
8
|
api?: MutableRefObject<TextFieldApi | undefined>;
|
|
10
|
-
onEnter?:
|
|
9
|
+
onEnter?: VoidFunction;
|
|
11
10
|
endAdornment?: ReactNode;
|
|
12
11
|
startAdornment?: ReactNode;
|
|
13
12
|
}
|
|
14
13
|
export declare function TextField<X extends Only<TextFieldXss, X>>(props: TextFieldProps<X>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
15
14
|
export declare type TextFieldApi = {
|
|
16
|
-
focus:
|
|
15
|
+
focus: VoidFunction;
|
|
17
16
|
};
|
|
@@ -3,8 +3,8 @@ import { PresentationFieldProps } from "../../components/PresentationContext";
|
|
|
3
3
|
import { Value } from "../Value";
|
|
4
4
|
import { BeamFocusableProps } from "../../interfaces";
|
|
5
5
|
export interface BeamSelectFieldBaseProps<O, V extends Value> extends BeamFocusableProps, PresentationFieldProps {
|
|
6
|
-
/** Renders `opt` in the dropdown menu, defaults to the `getOptionLabel` prop. */
|
|
7
|
-
getOptionMenuLabel?: (opt: O) => string | ReactNode;
|
|
6
|
+
/** Renders `opt` in the dropdown menu, defaults to the `getOptionLabel` prop. `isUnsetOpt` is only defined for single SelectField */
|
|
7
|
+
getOptionMenuLabel?: (opt: O, isUnsetOpt?: boolean) => string | ReactNode;
|
|
8
8
|
getOptionValue: (opt: O) => V;
|
|
9
9
|
getOptionLabel: (opt: O) => string;
|
|
10
10
|
/** The current value; it can be `undefined`, even if `V` cannot be. */
|
|
@@ -12,12 +12,7 @@ export interface BeamSelectFieldBaseProps<O, V extends Value> extends BeamFocusa
|
|
|
12
12
|
onSelect: (values: V[], opts: O[]) => void;
|
|
13
13
|
multiselect?: boolean;
|
|
14
14
|
disabledOptions?: V[];
|
|
15
|
-
options: O
|
|
16
|
-
initial: O[];
|
|
17
|
-
load: () => Promise<{
|
|
18
|
-
options: O[];
|
|
19
|
-
}>;
|
|
20
|
-
};
|
|
15
|
+
options: OptionsOrLoad<O>;
|
|
21
16
|
/** Whether the field is disabled. If a ReactNode, it's treated as a "disabled reason" that's shown in a tooltip. */
|
|
22
17
|
disabled?: boolean | ReactNode;
|
|
23
18
|
required?: boolean;
|
|
@@ -39,6 +34,8 @@ export interface BeamSelectFieldBaseProps<O, V extends Value> extends BeamFocusa
|
|
|
39
34
|
contrast?: boolean;
|
|
40
35
|
/** Placeholder content */
|
|
41
36
|
placeholder?: string;
|
|
37
|
+
/** Only used for Single Select Fields. If set, prepends an option with a `undefined` value at the top of the list */
|
|
38
|
+
unsetLabel?: string;
|
|
42
39
|
}
|
|
43
40
|
/**
|
|
44
41
|
* Provides a non-native select/dropdown widget.
|
|
@@ -50,3 +47,12 @@ export interface BeamSelectFieldBaseProps<O, V extends Value> extends BeamFocusa
|
|
|
50
47
|
* and so we cannot easily change them.
|
|
51
48
|
*/
|
|
52
49
|
export declare function SelectFieldBase<O, V extends Value>(props: BeamSelectFieldBaseProps<O, V>): JSX.Element;
|
|
50
|
+
declare type OptionsOrLoad<O> = O[] | {
|
|
51
|
+
initial: O[];
|
|
52
|
+
load: () => Promise<{
|
|
53
|
+
options: O[];
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
export declare function initializeOptions<O>(options: OptionsOrLoad<O>, unsetLabel: string | undefined): OptionsOrLoad<O>;
|
|
57
|
+
export declare const unsetOption: {};
|
|
58
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SelectFieldBase = void 0;
|
|
3
|
+
exports.unsetOption = exports.initializeOptions = exports.SelectFieldBase = 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");
|
|
@@ -23,7 +23,15 @@ const utils_1 = require("../../utils");
|
|
|
23
23
|
*/
|
|
24
24
|
function SelectFieldBase(props) {
|
|
25
25
|
var _a;
|
|
26
|
-
const { disabled, readOnly, onSelect, options
|
|
26
|
+
const { disabled, readOnly, onSelect, options, multiselect = false, values = [], nothingSelectedText = "", contrast, disabledOptions, borderless, unsetLabel, ...otherProps } = props;
|
|
27
|
+
// Call `initializeOptions` to prepend the `unset` option if the `unsetLabel` was provided.
|
|
28
|
+
const maybeOptions = (0, react_1.useMemo)(() => initializeOptions(options, unsetLabel), [options, unsetLabel]);
|
|
29
|
+
// Memoize the callback functions and handle the `unset` option if provided.
|
|
30
|
+
const getOptionLabel = (0, react_1.useCallback)((o) => (unsetLabel && o === exports.unsetOption ? unsetLabel : props.getOptionLabel(o)), [props.getOptionLabel, unsetLabel]);
|
|
31
|
+
const getOptionValue = (0, react_1.useCallback)((o) => (unsetLabel && o === exports.unsetOption ? undefined : props.getOptionValue(o)), [props.getOptionValue, unsetLabel]);
|
|
32
|
+
const getOptionMenuLabel = (0, react_1.useCallback)((o) => props.getOptionMenuLabel
|
|
33
|
+
? props.getOptionMenuLabel(o, Boolean(unsetLabel) && o === exports.unsetOption)
|
|
34
|
+
: getOptionLabel(o), [props.getOptionValue, unsetLabel, getOptionLabel]);
|
|
27
35
|
const { contains } = (0, react_aria_1.useFilter)({ sensitivity: "base" });
|
|
28
36
|
const isDisabled = !!disabled;
|
|
29
37
|
const isReadOnly = !!readOnly;
|
|
@@ -105,7 +113,9 @@ function SelectFieldBase(props) {
|
|
|
105
113
|
async function maybeInitLoad() {
|
|
106
114
|
if (!Array.isArray(maybeOptions)) {
|
|
107
115
|
setFieldState((prevState) => ({ ...prevState, optionsLoading: true }));
|
|
108
|
-
const
|
|
116
|
+
const loadedOptions = (await maybeOptions.load()).options;
|
|
117
|
+
// Ensure the `unset` option is prepended to the top of the list if `unsetLabel` was provided
|
|
118
|
+
const options = !unsetLabel ? loadedOptions : getOptionsWithUnset(unsetLabel, loadedOptions);
|
|
109
119
|
setFieldState((prevState) => ({
|
|
110
120
|
...prevState,
|
|
111
121
|
filteredOptions: options,
|
|
@@ -245,3 +255,17 @@ function getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSele
|
|
|
245
255
|
? nothingSelectedText
|
|
246
256
|
: "";
|
|
247
257
|
}
|
|
258
|
+
function initializeOptions(options, unsetLabel) {
|
|
259
|
+
if (!unsetLabel) {
|
|
260
|
+
return options;
|
|
261
|
+
}
|
|
262
|
+
if (Array.isArray(options)) {
|
|
263
|
+
return getOptionsWithUnset(unsetLabel, options);
|
|
264
|
+
}
|
|
265
|
+
return { ...options, initial: getOptionsWithUnset(unsetLabel, options.initial) };
|
|
266
|
+
}
|
|
267
|
+
exports.initializeOptions = initializeOptions;
|
|
268
|
+
function getOptionsWithUnset(unsetLabel, options) {
|
|
269
|
+
return [exports.unsetOption, ...options];
|
|
270
|
+
}
|
|
271
|
+
exports.unsetOption = {};
|
|
@@ -2,7 +2,6 @@ import { InputHTMLAttributes, LabelHTMLAttributes, MutableRefObject, ReactNode }
|
|
|
2
2
|
import { ComboBoxState } from "react-stately";
|
|
3
3
|
import { PresentationFieldProps } from "../../components/PresentationContext";
|
|
4
4
|
import { Value } from "../Value";
|
|
5
|
-
import { Callback } from "../../types";
|
|
6
5
|
interface SelectFieldInputProps<O, V extends Value> extends PresentationFieldProps {
|
|
7
6
|
buttonProps: any;
|
|
8
7
|
buttonRef: MutableRefObject<HTMLButtonElement | null>;
|
|
@@ -26,7 +25,7 @@ interface SelectFieldInputProps<O, V extends Value> extends PresentationFieldPro
|
|
|
26
25
|
contrast?: boolean;
|
|
27
26
|
nothingSelectedText: string;
|
|
28
27
|
tooltip?: ReactNode;
|
|
29
|
-
resetField:
|
|
28
|
+
resetField: VoidFunction;
|
|
30
29
|
}
|
|
31
30
|
export declare function SelectFieldInput<O, V extends Value>(props: SelectFieldInputProps<O, V>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
32
31
|
export {};
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { PressEvent } from "@react-types/shared";
|
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
import { PresentationFieldProps } from "./components/PresentationContext";
|
|
4
4
|
import { Xss } from "./Css";
|
|
5
|
-
import { Callback } from "./types";
|
|
6
5
|
/** Base Interfaced */
|
|
7
6
|
export interface BeamFocusableProps {
|
|
8
7
|
/** Whether the element should receive focus on render. */
|
|
@@ -36,9 +35,9 @@ export interface BeamTextFieldProps<X> extends BeamFocusableProps, PresentationF
|
|
|
36
35
|
/** Handler called when the interactive element state changes. */
|
|
37
36
|
onChange: (value: string | undefined) => void;
|
|
38
37
|
/** Called when the component loses focus, mostly for BoundTextField to use. */
|
|
39
|
-
onBlur?:
|
|
40
|
-
onFocus?:
|
|
41
|
-
onEnter?:
|
|
38
|
+
onBlur?: VoidFunction;
|
|
39
|
+
onFocus?: VoidFunction;
|
|
40
|
+
onEnter?: VoidFunction;
|
|
42
41
|
/** Whether the field is readOnly. If a ReactNode, it's treated as a "readOnly reason" that's shown in a tooltip. */
|
|
43
42
|
readOnly?: boolean | ReactNode;
|
|
44
43
|
placeholder?: string;
|
package/dist/types.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export declare type HasIdAndName<V = string> = {
|
|
|
3
3
|
name: string;
|
|
4
4
|
};
|
|
5
5
|
export declare type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
6
|
-
export declare type Callback = () => void;
|
|
7
6
|
export declare type CheckFn = () => boolean;
|
|
8
7
|
export declare type CanCloseCheck = {
|
|
9
8
|
check: CheckFn;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PressEvent } from "@react-types/shared";
|
|
2
2
|
import { HTMLAttributes, ReactNode } from "react";
|
|
3
|
-
export declare function getButtonOrLink(content: ReactNode, onClick: ((e: PressEvent) => void) | string, attrs: HTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, openInNew?: boolean, downloadLink?: boolean): JSX.Element;
|
|
3
|
+
export declare function getButtonOrLink(content: ReactNode, onClick: ((e: PressEvent) => void) | VoidFunction | string | undefined, attrs: HTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, openInNew?: boolean, downloadLink?: boolean): JSX.Element;
|
|
@@ -4,7 +4,12 @@ exports.getButtonOrLink = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const react_router_dom_1 = require("react-router-dom");
|
|
6
6
|
const index_1 = require("./index");
|
|
7
|
-
function getButtonOrLink(content,
|
|
8
|
-
|
|
7
|
+
function getButtonOrLink(content,
|
|
8
|
+
// PressEvent set by React-Aria's `useButton`.
|
|
9
|
+
onClick, attrs, openInNew = false, downloadLink = false) {
|
|
10
|
+
return typeof onClick === "string" ? ((0, index_1.isAbsoluteUrl)(onClick) || openInNew || downloadLink ? ((0, jsx_runtime_1.jsx)("a", Object.assign({}, attrs, { href: onClick }, (downloadLink ? { download: "" } : { target: "_blank", rel: "noreferrer noopener" }), { children: content }), void 0)) : ((0, jsx_runtime_1.jsx)(react_router_dom_1.Link, Object.assign({}, attrs, { to: onClick }, { children: content }), void 0))) : (
|
|
11
|
+
// Cast `onClick` as VoidFunction this is the type if will be if not overwritten by `attrs` (which happens via Button.tsx)
|
|
12
|
+
// Type `(e: PressEvent) => {}` is only used but Button.tsx, which passes the `onClick` prop as part of the `attrs`.
|
|
13
|
+
(0, jsx_runtime_1.jsx)("button", Object.assign({ onClick: onClick }, attrs, { children: content }), void 0));
|
|
9
14
|
}
|
|
10
15
|
exports.getButtonOrLink = getButtonOrLink;
|