@etsoo/materialui 1.1.49 → 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 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,28 @@ 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, 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
+ 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
+ };
19
27
  return (React.createElement(Autocomplete, { multiple: true, freeSolo: true, 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
- 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) => {
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) => {
31
37
  return item === moreLabel;
32
38
  }, noOptionsText: noOptionsText, loadingText: loadingText, openText: openText, ...rest }));
33
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.49",
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",
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,8 @@ export function TagList(props: TagListProps) {
56
66
  openText = openDefault,
57
67
  loadData,
58
68
  maxItems = 16,
69
+ label,
70
+ inputProps,
59
71
  ...rest
60
72
  } = props;
61
73
 
@@ -63,6 +75,14 @@ export function TagList(props: TagListProps) {
63
75
  const [options, setOptions] = React.useState<readonly string[]>([]);
64
76
  const loading = open && options.length === 0;
65
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
+
66
86
  return (
67
87
  <Autocomplete<string, true, false, true>
68
88
  multiple
@@ -70,6 +90,9 @@ export function TagList(props: TagListProps) {
70
90
  open={open}
71
91
  onOpen={() => {
72
92
  setOpen(true);
93
+ if (options.length === 0) {
94
+ loadDataLocal();
95
+ }
73
96
  }}
74
97
  onClose={() => {
75
98
  setOpen(false);
@@ -80,14 +103,12 @@ export function TagList(props: TagListProps) {
80
103
  renderTags={renderTags}
81
104
  renderInput={(params) => (
82
105
  <InputField
106
+ label={label}
83
107
  changeDelay={480}
84
108
  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);
109
+ await loadDataLocal(event.target.value);
90
110
  }}
111
+ {...inputProps}
91
112
  {...params}
92
113
  />
93
114
  )}