@wavv/ui 2.4.6-alpha.1 → 2.4.6

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,20 +1,25 @@
1
+ import { type ReactNode } from 'react';
1
2
  import type { ComboBoxProps } from './typeDefs/reactAriaTypes';
2
3
  import type { OpenStateProps, SelectInputProps } from './typeDefs/selectionTypes';
3
4
  type Props = {
4
5
  /** Use when loading options asynchronously with onTextChange */
5
6
  loadingResults?: boolean;
7
+ /** The element/string to display when the table is empty */
8
+ emptyFallback?: ReactNode;
6
9
  /** The function to be called when the search input is updated */
7
10
  onTextChange?: (text: string) => void;
8
11
  /** The function to be called when the input text does not match any options */
9
12
  onCreate?: (text: string) => void;
13
+ /** Customize the create option label. Receives raw inputText and returns the label to display. */
14
+ formatCreateOption?: (inputText: string) => ReactNode;
10
15
  ref?: React.Ref<HTMLInputElement>;
11
16
  } & SelectInputProps & OpenStateProps & ComboBoxProps;
12
- declare const _default: (({ backgroundColor, menuBackground, children, fontSize, disabled, invalid, required, readOnly, loading, loadingResults, label, options, placeholder, placeholderColor, description, errorMessage, textOnly, value, defaultValue, width, height, maxHeight, iconLeft, leftElement, rightElement, allowRepeatSelection, allowsEmptyCollection, position, fixedPosition, open, onOpenChange, before, after, onChange, onCreate, afterShow, afterHide, onTextChange, ref, ...props }: Props) => import("react/jsx-runtime").JSX.Element) & {
17
+ declare const _default: (({ backgroundColor, menuBackground, children, fontSize, disabled, invalid, required, readOnly, loading, loadingResults, label, options, placeholder, placeholderColor, description, errorMessage, textOnly, value, defaultValue, width, height, maxHeight, iconLeft, leftElement, rightElement, allowRepeatSelection, allowsEmptyCollection, emptyFallback, position, fixedPosition, open, onOpenChange, before, after, onChange, onCreate, formatCreateOption, afterShow, afterHide, onTextChange, ref, ...props }: Props) => import("react/jsx-runtime").JSX.Element) & {
13
18
  Item: ({ id, value, header, body, leftElement, rightElement, inline, disabled, ...props }: import("..").SelectItem & Omit<import("react-aria-components").ListBoxItemProps<object>, "id" | "value" | "isDisabled">) => import("react/jsx-runtime").JSX.Element;
14
19
  Section: ({ id, title, children }: {
15
20
  id?: string;
16
21
  title?: string;
17
- children: import("react").ReactNode;
22
+ children: ReactNode;
18
23
  }) => import("react/jsx-runtime").JSX.Element;
19
24
  };
20
25
  export default _default;
@@ -19,7 +19,7 @@ import ListRootStyles, { preventProps } from "./ListHelpers/ListRootStyles.js";
19
19
  import ListSection from "./ListHelpers/ListSection.js";
20
20
  import MotionPopover from "./MotionPopover.js";
21
21
  import Spinner from "./Spinner.js";
22
- const ComboBox_ComboBox = ({ backgroundColor, menuBackground, children, fontSize, disabled, invalid, required, readOnly, loading, loadingResults, label, options, placeholder = 'Select', placeholderColor, description, errorMessage, textOnly, value, defaultValue, width, height, maxHeight, iconLeft, leftElement, rightElement, allowRepeatSelection, allowsEmptyCollection, position, fixedPosition, open, onOpenChange, before, after, onChange, onCreate, afterShow, afterHide, onTextChange, ref, ...props })=>{
22
+ const ComboBox_ComboBox = ({ backgroundColor, menuBackground, children, fontSize, disabled, invalid, required, readOnly, loading, loadingResults, label, options, placeholder = 'Select', placeholderColor, description, errorMessage, textOnly, value, defaultValue, width, height, maxHeight, iconLeft, leftElement, rightElement, allowRepeatSelection, allowsEmptyCollection, emptyFallback, position, fixedPosition, open, onOpenChange, before, after, onChange, onCreate, formatCreateOption, afterShow, afterHide, onTextChange, ref, ...props })=>{
23
23
  const [isOpen, handleOpenChange] = useControlledOpenState({
24
24
  open,
25
25
  onOpenChange,
@@ -46,11 +46,13 @@ const ComboBox_ComboBox = ({ backgroundColor, menuBackground, children, fontSize
46
46
  marginRight,
47
47
  marginLeft
48
48
  };
49
+ const flatOptions = flattenListOptions(options || []);
49
50
  const handleSelect = (val)=>{
50
51
  if (!val || !allowRepeatSelection && val === currentValue) return;
51
52
  if (!isControlled) {
53
+ const option = flatOptions.find((o)=>o.id === val || o.value === val);
52
54
  setInternalValue(val);
53
- setInputText(val.toString());
55
+ setInputText(option?.value ?? val.toString());
54
56
  }
55
57
  if (onChange) onChange(val);
56
58
  };
@@ -60,8 +62,7 @@ const ComboBox_ComboBox = ({ backgroundColor, menuBackground, children, fontSize
60
62
  };
61
63
  const hasValue = !!(currentValue || defaultValue || inputText);
62
64
  const hidePlaceholder = !!(!hasValue && label);
63
- const flatOptions = flattenListOptions(options || []);
64
- const showCreateOption = inputText.length > 0 && onCreate && !flatOptions.some((option)=>option.value === inputText);
65
+ const showCreateOption = inputText.length > 0 && onCreate && !flatOptions.some((option)=>option.value === inputText || option.id === inputText);
65
66
  const handleCreateOption = ()=>{
66
67
  if (!onCreate) return;
67
68
  pendingSelectionRef.current = inputText;
@@ -79,7 +80,11 @@ const ComboBox_ComboBox = ({ backgroundColor, menuBackground, children, fontSize
79
80
  }, [
80
81
  options
81
82
  ]);
83
+ const emptyContent = 'string' == typeof emptyFallback ? /*#__PURE__*/ jsx(EmptyState, {
84
+ children: emptyFallback
85
+ }) : emptyFallback;
82
86
  return /*#__PURE__*/ jsxs(ComboRoot, {
87
+ inputValue: inputText,
83
88
  onOpenChange: handleOpenChange,
84
89
  menuTrigger: "focus",
85
90
  onInputChange: handleInputChange,
@@ -93,7 +98,7 @@ const ComboBox_ComboBox = ({ backgroundColor, menuBackground, children, fontSize
93
98
  defaultSelectedKey: defaultValue,
94
99
  textOnly: textOnly,
95
100
  width: width,
96
- allowsEmptyCollection: allowsEmptyCollection || !!onCreate,
101
+ allowsEmptyCollection: allowsEmptyCollection || !!onCreate || !!emptyFallback,
97
102
  ...props,
98
103
  children: [
99
104
  /*#__PURE__*/ jsxs(ComboContainer, {
@@ -162,9 +167,11 @@ const ComboBox_ComboBox = ({ backgroundColor, menuBackground, children, fontSize
162
167
  before: before,
163
168
  after: after,
164
169
  menuBackground: menuBackground,
170
+ renderEmptyState: emptyContent ? ()=>emptyContent : void 0,
165
171
  createOptionItem: showCreateOption && /*#__PURE__*/ jsx(CreateItem, {
166
172
  onAction: handleCreateOption,
167
- children: `Create "${inputText}"`
173
+ textValue: inputText,
174
+ children: formatCreateOption ? formatCreateOption(inputText) : `Create "${inputText}"`
168
175
  }),
169
176
  children: children
170
177
  })
@@ -184,6 +191,11 @@ const CaretButton = styled(AriaButton)(({ theme, disabled, readOnly })=>({
184
191
  cursor: readOnly ? 'default' : void 0
185
192
  }));
186
193
  const CreateItem = styled(ListBoxItem, preventProps)(ListItemStyles);
194
+ const EmptyState = styled.div(({ theme })=>({
195
+ color: theme.scale6,
196
+ fontSize: theme.font.size.md,
197
+ paddingLeft: 16
198
+ }));
187
199
  const components_ComboBox = Object.assign(ComboBox_ComboBox, {
188
200
  Item,
189
201
  Section
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavv/ui",
3
- "version": "2.4.6-alpha.1",
3
+ "version": "2.4.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {