@etsoo/materialui 1.1.53 → 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.
@@ -1,26 +1,38 @@
1
- /// <reference types="react" />
2
1
  import { DataTypes } from "@etsoo/shared";
3
2
  import { TypographyProps } from "@mui/material/Typography";
3
+ import React from "react";
4
4
  import { InputFieldProps } from "./InputField";
5
5
  type ItemType = DataTypes.IdLabelItem<string | number>;
6
6
  /**
7
7
  * InputField with tips properties
8
8
  */
9
- export type InputTipFieldProps = InputFieldProps & {
9
+ export type InputTipFieldProps<T extends ItemType = ItemType> = InputFieldProps & {
10
10
  /**
11
11
  * Load data
12
12
  * @param value Duplicate test value
13
13
  */
14
- loadData(value: string): Promise<[ItemType[]?, string?]>;
14
+ loadData(value: string): Promise<[T[]?, string?]>;
15
15
  /**
16
16
  * Label props
17
17
  */
18
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;
19
31
  };
20
32
  /**
21
33
  * InputField with tips
22
34
  * @param props Props
23
35
  * @returns Component
24
36
  */
25
- export declare function InputTipField(props: InputTipFieldProps): JSX.Element;
37
+ export declare function InputTipField<T extends ItemType = ItemType>(props: InputTipFieldProps<T>): JSX.Element;
26
38
  export {};
@@ -22,7 +22,7 @@ export function InputTipField(props) {
22
22
  React.createElement(Typography, { onClick: (event) => {
23
23
  setAnchorEl(event.currentTarget);
24
24
  }, ...labelProps }, title))) : undefined
25
- }, changeDelay = 480, onChangeDelay, loadData, ...rest } = props;
25
+ }, changeDelay = 480, onChangeDelay, loadData, itemLabel = (item) => item.label, renderItem = (item) => React.createElement(ListItem, { key: item.id }, itemLabel(item)), ...rest } = props;
26
26
  const load = (value) => {
27
27
  if (value.length < 2) {
28
28
  setTitle(undefined);
@@ -37,7 +37,7 @@ export function InputTipField(props) {
37
37
  React.createElement(Popover, { open: anchorEl != null, anchorEl: anchorEl, onClose: () => setAnchorEl(undefined), anchorOrigin: {
38
38
  vertical: "bottom",
39
39
  horizontal: "left"
40
- } }, data && (React.createElement(List, null, data.map((item) => (React.createElement(ListItem, { key: item.id }, item.label)))))),
40
+ } }, data && React.createElement(List, null, data.map((item) => renderItem(item)))),
41
41
  React.createElement(InputField, { changeDelay: changeDelay, onChangeDelay: (event) => {
42
42
  load(event.target.value);
43
43
  if (onChangeDelay)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.53",
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",
@@ -10,29 +10,46 @@ type ItemType = DataTypes.IdLabelItem<string | number>;
10
10
  /**
11
11
  * InputField with tips properties
12
12
  */
13
- export type InputTipFieldProps = InputFieldProps & {
14
- /**
15
- * Load data
16
- * @param value Duplicate test value
17
- */
18
- loadData(value: string): Promise<[ItemType[]?, string?]>;
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?]>;
19
20
 
20
- /**
21
- * Label props
22
- */
23
- labelProps?: Omit<TypographyProps, "onClick">;
24
- };
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
+ };
25
40
 
26
41
  /**
27
42
  * InputField with tips
28
43
  * @param props Props
29
44
  * @returns Component
30
45
  */
31
- export function InputTipField(props: InputTipFieldProps) {
46
+ export function InputTipField<T extends ItemType = ItemType>(
47
+ props: InputTipFieldProps<T>
48
+ ) {
32
49
  // State
33
50
  const [title, setTitle] = React.useState<string>();
34
51
  const [anchorEl, setAnchorEl] = React.useState<HTMLElement>();
35
- const [data, setData] = React.useState<ItemType[]>();
52
+ const [data, setData] = React.useState<T[]>();
36
53
 
37
54
  // Destruct
38
55
  const {
@@ -57,6 +74,8 @@ export function InputTipField(props: InputTipFieldProps) {
57
74
  changeDelay = 480,
58
75
  onChangeDelay,
59
76
  loadData,
77
+ itemLabel = (item) => item.label,
78
+ renderItem = (item) => <ListItem key={item.id}>{itemLabel(item)}</ListItem>,
60
79
  ...rest
61
80
  } = props;
62
81
 
@@ -83,13 +102,7 @@ export function InputTipField(props: InputTipFieldProps) {
83
102
  horizontal: "left"
84
103
  }}
85
104
  >
86
- {data && (
87
- <List>
88
- {data.map((item) => (
89
- <ListItem key={item.id}>{item.label}</ListItem>
90
- ))}
91
- </List>
92
- )}
105
+ {data && <List>{data.map((item) => renderItem(item))}</List>}
93
106
  </Popover>
94
107
  <InputField
95
108
  changeDelay={changeDelay}