@homebound/beam 2.245.0 → 2.247.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,6 @@
1
1
  import { MutableRefObject, PropsWithChildren, ReactNode } from "react";
2
2
  import { Only, Xss } from "../../Css";
3
- export type ModalSize = "sm" | "md" | "lg" | "xl";
3
+ export type ModalSize = "sm" | "md" | "lg" | "xl" | "xxl";
4
4
  export interface ModalProps {
5
5
  /**
6
6
  * The modal size, defaults to `md`.
@@ -95,6 +95,7 @@ const widths = {
95
95
  md: 480,
96
96
  lg: 640,
97
97
  xl: 800,
98
+ xxl: 900,
98
99
  };
99
100
  const defaultMinHeight = 204;
100
101
  function getSize(size) {
@@ -0,0 +1,24 @@
1
+ import { ReactNode } from "react";
2
+ import { PresentationFieldProps } from "../components/PresentationContext";
3
+ import { TextFieldBaseProps } from "./TextFieldBase";
4
+ interface AutocompleteProps<T> extends Pick<PresentationFieldProps, "labelStyle">, Pick<TextFieldBaseProps<any>, "label" | "clearable" | "startAdornment"> {
5
+ onSelect: (item: T) => void;
6
+ /** A function that returns how to render the an option in the menu. If not set, `getOptionLabel` will be used */
7
+ getOptionMenuLabel?: (o: T) => ReactNode;
8
+ /** A function that returns the string value of the option. Used for accessibility purposes */
9
+ getOptionLabel: (o: T) => string;
10
+ /** A function that returns a unique key for an option */
11
+ getOptionValue: (o: T) => string;
12
+ /** Called when the input value changes */
13
+ onInputChange: (value: string | undefined) => void;
14
+ /** The current value of the input */
15
+ value: string | undefined;
16
+ /** The list of options to choose from */
17
+ options: T[];
18
+ /** The placeholder text to show when the input is empty */
19
+ placeholder?: string;
20
+ /** Whether the input is disabled */
21
+ disabled?: boolean;
22
+ }
23
+ export declare function Autocomplete<T extends object>(props: AutocompleteProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
24
+ export {};
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Autocomplete = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_aria_1 = require("react-aria");
7
+ const react_stately_1 = require("react-stately");
8
+ const components_1 = require("../components");
9
+ const internal_1 = require("../components/internal");
10
+ const ListBox_1 = require("./internal/ListBox");
11
+ const TextFieldBase_1 = require("./TextFieldBase");
12
+ const Value_1 = require("./Value");
13
+ function Autocomplete(props) {
14
+ var _a;
15
+ const { onSelect, getOptionLabel, getOptionValue, getOptionMenuLabel, onInputChange, value, options, disabled, ...others } = props;
16
+ const comboBoxProps = {
17
+ isDisabled: !!disabled,
18
+ onInputChange: onInputChange,
19
+ inputValue: value,
20
+ items: options,
21
+ // Allow the user to type in a value that is not in the list. Allows for the text to stay in the input when the user clicks away
22
+ allowsCustomValue: true,
23
+ children: (item) => ((0, jsx_runtime_1.jsx)(react_stately_1.Item, { textValue: getOptionValue(item), children: getOptionMenuLabel ? getOptionMenuLabel(item) : getOptionLabel(item) }, getOptionValue(item))),
24
+ onSelectionChange: (key) => {
25
+ const selectedItem = options.find((i) => getOptionValue(i) === key);
26
+ if (selectedItem) {
27
+ onInputChange(getOptionLabel(selectedItem));
28
+ onSelect(selectedItem);
29
+ }
30
+ },
31
+ ...others,
32
+ };
33
+ const state = (0, react_stately_1.useComboBoxState)(comboBoxProps);
34
+ const inputWrapRef = (0, react_1.useRef)(null);
35
+ const inputRef = (0, react_1.useRef)(null);
36
+ const listBoxRef = (0, react_1.useRef)(null);
37
+ const popoverRef = (0, react_1.useRef)(null);
38
+ const { inputProps, listBoxProps, labelProps } = (0, react_aria_1.useComboBox)({
39
+ ...comboBoxProps,
40
+ inputRef,
41
+ listBoxRef,
42
+ popoverRef,
43
+ // When the input is focused and there are options, open the menu
44
+ onFocus: () => options.length > 0 && state.open(),
45
+ }, state);
46
+ // useOverlayPosition moves the overlay to the top of the DOM to avoid any z-index issues. Uses the `targetRef` to DOM placement
47
+ const { overlayProps: positionProps } = (0, react_aria_1.useOverlayPosition)({
48
+ targetRef: inputWrapRef,
49
+ overlayRef: popoverRef,
50
+ scrollRef: listBoxRef,
51
+ isOpen: state.isOpen,
52
+ onClose: state.close,
53
+ placement: "bottom left",
54
+ });
55
+ positionProps.style = {
56
+ ...positionProps.style,
57
+ width: (_a = inputWrapRef === null || inputWrapRef === void 0 ? void 0 : inputWrapRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth,
58
+ // Ensures the menu never gets too small.
59
+ minWidth: 200,
60
+ };
61
+ 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
+ // 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 }) }))] }));
64
+ }
65
+ exports.Autocomplete = Autocomplete;
@@ -1,3 +1,4 @@
1
+ export * from "./Autocomplete";
1
2
  export * from "./Checkbox";
2
3
  export * from "./CheckboxGroup";
3
4
  export * from "./ChipSelectField";
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.RadioGroupField = void 0;
18
+ __exportStar(require("./Autocomplete"), exports);
18
19
  __exportStar(require("./Checkbox"), exports);
19
20
  __exportStar(require("./CheckboxGroup"), exports);
20
21
  __exportStar(require("./ChipSelectField"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.245.0",
3
+ "version": "2.247.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",