@etsoo/materialui 1.1.52 → 1.1.54
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/InputTipField.d.ts +38 -0
- package/lib/InputTipField.js +46 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +5 -5
- package/src/InputTipField.tsx +118 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DataTypes } from "@etsoo/shared";
|
|
2
|
+
import { TypographyProps } from "@mui/material/Typography";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { InputFieldProps } from "./InputField";
|
|
5
|
+
type ItemType = DataTypes.IdLabelItem<string | number>;
|
|
6
|
+
/**
|
|
7
|
+
* InputField with tips properties
|
|
8
|
+
*/
|
|
9
|
+
export type InputTipFieldProps<T extends ItemType = ItemType> = InputFieldProps & {
|
|
10
|
+
/**
|
|
11
|
+
* Load data
|
|
12
|
+
* @param value Duplicate test value
|
|
13
|
+
*/
|
|
14
|
+
loadData(value: string): Promise<[T[]?, string?]>;
|
|
15
|
+
/**
|
|
16
|
+
* Label props
|
|
17
|
+
*/
|
|
18
|
+
labelProps?: Omit<TypographyProps, "onClick">;
|
|
19
|
+
/**
|
|
20
|
+
* Custom item label
|
|
21
|
+
* @param item List item data
|
|
22
|
+
* @returns Result
|
|
23
|
+
*/
|
|
24
|
+
itemLabel?: (item: T) => React.ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Custom render item
|
|
27
|
+
* @param item List item data
|
|
28
|
+
* @returns Result
|
|
29
|
+
*/
|
|
30
|
+
renderItem?: (item: T) => React.ReactNode;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* InputField with tips
|
|
34
|
+
* @param props Props
|
|
35
|
+
* @returns Component
|
|
36
|
+
*/
|
|
37
|
+
export declare function InputTipField<T extends ItemType = ItemType>(props: InputTipFieldProps<T>): JSX.Element;
|
|
38
|
+
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, itemLabel = (item) => item.label, renderItem = (item) => React.createElement(ListItem, { key: item.id }, itemLabel(item)), ...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) => renderItem(item)))),
|
|
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/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.
|
|
3
|
+
"version": "1.1.54",
|
|
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.
|
|
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.
|
|
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.
|
|
89
|
-
"@typescript-eslint/parser": "^5.
|
|
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,118 @@
|
|
|
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<T extends ItemType = ItemType> =
|
|
14
|
+
InputFieldProps & {
|
|
15
|
+
/**
|
|
16
|
+
* Load data
|
|
17
|
+
* @param value Duplicate test value
|
|
18
|
+
*/
|
|
19
|
+
loadData(value: string): Promise<[T[]?, string?]>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Label props
|
|
23
|
+
*/
|
|
24
|
+
labelProps?: Omit<TypographyProps, "onClick">;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Custom item label
|
|
28
|
+
* @param item List item data
|
|
29
|
+
* @returns Result
|
|
30
|
+
*/
|
|
31
|
+
itemLabel?: (item: T) => React.ReactNode;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Custom render item
|
|
35
|
+
* @param item List item data
|
|
36
|
+
* @returns Result
|
|
37
|
+
*/
|
|
38
|
+
renderItem?: (item: T) => React.ReactNode;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* InputField with tips
|
|
43
|
+
* @param props Props
|
|
44
|
+
* @returns Component
|
|
45
|
+
*/
|
|
46
|
+
export function InputTipField<T extends ItemType = ItemType>(
|
|
47
|
+
props: InputTipFieldProps<T>
|
|
48
|
+
) {
|
|
49
|
+
// State
|
|
50
|
+
const [title, setTitle] = React.useState<string>();
|
|
51
|
+
const [anchorEl, setAnchorEl] = React.useState<HTMLElement>();
|
|
52
|
+
const [data, setData] = React.useState<T[]>();
|
|
53
|
+
|
|
54
|
+
// Destruct
|
|
55
|
+
const {
|
|
56
|
+
labelProps = {
|
|
57
|
+
title: globalApp?.get("clickForDetails"),
|
|
58
|
+
sx: { color: (theme) => theme.palette.error.main, cursor: "pointer" }
|
|
59
|
+
},
|
|
60
|
+
InputProps = {
|
|
61
|
+
endAdornment: title ? (
|
|
62
|
+
<InputAdornment position="end">
|
|
63
|
+
<Typography
|
|
64
|
+
onClick={(event) => {
|
|
65
|
+
setAnchorEl(event.currentTarget);
|
|
66
|
+
}}
|
|
67
|
+
{...labelProps}
|
|
68
|
+
>
|
|
69
|
+
{title}
|
|
70
|
+
</Typography>
|
|
71
|
+
</InputAdornment>
|
|
72
|
+
) : undefined
|
|
73
|
+
},
|
|
74
|
+
changeDelay = 480,
|
|
75
|
+
onChangeDelay,
|
|
76
|
+
loadData,
|
|
77
|
+
itemLabel = (item) => item.label,
|
|
78
|
+
renderItem = (item) => <ListItem key={item.id}>{itemLabel(item)}</ListItem>,
|
|
79
|
+
...rest
|
|
80
|
+
} = props;
|
|
81
|
+
|
|
82
|
+
const load = (value: string) => {
|
|
83
|
+
if (value.length < 2) {
|
|
84
|
+
setTitle(undefined);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
loadData(value).then(([data, title]) => {
|
|
89
|
+
setData(data);
|
|
90
|
+
setTitle(title);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<React.Fragment>
|
|
96
|
+
<Popover
|
|
97
|
+
open={anchorEl != null}
|
|
98
|
+
anchorEl={anchorEl}
|
|
99
|
+
onClose={() => setAnchorEl(undefined)}
|
|
100
|
+
anchorOrigin={{
|
|
101
|
+
vertical: "bottom",
|
|
102
|
+
horizontal: "left"
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
{data && <List>{data.map((item) => renderItem(item))}</List>}
|
|
106
|
+
</Popover>
|
|
107
|
+
<InputField
|
|
108
|
+
changeDelay={changeDelay}
|
|
109
|
+
onChangeDelay={(event) => {
|
|
110
|
+
load(event.target.value);
|
|
111
|
+
if (onChangeDelay) onChangeDelay(event);
|
|
112
|
+
}}
|
|
113
|
+
InputProps={InputProps}
|
|
114
|
+
{...rest}
|
|
115
|
+
/>
|
|
116
|
+
</React.Fragment>
|
|
117
|
+
);
|
|
118
|
+
}
|
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";
|