@etsoo/materialui 1.1.48 → 1.1.50
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 +22 -0
- package/lib/TagList.js +39 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +5 -5
- package/src/TagList.tsx +124 -0
- package/src/index.ts +1 -0
package/lib/TagList.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AutocompleteProps } from "@mui/material";
|
|
3
|
+
import { InputFieldProps } from "./InputField";
|
|
4
|
+
export type TagListProps = Omit<AutocompleteProps<string, true, false, true>, "open" | "multiple" | "freeSolo" | "options" | "renderInput"> & {
|
|
5
|
+
/**
|
|
6
|
+
* Label
|
|
7
|
+
*/
|
|
8
|
+
label?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Load data callback
|
|
11
|
+
*/
|
|
12
|
+
loadData: (keyword: string | undefined, maxItems: number) => PromiseLike<string[] | null | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Input props
|
|
15
|
+
*/
|
|
16
|
+
inputProps?: Omit<InputFieldProps, "onChange">;
|
|
17
|
+
/**
|
|
18
|
+
* Max items
|
|
19
|
+
*/
|
|
20
|
+
maxItems?: number;
|
|
21
|
+
};
|
|
22
|
+
export declare function TagList(props: TagListProps): JSX.Element;
|
package/lib/TagList.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Autocomplete, Checkbox, Chip } from "@mui/material";
|
|
2
|
+
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
|
|
3
|
+
import CheckBoxIcon from "@mui/icons-material/CheckBox";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { InputField } from "./InputField";
|
|
6
|
+
import { globalApp } from "./app/ReactApp";
|
|
7
|
+
export function TagList(props) {
|
|
8
|
+
var _a;
|
|
9
|
+
// Labels
|
|
10
|
+
const { noOptions, loading: loadingLabel, more = "More", open: openDefault } = (_a = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("noOptions", "loading", "more", "open")) !== null && _a !== void 0 ? _a : {};
|
|
11
|
+
const moreLabel = more + "...";
|
|
12
|
+
// Destruct
|
|
13
|
+
const { renderOption = (props, option, { selected }) => (React.createElement("li", { ...props },
|
|
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, label, inputProps, ...rest } = props;
|
|
16
|
+
const [open, setOpen] = React.useState(false);
|
|
17
|
+
const [options, setOptions] = React.useState([]);
|
|
18
|
+
const loading = open && options.length === 0;
|
|
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, open: open, onOpen: () => {
|
|
28
|
+
setOpen(true);
|
|
29
|
+
if (options.length === 0) {
|
|
30
|
+
loadDataLocal();
|
|
31
|
+
}
|
|
32
|
+
}, onClose: () => {
|
|
33
|
+
setOpen(false);
|
|
34
|
+
}, options: options, loading: loading, renderOption: renderOption, renderTags: renderTags, renderInput: (params) => (React.createElement(InputField, { label: label, changeDelay: 480, onChange: async (event) => {
|
|
35
|
+
await loadDataLocal(event.target.value);
|
|
36
|
+
}, ...inputProps, ...params })), getOptionDisabled: (item) => {
|
|
37
|
+
return item === moreLabel;
|
|
38
|
+
}, noOptionsText: noOptionsText, loadingText: loadingText, openText: openText, ...rest }));
|
|
39
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.50",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"@emotion/css": "^11.10.6",
|
|
51
51
|
"@emotion/react": "^11.10.6",
|
|
52
52
|
"@emotion/styled": "^11.10.6",
|
|
53
|
-
"@etsoo/appscript": "^1.3.
|
|
53
|
+
"@etsoo/appscript": "^1.3.78",
|
|
54
54
|
"@etsoo/notificationbase": "^1.1.24",
|
|
55
55
|
"@etsoo/react": "^1.6.51",
|
|
56
|
-
"@etsoo/shared": "^1.1.
|
|
56
|
+
"@etsoo/shared": "^1.1.92",
|
|
57
57
|
"@mui/icons-material": "^5.11.11",
|
|
58
58
|
"@mui/material": "^5.11.13",
|
|
59
|
-
"@mui/x-data-grid": "^6.0.
|
|
59
|
+
"@mui/x-data-grid": "^6.0.2",
|
|
60
60
|
"@types/pica": "^9.0.1",
|
|
61
61
|
"@types/pulltorefreshjs": "^0.1.5",
|
|
62
62
|
"@types/react": "^18.0.28",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"@babel/runtime-corejs3": "^7.21.0",
|
|
85
85
|
"@testing-library/jest-dom": "^5.16.5",
|
|
86
86
|
"@testing-library/react": "^14.0.0",
|
|
87
|
-
"@types/jest": "^29.
|
|
87
|
+
"@types/jest": "^29.5.0",
|
|
88
88
|
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
89
89
|
"@typescript-eslint/parser": "^5.55.0",
|
|
90
90
|
"jest": "^29.5.0",
|
package/src/TagList.tsx
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Autocomplete, AutocompleteProps, Checkbox, Chip } from "@mui/material";
|
|
2
|
+
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
|
|
3
|
+
import CheckBoxIcon from "@mui/icons-material/CheckBox";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { InputField, InputFieldProps } from "./InputField";
|
|
6
|
+
import { globalApp } from "./app/ReactApp";
|
|
7
|
+
|
|
8
|
+
export type TagListProps = Omit<
|
|
9
|
+
AutocompleteProps<string, true, false, true>,
|
|
10
|
+
"open" | "multiple" | "freeSolo" | "options" | "renderInput"
|
|
11
|
+
> & {
|
|
12
|
+
/**
|
|
13
|
+
* Label
|
|
14
|
+
*/
|
|
15
|
+
label?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Load data callback
|
|
19
|
+
*/
|
|
20
|
+
loadData: (
|
|
21
|
+
keyword: string | undefined,
|
|
22
|
+
maxItems: number
|
|
23
|
+
) => PromiseLike<string[] | null | undefined>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Input props
|
|
27
|
+
*/
|
|
28
|
+
inputProps?: Omit<InputFieldProps, "onChange">;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Max items
|
|
32
|
+
*/
|
|
33
|
+
maxItems?: number;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function TagList(props: TagListProps) {
|
|
37
|
+
// Labels
|
|
38
|
+
const {
|
|
39
|
+
noOptions,
|
|
40
|
+
loading: loadingLabel,
|
|
41
|
+
more = "More",
|
|
42
|
+
open: openDefault
|
|
43
|
+
} = globalApp?.getLabels("noOptions", "loading", "more", "open") ?? {};
|
|
44
|
+
|
|
45
|
+
const moreLabel = more + "...";
|
|
46
|
+
|
|
47
|
+
// Destruct
|
|
48
|
+
const {
|
|
49
|
+
renderOption = (props, option, { selected }) => (
|
|
50
|
+
<li {...props}>
|
|
51
|
+
<Checkbox
|
|
52
|
+
icon={<CheckBoxOutlineBlankIcon fontSize="small" />}
|
|
53
|
+
checkedIcon={<CheckBoxIcon fontSize="small" />}
|
|
54
|
+
style={{ marginRight: 8 }}
|
|
55
|
+
checked={selected}
|
|
56
|
+
/>
|
|
57
|
+
{option}
|
|
58
|
+
</li>
|
|
59
|
+
),
|
|
60
|
+
renderTags = (value: readonly string[], getTagProps) =>
|
|
61
|
+
value.map((option: string, index: number) => (
|
|
62
|
+
<Chip variant="outlined" label={option} {...getTagProps({ index })} />
|
|
63
|
+
)),
|
|
64
|
+
noOptionsText = noOptions,
|
|
65
|
+
loadingText = loadingLabel,
|
|
66
|
+
openText = openDefault,
|
|
67
|
+
loadData,
|
|
68
|
+
maxItems = 16,
|
|
69
|
+
label,
|
|
70
|
+
inputProps,
|
|
71
|
+
...rest
|
|
72
|
+
} = props;
|
|
73
|
+
|
|
74
|
+
const [open, setOpen] = React.useState(false);
|
|
75
|
+
const [options, setOptions] = React.useState<readonly string[]>([]);
|
|
76
|
+
const loading = open && options.length === 0;
|
|
77
|
+
|
|
78
|
+
const loadDataLocal = async (keyword?: string) => {
|
|
79
|
+
const result = (await loadData(keyword, maxItems)) ?? [];
|
|
80
|
+
if (result.length >= maxItems) {
|
|
81
|
+
result.push(moreLabel);
|
|
82
|
+
}
|
|
83
|
+
setOptions(result);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Autocomplete<string, true, false, true>
|
|
88
|
+
multiple
|
|
89
|
+
freeSolo
|
|
90
|
+
open={open}
|
|
91
|
+
onOpen={() => {
|
|
92
|
+
setOpen(true);
|
|
93
|
+
if (options.length === 0) {
|
|
94
|
+
loadDataLocal();
|
|
95
|
+
}
|
|
96
|
+
}}
|
|
97
|
+
onClose={() => {
|
|
98
|
+
setOpen(false);
|
|
99
|
+
}}
|
|
100
|
+
options={options}
|
|
101
|
+
loading={loading}
|
|
102
|
+
renderOption={renderOption}
|
|
103
|
+
renderTags={renderTags}
|
|
104
|
+
renderInput={(params) => (
|
|
105
|
+
<InputField
|
|
106
|
+
label={label}
|
|
107
|
+
changeDelay={480}
|
|
108
|
+
onChange={async (event) => {
|
|
109
|
+
await loadDataLocal(event.target.value);
|
|
110
|
+
}}
|
|
111
|
+
{...inputProps}
|
|
112
|
+
{...params}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
getOptionDisabled={(item) => {
|
|
116
|
+
return item === moreLabel;
|
|
117
|
+
}}
|
|
118
|
+
noOptionsText={noOptionsText}
|
|
119
|
+
loadingText={loadingText}
|
|
120
|
+
openText={openText}
|
|
121
|
+
{...rest}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
}
|
package/src/index.ts
CHANGED