@etsoo/materialui 1.1.2 → 1.1.3

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/ItemList.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from '@etsoo/shared';
1
+ import React from "react";
2
+ import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from "@etsoo/shared";
3
3
  /**
4
4
  * Item list properties
5
5
  */
@@ -35,7 +35,7 @@ export interface ItemListProps<T extends object, D extends DataTypes.Keys<T>, L
35
35
  /**
36
36
  * Button color
37
37
  */
38
- color?: 'inherit' | 'primary' | 'secondary';
38
+ color?: "inherit" | "primary" | "secondary";
39
39
  /**
40
40
  * Close event
41
41
  */
@@ -47,7 +47,7 @@ export interface ItemListProps<T extends object, D extends DataTypes.Keys<T>, L
47
47
  /**
48
48
  * Button size
49
49
  */
50
- size?: 'small' | 'medium' | 'large';
50
+ size?: "small" | "medium" | "large";
51
51
  /**
52
52
  * Title
53
53
  */
@@ -59,7 +59,7 @@ export interface ItemListProps<T extends object, D extends DataTypes.Keys<T>, L
59
59
  /**
60
60
  * Button variant
61
61
  */
62
- variant?: 'text' | 'outlined' | 'contained';
62
+ variant?: "text" | "outlined" | "contained";
63
63
  }
64
64
  /**
65
65
  * Item list component
package/lib/ItemList.js CHANGED
@@ -1,21 +1,21 @@
1
- import React from 'react';
2
- import { Dialog, DialogTitle, List, ListItemText, DialogContent, Button, ListItemButton } from '@mui/material';
3
- import { DataTypes } from '@etsoo/shared';
1
+ import React from "react";
2
+ import { Dialog, DialogTitle, List, ListItemText, DialogContent, Button, ListItemButton, } from "@mui/material";
3
+ import { DataTypes, } from "@etsoo/shared";
4
4
  /**
5
5
  * Item list component
6
6
  * @param props Properties
7
7
  */
