@etsoo/materialui 1.1.48 → 1.1.49

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,13 @@
1
+ /// <reference types="react" />
2
+ import { AutocompleteProps } from "@mui/material";
3
+ export type TagListProps = Omit<AutocompleteProps<string, true, false, true>, "open" | "multiple" | "freeSolo" | "options" | "renderInput"> & {
4
+ /**
5
+ * Load data callback
6
+ */
7
+ loadData: (keyword: string | undefined, maxItems: number) => PromiseLike<string[] | null | undefined>;
8
+ /**
9
+ * Max items
10
+ */
11
+ maxItems?: number;
12
+ };
13
+ export declare function TagList(props: TagListProps): JSX.Element;
package/lib/TagList.js ADDED
@@ -0,0 +1,33 @@
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, ...rest } = props;
16
+ const [open, setOpen] = React.useState(false);
17
+ const [options, setOptions] = React.useState([]);
18
+ const loading = open && options.length === 0;
19
+ return (React.createElement(Autocomplete, { multiple: true, freeSolo: true, open: open, onOpen: () => {
20
+ setOpen(true);
21
+ }, onClose: () => {
22
+ setOpen(false);
23
+ }, options: options, loading: loading, renderOption: renderOption, renderTags: renderTags, renderInput: (params) => (React.createElement(InputField, { changeDelay: 480, onChange: async (event) => {
24
+ var _a;
25
+ const result = (_a = (await loadData(event.target.value, maxItems))) !== null && _a !== void 0 ? _a : [];
26
+ if (result.length >= maxItems) {
27
+ result.push(moreLabel);
28
+ }
29
+ setOptions(result);
30
+ }, ...params })), getOptionDisabled: (item) => {
31
+ return item === moreLabel;
32
+ }, noOptionsText: noOptionsText, loadingText: loadingText, openText: openText, ...rest }));
33
+ }
package/lib/index.d.ts CHANGED
@@ -85,6 +85,7 @@ export * from "./TabBox";
85
85
  export * from "./TableEx";
86
86
  export * from "./TextFieldEx";
87
87
  export * from "./Tiplist";
88
+ export * from "./TagList";
88
89
  export * from "./TwoFieldInput";
89
90
  export * from "./TooltipClick";
90
91
  export * from "./UserAvatar";
package/lib/index.js CHANGED
@@ -85,6 +85,7 @@ export * from "./TabBox";
85
85
  export * from "./TableEx";
86
86
  export * from "./TextFieldEx";
87
87
  export * from "./Tiplist";
88
+ export * from "./TagList";
88
89
  export * from "./TwoFieldInput";
89
90
  export * from "./TooltipClick";
90
91
  export * from "./UserAvatar";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.48",
3
+ "version": "1.1.49",
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.76",
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.90",
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.1",
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.4.1",
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",
@@ -0,0 +1,103 @@
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 } 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
+ * Load data callback
14
+ */
15
+ loadData: (
16
+ keyword: string | undefined,
17
+ maxItems: number
18
+ ) => PromiseLike<string[] | null | undefined>;
19
+
20
+ /**
21
+ * Max items
22
+ */
23
+ maxItems?: number;
24
+ };
25
+
26
+ export function TagList(props: TagListProps) {
27
+ // Labels
28
+ const {
29
+ noOptions,
30
+ loading: loadingLabel,
31
+ more = "More",
32
+ open: openDefault
33
+ } = globalApp?.getLabels("noOptions", "loading", "more", "open") ?? {};
34
+
35
+ const moreLabel = more + "...";
36
+
37
+ // Destruct
38
+ const {
39
+ renderOption = (props, option, { selected }) => (
40
+ <li {...props}>
41
+ <Checkbox
42
+ icon={<CheckBoxOutlineBlankIcon fontSize="small" />}
43
+ checkedIcon={<CheckBoxIcon fontSize="small" />}
44
+ style={{ marginRight: 8 }}
45
+ checked={selected}
46
+ />
47
+ {option}
48
+ </li>
49
+ ),
50
+ renderTags = (value: readonly string[], getTagProps) =>
51
+ value.map((option: string, index: number) => (
52
+ <Chip variant="outlined" label={option} {...getTagProps({ index })} />
53
+ )),
54
+ noOptionsText = noOptions,
55
+ loadingText = loadingLabel,
56
+ openText = openDefault,
57
+ loadData,
58
+ maxItems = 16,
59
+ ...rest
60
+ } = props;
61
+
62
+ const [open, setOpen] = React.useState(false);
63
+ const [options, setOptions] = React.useState<readonly string[]>([]);
64
+ const loading = open && options.length === 0;
65
+
66
+ return (
67
+ <Autocomplete<string, true, false, true>
68
+ multiple
69
+ freeSolo
70
+ open={open}
71
+ onOpen={() => {
72
+ setOpen(true);
73
+ }}
74
+ onClose={() => {
75
+ setOpen(false);
76
+ }}
77
+ options={options}
78
+ loading={loading}
79
+ renderOption={renderOption}
80
+ renderTags={renderTags}
81
+ renderInput={(params) => (
82
+ <InputField
83
+ changeDelay={480}
84
+ onChange={async (event) => {
85
+ const result = (await loadData(event.target.value, maxItems)) ?? [];
86
+ if (result.length >= maxItems) {
87
+ result.push(moreLabel);
88
+ }
89
+ setOptions(result);
90
+ }}
91
+ {...params}
92
+ />
93
+ )}
94
+ getOptionDisabled={(item) => {
95
+ return item === moreLabel;
96
+ }}
97
+ noOptionsText={noOptionsText}
98
+ loadingText={loadingText}
99
+ openText={openText}
100
+ {...rest}
101
+ />
102
+ );
103
+ }
package/src/index.ts CHANGED
@@ -88,6 +88,7 @@ export * from "./TabBox";
88
88
  export * from "./TableEx";
89
89
  export * from "./TextFieldEx";
90
90
  export * from "./Tiplist";
91
+ export * from "./TagList";
91
92
  export * from "./TwoFieldInput";
92
93
  export * from "./TooltipClick";
93
94
  export * from "./UserAvatar";