@homebound/beam 2.269.0 → 2.270.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.
@@ -1,6 +1,7 @@
1
1
  import { ReactNode } from "react";
2
2
  import { PresentationFieldProps } from "../components/PresentationContext";
3
3
  import { TextFieldBaseProps } from "./TextFieldBase";
4
+ import { Value } from "./Value";
4
5
  interface AutocompleteProps<T> extends Pick<PresentationFieldProps, "labelStyle">, Pick<TextFieldBaseProps<any>, "label" | "clearable" | "startAdornment"> {
5
6
  onSelect: (item: T) => void;
6
7
  /** A function that returns how to render the an option in the menu. If not set, `getOptionLabel` will be used */
@@ -19,6 +20,11 @@ interface AutocompleteProps<T> extends Pick<PresentationFieldProps, "labelStyle"
19
20
  placeholder?: string;
20
21
  /** Whether the input is disabled */
21
22
  disabled?: boolean;
23
+ /** A list of options that are disabled. Can be either the option itself or an object with the option and a reason why it is disabled */
24
+ disabledOptions?: (Value | {
25
+ value: Value;
26
+ reason: string;
27
+ })[];
22
28
  }
23
29
  export declare function Autocomplete<T extends object>(props: AutocompleteProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
24
30
  export {};
@@ -7,14 +7,17 @@ const react_aria_1 = require("react-aria");
7
7
  const react_stately_1 = require("react-stately");
8
8
  const components_1 = require("../components");
9
9
  const internal_1 = require("../components/internal");
10
+ const ComboBoxBase_1 = require("./internal/ComboBoxBase");
10
11
  const ListBox_1 = require("./internal/ListBox");
11
12
  const TextFieldBase_1 = require("./TextFieldBase");
12
13
  const Value_1 = require("./Value");
13
14
  function Autocomplete(props) {
14
- var _a;
15
- const { onSelect, getOptionLabel, getOptionValue, getOptionMenuLabel, onInputChange, value, options, disabled, ...others } = props;
15
+ var _a, _b;
16
+ const { onSelect, getOptionLabel, getOptionValue, getOptionMenuLabel, onInputChange, value, options, disabled, disabledOptions, ...others } = props;
17
+ const disabledOptionsWithReasons = Object.fromEntries((_a = disabledOptions === null || disabledOptions === void 0 ? void 0 : disabledOptions.map(ComboBoxBase_1.disabledOptionToKeyedTuple)) !== null && _a !== void 0 ? _a : []);
16
18
  const comboBoxProps = {
17
19
  isDisabled: !!disabled,
20
+ disabledKeys: Object.keys(disabledOptionsWithReasons),
18
21
  onInputChange: onInputChange,
19
22
  inputValue: value,
20
23
  items: options,
@@ -54,12 +57,12 @@ function Autocomplete(props) {
54
57
  });
55
58
  positionProps.style = {
56
59
  ...positionProps.style,
57
- width: (_a = inputWrapRef === null || inputWrapRef === void 0 ? void 0 : inputWrapRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth,
60
+ width: (_b = inputWrapRef === null || inputWrapRef === void 0 ? void 0 : inputWrapRef.current) === null || _b === void 0 ? void 0 : _b.clientWidth,
58
61
  // Ensures the menu never gets too small.
59
62
  minWidth: 200,
60
63
  };
61
64
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TextFieldBase_1.TextFieldBase, { inputRef: inputRef, inputWrapRef: inputWrapRef, inputProps: inputProps, labelProps: labelProps, onChange: onInputChange, clearable: true,
62
65
  // Respect if caller to passes in `startAdornment={undefined}`
63
- startAdornment: "startAdornment" in props ? props.startAdornment : (0, jsx_runtime_1.jsx)(components_1.Icon, { icon: "search" }), ...others }), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, { triggerRef: inputRef, 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, getOptionValue: (o) => (0, Value_1.valueToKey)(getOptionValue(o)), getOptionLabel: getOptionLabel }) }))] }));
66
+ startAdornment: "startAdornment" in props ? props.startAdornment : (0, jsx_runtime_1.jsx)(components_1.Icon, { icon: "search" }), ...others }), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, { triggerRef: inputRef, 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, getOptionValue: (o) => (0, Value_1.valueToKey)(getOptionValue(o)), getOptionLabel: getOptionLabel, disabledOptionsWithReasons: disabledOptionsWithReasons }) }))] }));
64
67
  }
65
68
  exports.Autocomplete = Autocomplete;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.269.0",
3
+ "version": "2.270.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",