@etsoo/materialui 1.1.49 → 1.1.51
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/lib/TagList.d.ts +9 -0
- package/lib/TagList.js +19 -10
- package/package.json +1 -1
- package/src/TagList.tsx +36 -6
package/lib/TagList.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { AutocompleteProps } from "@mui/material";
|
|
3
|
+
import { InputFieldProps } from "./InputField";
|
|
3
4
|
export type TagListProps = Omit<AutocompleteProps<string, true, false, true>, "open" | "multiple" | "freeSolo" | "options" | "renderInput"> & {
|
|
5
|
+
/**
|
|
6
|
+
* Label
|
|
7
|
+
*/
|
|
8
|
+
label?: string;
|
|
4
9
|
/**
|
|
5
10
|
* Load data callback
|
|
6
11
|
*/
|
|
7
12
|
loadData: (keyword: string | undefined, maxItems: number) => PromiseLike<string[] | null | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Input props
|
|
15
|
+
*/
|
|
16
|
+
inputProps?: Omit<InputFieldProps, "onChange">;
|
|
8
17
|
/**
|
|
9
18
|
* Max items
|
|
10
19
|
*/
|
package/lib/TagList.js
CHANGED
|
@@ -12,22 +12,31 @@ export function TagList(props) {
|
|
|
12
12
|
// Destruct
|
|
13
13
|
const { renderOption = (props, option, { selected }) => (React.createElement("li", { ...props },
|
|
14
14
|
React.createElement(Checkbox, { icon: React.createElement(CheckBoxOutlineBlankIcon, { fontSize: "small" }), checkedIcon: React.createElement(CheckBoxIcon, { fontSize: "small" }), style: { marginRight: 8 }, checked: selected }),
|
|
15
|
-
option)), renderTags = (value, getTagProps) => value.map((option, index) => (React.createElement(Chip, { variant: "outlined", label: option, ...getTagProps({ index }) }))), noOptionsText = noOptions, loadingText = loadingLabel, openText = openDefault, loadData, maxItems = 16, ...rest } = props;
|
|
15
|
+
option)), renderTags = (value, getTagProps) => value.map((option, index) => (React.createElement(Chip, { variant: "outlined", label: option, ...getTagProps({ index }) }))), noOptionsText = noOptions, loadingText = loadingLabel, openText = openDefault, loadData, maxItems = 16, disableCloseOnSelect = true, openOnFocus = true, label, inputProps, ...rest } = props;
|
|
16
16
|
const [open, setOpen] = React.useState(false);
|
|
17
17
|
const [options, setOptions] = React.useState([]);
|
|
18
18
|
const loading = open && options.length === 0;
|
|
19
|
-
|
|
19
|
+
const loadDataLocal = async (keyword) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const result = (_a = (await loadData(keyword, maxItems))) !== null && _a !== void 0 ? _a : [];
|
|
22
|
+
if (result.length >= maxItems) {
|
|
23
|
+
result.push(moreLabel);
|
|
24
|
+
}
|
|
25
|
+
setOptions(result);
|
|
26
|
+
};
|
|
27
|
+
return (React.createElement(Autocomplete, { multiple: true, freeSolo: true, filterOptions: (options, _state) => options, open: open, onOpen: () => {
|
|
20
28
|
setOpen(true);
|
|
29
|
+
if (options.length === 0) {
|
|
30
|
+
loadDataLocal();
|
|
31
|
+
}
|
|
21
32
|
}, onClose: () => {
|
|
22
33
|
setOpen(false);
|
|
23
|
-
}, options: options, loading: loading, renderOption: renderOption, renderTags: renderTags, renderInput: (params) => (React.createElement(InputField, { changeDelay: 480, onChange: async (event) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
setOptions(result);
|
|
30
|
-
}, ...params })), getOptionDisabled: (item) => {
|
|
34
|
+
}, options: options, loading: loading, disableCloseOnSelect: disableCloseOnSelect, openOnFocus: openOnFocus, renderOption: renderOption, renderTags: renderTags, renderInput: (params) => (React.createElement(InputField, { label: label, changeDelay: 480, onChange: async (event) => {
|
|
35
|
+
// Stop bubble
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
event.stopPropagation();
|
|
38
|
+
await loadDataLocal(event.target.value);
|
|
39
|
+
}, ...inputProps, ...params })), getOptionDisabled: (item) => {
|
|
31
40
|
return item === moreLabel;
|
|
32
41
|
}, noOptionsText: noOptionsText, loadingText: loadingText, openText: openText, ...rest }));
|
|
33
42
|
}
|
package/package.json
CHANGED
package/src/TagList.tsx
CHANGED
|
@@ -2,13 +2,18 @@ import { Autocomplete, AutocompleteProps, Checkbox, Chip } from "@mui/material";
|
|
|
2
2
|
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
|
|
3
3
|
import CheckBoxIcon from "@mui/icons-material/CheckBox";
|
|
4
4
|
import React from "react";
|
|
5
|
-
import { InputField } from "./InputField";
|
|
5
|
+
import { InputField, InputFieldProps } from "./InputField";
|
|
6
6
|
import { globalApp } from "./app/ReactApp";
|
|
7
7
|
|
|
8
8
|
export type TagListProps = Omit<
|
|
9
9
|
AutocompleteProps<string, true, false, true>,
|
|
10
10
|
"open" | "multiple" | "freeSolo" | "options" | "renderInput"
|
|
11
11
|
> & {
|
|
12
|
+
/**
|
|
13
|
+
* Label
|
|
14
|
+
*/
|
|
15
|
+
label?: string;
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* Load data callback
|
|
14
19
|
*/
|
|
@@ -17,6 +22,11 @@ export type TagListProps = Omit<
|
|
|
17
22
|
maxItems: number
|
|
18
23
|
) => PromiseLike<string[] | null | undefined>;
|
|
19
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Input props
|
|
27
|
+
*/
|
|
28
|
+
inputProps?: Omit<InputFieldProps, "onChange">;
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
31
|
* Max items
|
|
22
32
|
*/
|
|
@@ -56,6 +66,10 @@ export function TagList(props: TagListProps) {
|
|
|
56
66
|
openText = openDefault,
|
|
57
67
|
loadData,
|
|
58
68
|
maxItems = 16,
|
|
69
|
+
disableCloseOnSelect = true,
|
|
70
|
+
openOnFocus = true,
|
|
71
|
+
label,
|
|
72
|
+
inputProps,
|
|
59
73
|
...rest
|
|
60
74
|
} = props;
|
|
61
75
|
|
|
@@ -63,31 +77,47 @@ export function TagList(props: TagListProps) {
|
|
|
63
77
|
const [options, setOptions] = React.useState<readonly string[]>([]);
|
|
64
78
|
const loading = open && options.length === 0;
|
|
65
79
|
|
|
80
|
+
const loadDataLocal = async (keyword?: string) => {
|
|
81
|
+
const result = (await loadData(keyword, maxItems)) ?? [];
|
|
82
|
+
if (result.length >= maxItems) {
|
|
83
|
+
result.push(moreLabel);
|
|
84
|
+
}
|
|
85
|
+
setOptions(result);
|
|
86
|
+
};
|
|
87
|
+
|
|
66
88
|
return (
|
|
67
89
|
<Autocomplete<string, true, false, true>
|
|
68
90
|
multiple
|
|
69
91
|
freeSolo
|
|
92
|
+
filterOptions={(options, _state) => options}
|
|
70
93
|
open={open}
|
|
71
94
|
onOpen={() => {
|
|
72
95
|
setOpen(true);
|
|
96
|
+
if (options.length === 0) {
|
|
97
|
+
loadDataLocal();
|
|
98
|
+
}
|
|
73
99
|
}}
|
|
74
100
|
onClose={() => {
|
|
75
101
|
setOpen(false);
|
|
76
102
|
}}
|
|
77
103
|
options={options}
|
|
78
104
|
loading={loading}
|
|
105
|
+
disableCloseOnSelect={disableCloseOnSelect}
|
|
106
|
+
openOnFocus={openOnFocus}
|
|
79
107
|
renderOption={renderOption}
|
|
80
108
|
renderTags={renderTags}
|
|
81
109
|
renderInput={(params) => (
|
|
82
110
|
<InputField
|
|
111
|
+
label={label}
|
|
83
112
|
changeDelay={480}
|
|
84
113
|
onChange={async (event) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
// Stop bubble
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
event.stopPropagation();
|
|
117
|
+
|
|
118
|
+
await loadDataLocal(event.target.value);
|
|
90
119
|
}}
|
|
120
|
+
{...inputProps}
|
|
91
121
|
{...params}
|
|
92
122
|
/>
|
|
93
123
|
)}
|