@etsoo/materialui 1.0.93 → 1.0.95
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 +12 -0
- package/lib/ItemList.js +6 -5
- package/package.json +1 -1
- package/src/ItemList.tsx +25 -5
package/lib/ItemList.d.ts
CHANGED
|
@@ -4,10 +4,18 @@ import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from '@etsoo/sha
|
|
|
4
4
|
* Item list properties
|
|
5
5
|
*/
|
|
6
6
|
export interface ItemListProps<T extends object, D extends DataTypes.Keys<T>, L extends DataTypes.Keys<T, string>> {
|
|
7
|
+
/**
|
|
8
|
+
* Button label
|
|
9
|
+
*/
|
|
10
|
+
buttonLabel?: React.ReactNode;
|
|
7
11
|
/**
|
|
8
12
|
* Style class name
|
|
9
13
|
*/
|
|
10
14
|
className?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Keep click for all items
|
|
17
|
+
*/
|
|
18
|
+
keepClick?: boolean;
|
|
11
19
|
/**
|
|
12
20
|
* Id field name
|
|
13
21
|
*/
|
|
@@ -16,6 +24,10 @@ export interface ItemListProps<T extends object, D extends DataTypes.Keys<T>, L
|
|
|
16
24
|
* Label field name or callback
|
|
17
25
|
*/
|
|
18
26
|
labelField?: L | ((item: T) => string);
|
|
27
|
+
/**
|
|
28
|
+
* Minimum width
|
|
29
|
+
*/
|
|
30
|
+
minWidth?: number | string;
|
|
19
31
|
/**
|
|
20
32
|
* Button icon
|
|
21
33
|
*/
|
package/lib/ItemList.js
CHANGED
|
@@ -8,7 +8,7 @@ import { DataTypes } from '@etsoo/shared';
|
|
|
8
8
|
export function ItemList(props) {
|
|
9
9
|
var _a;
|
|
10
10
|
// properties destructure
|
|
11
|
-
const { className, color = 'primary', items, idField = 'id', labelField = 'label', icon, onClose, selectedValue, size = 'medium', title, variant = 'outlined' } = props;
|
|
11
|
+
const { buttonLabel, className, color = 'primary', keepClick = false, items, idField = 'id', labelField = 'label', minWidth = '200px', icon, onClose, selectedValue, size = 'medium', title, variant = 'outlined' } = props;
|
|
12
12
|
// Get label
|
|
13
13
|
const getLabel = (item) => {
|
|
14
14
|
var _a;
|
|
@@ -57,13 +57,14 @@ export function ItemList(props) {
|
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
return (React.createElement(React.Fragment, null,
|
|
60
|
-
React.createElement(Button, { className: className, variant: variant, startIcon: icon, color: color, size: size, onClick: clickHandler }, getLabel(currentItem)),
|
|
61
|
-
React.createElement(Dialog, { "aria-labelledby": "dialog-title", open: open, onClose: closeHandler },
|
|
62
|
-
React.createElement(DialogTitle, {
|
|
60
|
+
React.createElement(Button, { className: className, variant: variant, startIcon: icon, color: color, size: size, onClick: clickHandler }, buttonLabel !== null && buttonLabel !== void 0 ? buttonLabel : getLabel(currentItem)),
|
|
61
|
+
React.createElement(Dialog, { "aria-labelledby": "dialog-title", open: open, onClose: closeHandler, sx: { minWidth } },
|
|
62
|
+
title && React.createElement(DialogTitle, { id: "dialog-title" }, title),
|
|
63
63
|
React.createElement(DialogContent, null,
|
|
64
64
|
React.createElement(List, null, items.map((item) => {
|
|
65
65
|
const id = item[idField];
|
|
66
|
-
return (React.createElement(ListItemButton, { key: id, disabled: id === currentItem[idField]
|
|
66
|
+
return (React.createElement(ListItemButton, { key: id, disabled: id === currentItem[idField] &&
|
|
67
|
+
!keepClick, onClick: () => closeItemHandler(item) },
|
|
67
68
|
React.createElement(ListItemText, null, getLabel(item))));
|
|
68
69
|
}))))));
|
|
69
70
|
}
|
package/package.json
CHANGED
package/src/ItemList.tsx
CHANGED
|
@@ -23,11 +23,21 @@ export interface ItemListProps<
|
|
|
23
23
|
D extends DataTypes.Keys<T>,
|
|
24
24
|
L extends DataTypes.Keys<T, string>
|
|
25
25
|
> {
|
|
26
|
+
/**
|
|
27
|
+
* Button label
|
|
28
|
+
*/
|
|
29
|
+
buttonLabel?: React.ReactNode;
|
|
30
|
+
|
|
26
31
|
/**
|
|
27
32
|
* Style class name
|
|
28
33
|
*/
|
|
29
34
|
className?: string;
|
|
30
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Keep click for all items
|
|
38
|
+
*/
|
|
39
|
+
keepClick?: boolean;
|
|
40
|
+
|
|
31
41
|
/**
|
|
32
42
|
* Id field name
|
|
33
43
|
*/
|
|
@@ -38,6 +48,11 @@ export interface ItemListProps<
|
|
|
38
48
|
*/
|
|
39
49
|
labelField?: L | ((item: T) => string);
|
|
40
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Minimum width
|
|
53
|
+
*/
|
|
54
|
+
minWidth?: number | string;
|
|
55
|
+
|
|
41
56
|
/**
|
|
42
57
|
* Button icon
|
|
43
58
|
*/
|
|
@@ -90,11 +105,14 @@ export function ItemList<
|
|
|
90
105
|
>(props: ItemListProps<T, D, L>) {
|
|
91
106
|
// properties destructure
|
|
92
107
|
const {
|
|
108
|
+
buttonLabel,
|
|
93
109
|
className,
|
|
94
110
|
color = 'primary',
|
|
111
|
+
keepClick = false,
|
|
95
112
|
items,
|
|
96
113
|
idField = 'id' as D,
|
|
97
114
|
labelField = 'label' as L,
|
|
115
|
+
minWidth = '200px',
|
|
98
116
|
icon,
|
|
99
117
|
onClose,
|
|
100
118
|
selectedValue,
|
|
@@ -170,16 +188,15 @@ export function ItemList<
|
|
|
170
188
|
size={size}
|
|
171
189
|
onClick={clickHandler}
|
|
172
190
|
>
|
|
173
|
-
{getLabel(currentItem)}
|
|
191
|
+
{buttonLabel ?? getLabel(currentItem)}
|
|
174
192
|
</Button>
|
|
175
193
|
<Dialog
|
|
176
194
|
aria-labelledby="dialog-title"
|
|
177
195
|
open={open}
|
|
178
196
|
onClose={closeHandler}
|
|
197
|
+
sx={{ minWidth }}
|
|
179
198
|
>
|
|
180
|
-
|
|
181
|
-
{title || ''}
|
|
182
|
-
</DialogTitle>
|
|
199
|
+
{title && <DialogTitle id="dialog-title">{title}</DialogTitle>}
|
|
183
200
|
<DialogContent>
|
|
184
201
|
<List>
|
|
185
202
|
{items.map((item) => {
|
|
@@ -187,7 +204,10 @@ export function ItemList<
|
|
|
187
204
|
return (
|
|
188
205
|
<ListItemButton
|
|
189
206
|
key={id as unknown as React.Key}
|
|
190
|
-
disabled={
|
|
207
|
+
disabled={
|
|
208
|
+
id === currentItem[idField] &&
|
|
209
|
+
!keepClick
|
|
210
|
+
}
|
|
191
211
|
onClick={() => closeItemHandler(item)}
|
|
192
212
|
>
|
|
193
213
|
<ListItemText>
|