@nethru/ui 2.1.56 → 2.1.58

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.
@@ -0,0 +1,77 @@
1
+ import { forwardRef, useCallback, useMemo, useState } from "react";
2
+ import { Autocomplete, createFilterOptions, FormControl, FormHelperText } from "@mui/material";
3
+ import { TextField } from "./index";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { jsxs as _jsxs } from "react/jsx-runtime";
6
+ const AddableSelect = /*#__PURE__*/forwardRef(({
7
+ label,
8
+ placeholder = '새 값을 입력하거나 선택해주세요',
9
+ helperText,
10
+ value,
11
+ options,
12
+ onInputChange,
13
+ error,
14
+ fullWidth,
15
+ formControlProps,
16
+ ...props
17
+ }, ref) => {
18
+ const styles = useMemo(() => ({
19
+ mt: label ? '17px' : undefined,
20
+ ...formControlProps?.sx
21
+ }), [label, formControlProps]);
22
+ const [inputValue, setInputValue] = useState('');
23
+ const [open, setOpen] = useState(false);
24
+ const getOptionLabel = useCallback(option => typeof option === 'string' ? option : option.label ?? '', []);
25
+ const filter = useMemo(() => createFilterOptions({
26
+ stringify: getOptionLabel
27
+ }), [getOptionLabel]);
28
+ const filteredOptions = useMemo(() => {
29
+ return filter(options, {
30
+ inputValue,
31
+ getOptionLabel
32
+ });
33
+ }, [filter, options, inputValue, getOptionLabel]);
34
+ const handleInputChange = useCallback((event, newValue, reason) => {
35
+ if (onInputChange) onInputChange(event, newValue, reason);
36
+ setInputValue(newValue);
37
+ if (reason !== 'input') {
38
+ setOpen(false);
39
+ return;
40
+ }
41
+ const nextFiltered = filter(options, {
42
+ inputValue: newValue,
43
+ getOptionLabel
44
+ });
45
+ setOpen(nextFiltered.length > 0);
46
+ }, [filter, options, getOptionLabel, onInputChange]);
47
+ return /*#__PURE__*/_jsxs(FormControl, {
48
+ ref: ref,
49
+ disabled: props.disabled,
50
+ error: error,
51
+ sx: styles,
52
+ fullWidth: fullWidth,
53
+ ...formControlProps,
54
+ children: [/*#__PURE__*/_jsx(Autocomplete, {
55
+ freeSolo: true,
56
+ options: options,
57
+ value: value ?? '',
58
+ inputValue: inputValue,
59
+ open: open && filteredOptions.length > 0,
60
+ onOpen: () => {
61
+ if (filteredOptions.length > 0) setOpen(true);
62
+ },
63
+ onClose: () => setOpen(false),
64
+ onInputChange: handleInputChange,
65
+ filterOptions: (opts, state) => filter(opts, state),
66
+ renderInput: params => /*#__PURE__*/_jsx(TextField, {
67
+ ...params,
68
+ label: label,
69
+ placeholder: placeholder
70
+ }),
71
+ ...props
72
+ }), helperText && /*#__PURE__*/_jsx(FormHelperText, {
73
+ children: helperText
74
+ })]
75
+ });
76
+ });
77
+ export default AddableSelect;
package/base/index.js CHANGED
@@ -7,6 +7,7 @@ export { colors };
7
7
  export { borderRadius, shadow, globalStyles, createTheme };
8
8
  export { default as AccordionSummary } from "./AccordionSummary";
9
9
  export { default as AddableFormList } from "./AddableFormList";
10
+ export { default as AddableSelect } from "./AddableSelect";
10
11
  export { default as Alert } from "./Alert";
11
12
  export { default as AlertDialog } from "./dialog/AlertDialog";
12
13
  export { default as AppBar } from "./frame/AppBar";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nethru/ui",
3
- "version": "2.1.56",
3
+ "version": "2.1.58",
4
4
  "main": "base/index.js",
5
5
  "files": [
6
6
  "/base"