@etsoo/materialui 1.1.51 → 1.1.53

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,26 @@
1
+ /// <reference types="react" />
2
+ import { DataTypes } from "@etsoo/shared";
3
+ import { TypographyProps } from "@mui/material/Typography";
4
+ import { InputFieldProps } from "./InputField";
5
+ type ItemType = DataTypes.IdLabelItem<string | number>;
6
+ /**
7
+ * InputField with tips properties
8
+ */
9
+ export type InputTipFieldProps = InputFieldProps & {
10
+ /**
11
+ * Load data
12
+ * @param value Duplicate test value
13
+ */
14
+ loadData(value: string): Promise<[ItemType[]?, string?]>;
15
+ /**
16
+ * Label props
17
+ */
18
+ labelProps?: Omit<TypographyProps, "onClick">;
19
+ };
20
+ /**
21
+ * InputField with tips
22
+ * @param props Props
23
+ * @returns Component
24
+ */
25
+ export declare function InputTipField(props: InputTipFieldProps): JSX.Element;
26
+ export {};
@@ -0,0 +1,46 @@
1
+ import { InputAdornment, List, ListItem, Popover } from "@mui/material";
2
+ import Typography from "@mui/material/Typography";
3
+ import React from "react";
4
+ import { globalApp } from "./app/ReactApp";
5
+ import { InputField } from "./InputField";
6
+ /**
7
+ * InputField with tips
8
+ * @param props Props
9
+ * @returns Component
10
+ */
11
+ export function InputTipField(props) {
12
+ // State
13
+ const [title, setTitle] = React.useState();
14
+ const [anchorEl, setAnchorEl] = React.useState();
15
+ const [data, setData] = React.useState();
16
+ // Destruct
17
+ const { labelProps = {
18
+ title: globalApp === null || globalApp === void 0 ? void 0 : globalApp.get("clickForDetails"),
19
+ sx: { color: (theme) => theme.palette.error.main, cursor: "pointer" }
20
+ }, InputProps = {
21
+ endAdornment: title ? (React.createElement(InputAdornment, { position: "end" },
22
+ React.createElement(Typography, { onClick: (event) => {
23
+ setAnchorEl(event.currentTarget);
24
+ }, ...labelProps }, title))) : undefined
25
+ }, changeDelay = 480, onChangeDelay, loadData, ...rest } = props;
26
+ const load = (value) => {
27
+ if (value.length < 2) {
28
+ setTitle(undefined);
29
+ return;
30
+ }
31
+ loadData(value).then(([data, title]) => {
32
+ setData(data);
33
+ setTitle(title);
34
+ });
35
+ };
36
+ return (React.createElement(React.Fragment, null,
37
+ React.createElement(Popover, { open: anchorEl != null, anchorEl: anchorEl, onClose: () => setAnchorEl(undefined), anchorOrigin: {
38
+ vertical: "bottom",
39
+ horizontal: "left"
40
+ } }, data && (React.createElement(List, null, data.map((item) => (React.createElement(ListItem, { key: item.id }, item.label)))))),
41
+ React.createElement(InputField, { changeDelay: changeDelay, onChangeDelay: (event) => {
42
+ load(event.target.value);
43
+ if (onChangeDelay)
44
+ onChangeDelay(event);
45
+ }, InputProps: InputProps, ...rest })));
46
+ }
package/lib/TagList.js CHANGED
@@ -15,14 +15,16 @@ export function TagList(props) {
15
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
- const loading = open && options.length === 0;
18
+ const [loading, setLoading] = React.useState(false);
19
19
  const loadDataLocal = async (keyword) => {
20
20
  var _a;
21
+ setLoading(true);
21
22
  const result = (_a = (await loadData(keyword, maxItems))) !== null && _a !== void 0 ? _a : [];
22
23
  if (result.length >= maxItems) {
23
24
  result.push(moreLabel);
24
25
  }
25
26
  setOptions(result);
27
+ setLoading(false);
26
28
  };
27
29
  return (React.createElement(Autocomplete, { multiple: true, freeSolo: true, filterOptions: (options, _state) => options, open: open, onOpen: () => {
28
30
  setOpen(true);
package/lib/index.d.ts CHANGED
@@ -52,6 +52,7 @@ export * from "./HiSelector";
52
52
  export * from "./HiSelectorTL";
53
53
  export * from "./IconButtonLink";
54
54
  export * from "./InputField";
55
+ export * from "./InputTipField";
55
56
  export * from "./IntInputField";
56
57
  export * from "./ItemList";
57
58
  export * from "./ListChooser";
package/lib/index.js CHANGED
@@ -52,6 +52,7 @@ export * from "./HiSelector";
52
52
  export * from "./HiSelectorTL";
53
53
  export * from "./IconButtonLink";
54
54
  export * from "./InputField";
55
+ export * from "./InputTipField";
55
56
  export * from "./IntInputField";
56
57
  export * from "./ItemList";
57
58
  export * from "./ListChooser";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.51",
3
+ "version": "1.1.53",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,12 +50,12 @@
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.78",
53
+ "@etsoo/appscript": "^1.3.80",
54
54
  "@etsoo/notificationbase": "^1.1.24",
55
55
  "@etsoo/react": "^1.6.51",
56
56
  "@etsoo/shared": "^1.1.92",
57
57
  "@mui/icons-material": "^5.11.11",
58
- "@mui/material": "^5.11.13",
58
+ "@mui/material": "^5.11.14",
59
59
  "@mui/x-data-grid": "^6.0.2",
60
60
  "@types/pica": "^9.0.1",
61
61
  "@types/pulltorefreshjs": "^0.1.5",
@@ -85,8 +85,8 @@
85
85
  "@testing-library/jest-dom": "^5.16.5",
86
86
  "@testing-library/react": "^14.0.0",
87
87
  "@types/jest": "^29.5.0",
88
- "@typescript-eslint/eslint-plugin": "^5.55.0",
89
- "@typescript-eslint/parser": "^5.55.0",
88
+ "@typescript-eslint/eslint-plugin": "^5.56.0",
89
+ "@typescript-eslint/parser": "^5.56.0",
90
90
  "jest": "^29.5.0",
91
91
  "jest-environment-jsdom": "^29.5.0",
92
92
  "typescript": "^4.9.5"
@@ -0,0 +1,105 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import { InputAdornment, List, ListItem, Popover } from "@mui/material";
3
+ import Typography, { TypographyProps } from "@mui/material/Typography";
4
+ import React from "react";
5
+ import { globalApp } from "./app/ReactApp";
6
+ import { InputField, InputFieldProps } from "./InputField";
7
+
8
+ type ItemType = DataTypes.IdLabelItem<string | number>;
9
+
10
+ /**
11
+ * InputField with tips properties
12
+ */
13
+ export type InputTipFieldProps = InputFieldProps & {
14
+ /**
15
+ * Load data
16
+ * @param value Duplicate test value
17
+ */
18
+ loadData(value: string): Promise<[ItemType[]?, string?]>;
19
+
20
+ /**
21
+ * Label props
22
+ */
23
+ labelProps?: Omit<TypographyProps, "onClick">;
24
+ };
25
+
26
+ /**
27
+ * InputField with tips
28
+ * @param props Props
29
+ * @returns Component
30
+ */
31
+ export function InputTipField(props: InputTipFieldProps) {
32
+ // State
33
+ const [title, setTitle] = React.useState<string>();
34
+ const [anchorEl, setAnchorEl] = React.useState<HTMLElement>();
35
+ const [data, setData] = React.useState<ItemType[]>();
36
+
37
+ // Destruct
38
+ const {
39
+ labelProps = {
40
+ title: globalApp?.get("clickForDetails"),
41
+ sx: { color: (theme) => theme.palette.error.main, cursor: "pointer" }
42
+ },
43
+ InputProps = {
44
+ endAdornment: title ? (
45
+ <InputAdornment position="end">
46
+ <Typography
47
+ onClick={(event) => {
48
+ setAnchorEl(event.currentTarget);
49
+ }}
50
+ {...labelProps}
51
+ >
52
+ {title}
53
+ </Typography>
54
+ </InputAdornment>
55
+ ) : undefined
56
+ },
57
+ changeDelay = 480,
58
+ onChangeDelay,
59
+ loadData,
60
+ ...rest
61
+ } = props;
62
+
63
+ const load = (value: string) => {
64
+ if (value.length < 2) {
65
+ setTitle(undefined);
66
+ return;
67
+ }
68
+
69
+ loadData(value).then(([data, title]) => {
70
+ setData(data);
71
+ setTitle(title);
72
+ });
73
+ };
74
+
75
+ return (
76
+ <React.Fragment>
77
+ <Popover
78
+ open={anchorEl != null}
79
+ anchorEl={anchorEl}
80
+ onClose={() => setAnchorEl(undefined)}
81
+ anchorOrigin={{
82
+ vertical: "bottom",
83
+ horizontal: "left"
84
+ }}
85
+ >
86
+ {data && (
87
+ <List>
88
+ {data.map((item) => (
89
+ <ListItem key={item.id}>{item.label}</ListItem>
90
+ ))}
91
+ </List>
92
+ )}
93
+ </Popover>
94
+ <InputField
95
+ changeDelay={changeDelay}
96
+ onChangeDelay={(event) => {
97
+ load(event.target.value);
98
+ if (onChangeDelay) onChangeDelay(event);
99
+ }}
100
+ InputProps={InputProps}
101
+ {...rest}
102
+ />
103
+ </React.Fragment>
104
+ );
105
+ }
package/src/TagList.tsx CHANGED
@@ -75,14 +75,16 @@ export function TagList(props: TagListProps) {
75
75
 
76
76
  const [open, setOpen] = React.useState(false);
77
77
  const [options, setOptions] = React.useState<readonly string[]>([]);
78
- const loading = open && options.length === 0;
78
+ const [loading, setLoading] = React.useState(false);
79
79
 
80
80
  const loadDataLocal = async (keyword?: string) => {
81
+ setLoading(true);
81
82
  const result = (await loadData(keyword, maxItems)) ?? [];
82
83
  if (result.length >= maxItems) {
83
84
  result.push(moreLabel);
84
85
  }
85
86
  setOptions(result);
87
+ setLoading(false);
86
88
  };
87
89
 
88
90
  return (
package/src/index.ts CHANGED
@@ -55,6 +55,7 @@ export * from "./HiSelector";
55
55
  export * from "./HiSelectorTL";
56
56
  export * from "./IconButtonLink";
57
57
  export * from "./InputField";
58
+ export * from "./InputTipField";
58
59
  export * from "./IntInputField";
59
60
  export * from "./ItemList";
60
61
  export * from "./ListChooser";