8
8
  export function ItemList(props) {
9
9
  // properties destructure
10
- const { buttonLabel, className, color = 'primary', keepClick = false, items, idField = 'id', labelField = 'label', minWidth, icon, onClose, selectedValue, size = 'medium', title, variant = 'outlined' } = props;
10
+ const { buttonLabel, className, color = "primary", keepClick = false, items, idField = "id", labelField = "label", minWidth, icon, onClose, selectedValue, size = "medium", title, variant = "outlined", } = props;
11
11
  // Get label
12
12
  const getLabel = (item) => {
13
13
  var _a;
14
- if (typeof labelField === 'function') {
14
+ if (typeof labelField === "function") {
15
15
  return labelField(item);
16
16
  }
17
17
  else {
18
- return (_a = DataTypes.convert(item[labelField], 'string')) !== null && _a !== void 0 ? _a : '';
18
+ return (_a = DataTypes.convert(item[labelField], "string")) !== null && _a !== void 0 ? _a : "";
19
19
  }
20
20
  };
21
21
  // Dialog open or not state
@@ -46,8 +46,10 @@ export function ItemList(props) {
46
46
  };
47
47
  // Close item handler
48
48
  const closeItemHandler = (item) => {
49
- // Update the current item
50
- setCurrentItem(item);
49
+ if (!keepClick) {
50
+ // Update the current item
51
+ setCurrentItem(item);
52
+ }
51
53
  // Close the dialog
52
54
  setOpen(false);
53
55
  // Emit close event
@@ -62,10 +64,8 @@ export function ItemList(props) {
62
64
  React.createElement(DialogContent, { sx: { minWidth } },
63
65
  React.createElement(List, null, items.map((item) => {
64
66
  const id = item[idField];
65
- return (React.createElement(ListItemButton, { key: id, disabled: id ===
66
- (currentItem
67
- ? currentItem[idField]
68
- : undefined) && !keepClick, onClick: () => closeItemHandler(item) },
67
+ return (React.createElement(ListItemButton, { key: id, disabled: id === (currentItem ? currentItem[idField] : undefined) &&
68
+ !keepClick, onClick: () => closeItemHandler(item) },
69
69
  React.createElement(ListItemText, null, getLabel(item))));
70
70
  }))))));
71
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/ItemList.tsx CHANGED
@@ -1,97 +1,97 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  import {
3
- Dialog,
4
- DialogTitle,
5
- List,
6
- ListItemText,
7
- DialogContent,
8
- Button,
9
- ListItemButton
10
- } from '@mui/material';
3
+ Dialog,
4
+ DialogTitle,
5
+ List,
6
+ ListItemText,
7
+ DialogContent,
8
+ Button,
9
+ ListItemButton,
10
+ } from "@mui/material";
11
11
  import {
12
- DataTypes,
13
- IdDefaultType,
14
- LabelDefaultType,
15
- ListType
16
- } from '@etsoo/shared';
12
+ DataTypes,
13
+ IdDefaultType,
14
+ LabelDefaultType,
15
+ ListType,
16
+ } from "@etsoo/shared";
17
17
 
18
18
  /**
19
19
  * Item list properties
20
20
  */
21
21
  export interface ItemListProps<
22
- T extends object,
23
- D extends DataTypes.Keys<T>,
24
- L extends DataTypes.Keys<T, string>
22
+ T extends object,
23
+ D extends DataTypes.Keys<T>,
24
+ L extends DataTypes.Keys<T, string>
25
25
  > {
26
- /**
27
- * Button label
28
- */
29
- buttonLabel?: React.ReactNode;
30
-
31
- /**
32
- * Style class name
33
- */
34
- className?: string;
35
-
36
- /**
37
- * Keep click for all items
38
- */
39
- keepClick?: boolean;
40
-
41
- /**
42
- * Id field name
43
- */
44
- idField?: D;
45
-
46
- /**
47
- * Label field name or callback
48
- */
49
- labelField?: L | ((item: T) => string);
50
-
51
- /**
52
- * Minimum width
53
- */
54
- minWidth?: number | string;
55
-
56
- /**
57
- * Button icon
58
- */
59
- icon?: React.ReactNode;
60
-
61
- /**
62
- * Button color
63
- */
64
- color?: 'inherit' | 'primary' | 'secondary';
65
-
66
- /**
67
- * Close event
68
- */
69
- onClose?(item: T | undefined, changed: boolean): void;
70
-
71
- /**
72
- * Current selected language
73
- */
74
- selectedValue?: T[D];
75
-
76
- /**
77
- * Button size
78
- */
79
- size?: 'small' | 'medium' | 'large';
80
-
81
- /**
82
- * Title
83
- */
84
- title?: string;
85
-
86
- /**
87
- * Items
88
- */
89
- items: T[];
90
-
91
- /**
92
- * Button variant
93
- */
94
- variant?: 'text' | 'outlined' | 'contained';
26
+ /**
27
+ * Button label
28
+ */
29
+ buttonLabel?: React.ReactNode;
30
+
31
+ /**
32
+ * Style class name
33
+ */
34
+ className?: string;
35
+
36
+ /**
37
+ * Keep click for all items
38
+ */
39
+ keepClick?: boolean;
40
+
41
+ /**
42
+ * Id field name
43
+ */
44
+ idField?: D;
45
+
46
+ /**
47
+ * Label field name or callback
48
+ */
49
+ labelField?: L | ((item: T) => string);
50
+
51
+ /**
52
+ * Minimum width
53
+ */
54
+ minWidth?: number | string;
55
+
56
+ /**
57
+ * Button icon
58
+ */
59
+ icon?: React.ReactNode;
60
+
61
+ /**
62
+ * Button color
63
+ */
64
+ color?: "inherit" | "primary" | "secondary";
65
+
66
+ /**
67
+ * Close event
68
+ */
69
+ onClose?(item: T | undefined, changed: boolean): void;
70
+
71
+ /**
72
+ * Current selected language
73
+ */
74
+ selectedValue?: T[D];
75
+
76
+ /**
77
+ * Button size
78
+ */
79
+ size?: "small" | "medium" | "large";
80
+
81
+ /**
82
+ * Title
83
+ */
84
+ title?: string;
85
+
86
+ /**
87
+ * Items
88
+ */
89
+ items: T[];
90
+
91
+ /**
92
+ * Button variant
93
+ */
94
+ variant?: "text" | "outlined" | "contained";
95
95
  }
96
96
 
97
97
  /**
@@ -99,129 +99,122 @@ export interface ItemListProps<
99
99
  * @param props Properties
100
100
  */
101
101
  export function ItemList<
102
- T extends object = ListType,
103
- D extends DataTypes.Keys<T> = IdDefaultType<T>,
104
- L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
102
+ T extends object = ListType,
103
+ D extends DataTypes.Keys<T> = IdDefaultType<T>,
104
+ L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
105
105
  >(props: ItemListProps<T, D, L>) {
106
- // properties destructure
107
- const {
108
- buttonLabel,
109
- className,
110
- color = 'primary',
111
- keepClick = false,
112
- items,
113
- idField = 'id' as D,
114
- labelField = 'label' as L,
115
- minWidth,
116
- icon,
117
- onClose,
118
- selectedValue,
119
- size = 'medium',
120
- title,
121
- variant = 'outlined'
122
- } = props;
123
-
124
- // Get label
125
- const getLabel = (item: T): string => {
126
- if (typeof labelField === 'function') {
127
- return labelField(item);
128
- } else {
129
- return DataTypes.convert(item[labelField], 'string') ?? '';
130
- }
131
- };
132
-
133
- // Dialog open or not state
134
- const [open, setOpen] = React.useState(false);
135
-
136
- // Default state
137
- const defaultItem: T | undefined = items.find(
138
- (item) => item[idField] === selectedValue
139
- );
140
-
141
- // Current item
142
- const [currentItem, setCurrentItem] = React.useState(defaultItem);
143
-
144
- // Click handler
145
- const clickHandler = () => {
146
- // More than one language
147
- if (items.length < 2) {
148
- return;
149
- }
150
-
151
- // Open the dialog
152
- setOpen(true);
153
- };
154
-
155
- // Close handler
156
- const closeHandler = () => {
157
- if (!open) return;
158
-
159
- // Close the dialog
160
- setOpen(false);
161
-
162
- // Emit close event
163
- if (onClose) {
164
- onClose(currentItem, false);
165
- }
166
- };
167
-
168
- // Close item handler
169
- const closeItemHandler = (item: any) => {
170
- // Update the current item
171
- setCurrentItem(item);
172
-
173
- // Close the dialog
174
- setOpen(false);
175
-
176
- // Emit close event
177
- if (onClose) {
178
- onClose(item, true);
179
- }
180
- };
181
-
182
- return (
183
- <>
184
- <Button
185
- className={className}
186
- variant={variant}
187
- startIcon={icon}
188
- color={color}
189
- size={size}
190
- onClick={clickHandler}
191
- >
192
- {buttonLabel ??
193
- (currentItem ? getLabel(currentItem) : undefined)}
194
- </Button>
195
- <Dialog
196
- aria-labelledby="dialog-title"
197
- open={open}
198
- onClose={closeHandler}
199
- >
200
- {title && <DialogTitle id="dialog-title">{title}</DialogTitle>}
201
- <DialogContent sx={{ minWidth }}>
202
- <List>
203
- {items.map((item) => {
204
- const id = item[idField];
205
- return (
206
- <ListItemButton
207
- key={id as unknown as React.Key}
208
- disabled={
209
- id ===
210
- (currentItem
211
- ? currentItem[idField]
212
- : undefined) && !keepClick
213
- }
214
- onClick={() => closeItemHandler(item)}
215
- >
216
- <ListItemText>
217
- {getLabel(item)}
218
- </ListItemText>
219
- </ListItemButton>
220
- );
221
- })}
222
- </List>
223
- </DialogContent>
224
- </Dialog>
225
- </>
226
- );
106
+ // properties destructure
107
+ const {
108
+ buttonLabel,
109
+ className,
110
+ color = "primary",
111
+ keepClick = false,
112
+ items,
113
+ idField = "id" as D,
114
+ labelField = "label" as L,
115
+ minWidth,
116
+ icon,
117
+ onClose,
118
+ selectedValue,
119
+ size = "medium",
120
+ title,
121
+ variant = "outlined",
122
+ } = props;
123
+
124
+ // Get label
125
+ const getLabel = (item: T): string => {
126
+ if (typeof labelField === "function") {
127
+ return labelField(item);
128
+ } else {
129
+ return DataTypes.convert(item[labelField], "string") ?? "";
130
+ }
131
+ };
132
+
133
+ // Dialog open or not state
134
+ const [open, setOpen] = React.useState(false);
135
+
136
+ // Default state
137
+ const defaultItem: T | undefined = items.find(
138
+ (item) => item[idField] === selectedValue
139
+ );
140
+
141
+ // Current item
142
+ const [currentItem, setCurrentItem] = React.useState(defaultItem);
143
+
144
+ // Click handler
145
+ const clickHandler = () => {
146
+ // More than one language
147
+ if (items.length < 2) {
148
+ return;
149
+ }
150
+
151
+ // Open the dialog
152
+ setOpen(true);
153
+ };
154
+
155
+ // Close handler
156
+ const closeHandler = () => {
157
+ if (!open) return;
158
+
159
+ // Close the dialog
160
+ setOpen(false);
161
+
162
+ // Emit close event
163
+ if (onClose) {
164
+ onClose(currentItem, false);
165
+ }
166
+ };
167
+
168
+ // Close item handler
169
+ const closeItemHandler = (item: T) => {
170
+ if (!keepClick) {
171
+ // Update the current item
172
+ setCurrentItem(item);
173
+ }
174
+
175
+ // Close the dialog
176
+ setOpen(false);
177
+
178
+ // Emit close event
179
+ if (onClose) {
180
+ onClose(item, true);
181
+ }
182
+ };
183
+
184
+ return (
185
+ <>
186
+ <Button
187
+ className={className}
188
+ variant={variant}
189
+ startIcon={icon}
190
+ color={color}
191
+ size={size}
192
+ onClick={clickHandler}
193
+ >
194
+ {buttonLabel ?? (currentItem ? getLabel(currentItem) : undefined)}
195
+ </Button>
196
+ <Dialog aria-labelledby="dialog-title" open={open} onClose={closeHandler}>
197
+ {title && <DialogTitle id="dialog-title">{title}</DialogTitle>}
198
+ <DialogContent sx={{ minWidth }}>
199
+ <List>
200
+ {items.map((item) => {
201
+ const id = item[idField];
202
+ return (
203
+ <ListItemButton
204
+ key={id as unknown as React.Key}
205
+ disabled={
206
+ id === (currentItem ? currentItem[idField] : undefined) &&
207
+ !keepClick
208
+ }
209
+ onClick={() => closeItemHandler(item)}
210
+ >
211
+ <ListItemText>{getLabel(item)}</ListItemText>
212
+ </ListItemButton>
213
+ );
214
+ })}
215
+ </List>
216
+ </DialogContent>
217
+ </Dialog>
218
+ </>
219
+ );
227
220
  }