@availity/mui-autocomplete 0.9.0 → 0.9.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.9.2](https://github.com/Availity/element/compare/@availity/mui-autocomplete@0.9.1...@availity/mui-autocomplete@0.9.2) (2024-11-20)
6
+
7
+ ## [0.9.1](https://github.com/Availity/element/compare/@availity/mui-autocomplete@0.9.0...@availity/mui-autocomplete@0.9.1) (2024-11-20)
8
+
9
+ ### Dependency Updates
10
+
11
+ * `mui-form-utils` updated to version `0.9.0`
12
+ * `mui-textfield` updated to version `0.9.0`
5
13
  ## [0.9.0](https://github.com/Availity/element/compare/@availity/mui-autocomplete@0.8.6...@availity/mui-autocomplete@0.9.0) (2024-10-31)
6
14
 
7
15
  ### Dependency Updates
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { AutocompleteProps as AutocompleteProps$1 } from '@mui/material/Autocomplete';
3
+ export { createFilterOptions } from '@mui/material/Autocomplete';
3
4
  import { ChipTypeMap } from '@mui/material/Chip';
4
5
  import { TextFieldProps } from '@availity/mui-textfield';
5
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { AutocompleteProps as AutocompleteProps$1 } from '@mui/material/Autocomplete';
3
+ export { createFilterOptions } from '@mui/material/Autocomplete';
3
4
  import { ChipTypeMap } from '@mui/material/Chip';
4
5
  import { TextFieldProps } from '@availity/mui-textfield';
5
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
package/dist/index.js CHANGED
@@ -82,7 +82,8 @@ __export(src_exports, {
82
82
  AsyncAutocomplete: () => AsyncAutocomplete,
83
83
  Autocomplete: () => Autocomplete,
84
84
  OrganizationAutocomplete: () => OrganizationAutocomplete,
85
- ProviderAutocomplete: () => ProviderAutocomplete
85
+ ProviderAutocomplete: () => ProviderAutocomplete,
86
+ createFilterOptions: () => import_Autocomplete2.createFilterOptions
86
87
  });
87
88
  module.exports = __toCommonJS(src_exports);
88
89
 
@@ -93,6 +94,7 @@ var import_CircularProgress = __toESM(require("@mui/material/CircularProgress"))
93
94
  var import_IconButton = __toESM(require("@mui/material/IconButton"));
94
95
  var import_mui_textfield = require("@availity/mui-textfield");
95
96
  var import_mui_form_utils = require("@availity/mui-form-utils");
97
+ var import_Autocomplete2 = require("@mui/material/Autocomplete");
96
98
  var import_jsx_runtime = require("react/jsx-runtime");
97
99
  var PopupIndicatorWrapper = (0, import_react.forwardRef)((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
98
100
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_form_utils.SelectDivider, { orientation: "vertical", className: "MuiSelect-avEndAdornmentDivider" }),
@@ -295,5 +297,6 @@ var ProviderAutocomplete = (_a) => {
295
297
  AsyncAutocomplete,
296
298
  Autocomplete,
297
299
  OrganizationAutocomplete,
298
- ProviderAutocomplete
300
+ ProviderAutocomplete,
301
+ createFilterOptions
299
302
  });
package/dist/index.mjs CHANGED
@@ -59,6 +59,7 @@ import CircularProgress from "@mui/material/CircularProgress";
59
59
  import { default as MuiIconButton } from "@mui/material/IconButton";
60
60
  import { TextField } from "@availity/mui-textfield";
61
61
  import { SelectDivider, SelectExpandIcon } from "@availity/mui-form-utils";
62
+ import { createFilterOptions } from "@mui/material/Autocomplete";
62
63
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
63
64
  var PopupIndicatorWrapper = forwardRef((props, ref) => /* @__PURE__ */ jsxs(Fragment, { children: [
64
65
  /* @__PURE__ */ jsx(SelectDivider, { orientation: "vertical", className: "MuiSelect-avEndAdornmentDivider" }),
@@ -260,5 +261,6 @@ export {
260
261
  AsyncAutocomplete,
261
262
  Autocomplete,
262
263
  OrganizationAutocomplete,
263
- ProviderAutocomplete
264
+ ProviderAutocomplete,
265
+ createFilterOptions
264
266
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/mui-autocomplete",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Availity MUI Autocomplete Component - part of the @availity/element design system",
5
5
  "keywords": [
6
6
  "react",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@availity/api-axios": "^9.0.4",
40
- "@availity/mui-form-utils": "^0.14.0",
41
- "@availity/mui-textfield": "^0.6.11",
40
+ "@availity/mui-form-utils": "^0.15.0",
41
+ "@availity/mui-textfield": "^0.6.12",
42
42
  "@mui/material": "^5.15.15",
43
43
  "@tanstack/react-query": "^4.36.1",
44
44
  "react": "18.2.0",
@@ -48,8 +48,8 @@
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@availity/api-axios": "^8.0.7",
51
- "@availity/mui-form-utils": "^0.14.0",
52
- "@availity/mui-textfield": "^0.6.11",
51
+ "@availity/mui-form-utils": "^0.15.0",
52
+ "@availity/mui-textfield": "^0.6.12",
53
53
  "@mui/material": "^5.11.9",
54
54
  "@tanstack/react-query": "^4.36.1",
55
55
  "react": ">=16.3.0"
@@ -1,6 +1,30 @@
1
1
  // Each exported component in the package should have its own stories file
2
+ import { useState } from 'react';
2
3
  import type { Meta, StoryObj } from '@storybook/react';
3
- import { Autocomplete } from './Autocomplete';
4
+ import { Autocomplete, createFilterOptions } from './Autocomplete';
5
+ import { FilterOptionsState } from '@mui/material';
6
+
7
+ const languages = [
8
+ 'Python',
9
+ 'JavaScript',
10
+ 'C#',
11
+ 'Java',
12
+ 'Go',
13
+ 'SQL',
14
+ 'PHP',
15
+ 'Swift',
16
+ 'Ruby',
17
+ 'R',
18
+ 'Rust',
19
+ 'TypeScript',
20
+ 'C++',
21
+ 'MATLAB',
22
+ 'Objective-C',
23
+ 'CSS',
24
+ 'HTML',
25
+ 'Kotlin',
26
+ 'Perl',
27
+ ];
4
28
 
5
29
  const meta: Meta<typeof Autocomplete> = {
6
30
  title: 'Form Components/Autocomplete/Autocomplete',
@@ -42,3 +66,105 @@ export const _Multi: StoryObj<typeof Autocomplete> = {
42
66
  multiple: true,
43
67
  },
44
68
  };
69
+
70
+ type Option = { inputValue?: string; title: string };
71
+
72
+ const filter = createFilterOptions<Option>();
73
+
74
+ export const _FreeSolo: StoryObj<typeof Autocomplete> = {
75
+ render: () => {
76
+ const [value, setValue] = useState<Option | null>(null);
77
+
78
+ const options: Option[] = [
79
+ { inputValue: 'option1', title: 'Option 1' },
80
+ { inputValue: 'option2', title: 'Option 2' },
81
+ ];
82
+
83
+ const onChange = (_event: any, newValue: Option) => {
84
+ if (typeof newValue === 'string') {
85
+ setValue({
86
+ title: newValue,
87
+ });
88
+ } else if (newValue && newValue.inputValue) {
89
+ // Create a new value from the user input
90
+ setValue({
91
+ title: newValue.inputValue,
92
+ });
93
+ } else {
94
+ setValue(newValue);
95
+ }
96
+ };
97
+
98
+ const getOptionLabel = (option: Option) => {
99
+ // Value selected with enter, right from the input
100
+ if (typeof option === 'string') {
101
+ return option;
102
+ }
103
+ // Add "xxx" option created dynamically
104
+ if (option.inputValue) {
105
+ return option.inputValue;
106
+ }
107
+ // Regular option
108
+ return option.title;
109
+ };
110
+
111
+ const filterOptions = (options: Option[], params: FilterOptionsState<Option>) => {
112
+ const filtered = filter(options, params);
113
+
114
+ const { inputValue } = params;
115
+ // Suggest the creation of a new value
116
+ const isExisting = options.some((option) => inputValue === option.title);
117
+ if (inputValue !== '' && !isExisting) {
118
+ filtered.push({
119
+ inputValue,
120
+ title: `Add "${inputValue}"`,
121
+ });
122
+ }
123
+
124
+ return filtered;
125
+ };
126
+
127
+ const renderOption = (props: React.HTMLAttributes<HTMLLIElement>, option: Option) => {
128
+ const { key, ...optionProps } = props;
129
+ return (
130
+ <li key={key} {...optionProps}>
131
+ {option.title}
132
+ </li>
133
+ );
134
+ };
135
+
136
+ return (
137
+ <Autocomplete
138
+ freeSolo
139
+ value={value}
140
+ options={options}
141
+ getOptionLabel={getOptionLabel}
142
+ onChange={onChange}
143
+ FieldProps={{ label: 'FreeSolo Select', helperText: 'Helper Text', fullWidth: false }}
144
+ filterOptions={filterOptions}
145
+ renderOption={renderOption}
146
+ />
147
+ );
148
+ },
149
+ };
150
+
151
+ export const _Grouped: StoryObj<typeof Autocomplete> = {
152
+ render: () => {
153
+ const options = languages.map((option) => {
154
+ const firstLetter = option[0].toUpperCase();
155
+
156
+ return {
157
+ firstLetter,
158
+ title: option,
159
+ };
160
+ });
161
+ return (
162
+ <Autocomplete
163
+ options={options.sort((a, b) => -b.firstLetter.localeCompare(a.firstLetter))}
164
+ groupBy={(option) => option.firstLetter}
165
+ getOptionLabel={(option) => option.title}
166
+ FieldProps={{ label: 'FreeSolo Select', helperText: 'Helper Text', fullWidth: false }}
167
+ />
168
+ );
169
+ },
170
+ };
@@ -12,6 +12,8 @@ import { OverridableStringUnion } from '@mui/types';
12
12
  import { TextField, TextFieldProps } from '@availity/mui-textfield';
13
13
  import { SelectDivider, SelectExpandIcon } from '@availity/mui-form-utils';
14
14
 
15
+ export { createFilterOptions } from '@mui/material/Autocomplete';
16
+
15
17
  export interface AutocompleteProps<
16
18
  T,
17
19
  Multiple extends boolean | undefined,