@janrankenhohn/react-thumbnail-list 0.5.1 → 0.5.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/dist/index.cjs.js +574 -280
- package/dist/index.esm.js +574 -280
- package/package.json +4 -1
package/dist/index.cjs.js
CHANGED
|
@@ -20,316 +20,610 @@ var ClearIcon__default = /*#__PURE__*/_interopDefaultLegacy(ClearIcon);
|
|
|
20
20
|
var SwapVertIcon__default = /*#__PURE__*/_interopDefaultLegacy(SwapVertIcon);
|
|
21
21
|
var SortIcon__default = /*#__PURE__*/_interopDefaultLegacy(SortIcon);
|
|
22
22
|
|
|
23
|
-
const ThumbnailListItemContext = React.createContext(undefined);
|
|
24
|
-
const useThumbnailListItemContext = () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const ThumbnailListItemContext = /*#__PURE__*/React.createContext(undefined);
|
|
24
|
+
const useThumbnailListItemContext = () => {
|
|
25
|
+
const context = React.useContext(ThumbnailListItemContext);
|
|
26
|
+
if (!context) {
|
|
27
|
+
throw new Error('no context provider available');
|
|
28
|
+
}
|
|
29
|
+
return context;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
/**
|
|
33
|
-
* Creates a ellipies text with webkit css styles
|
|
34
|
-
* @param props lineClamp: lines till ellipses
|
|
35
|
-
* @returns component
|
|
36
|
-
*/
|
|
37
|
-
function EllipsisContainer(props) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Creates a ellipies text with webkit css styles
|
|
34
|
+
* @param props lineClamp: lines till ellipses
|
|
35
|
+
* @returns component
|
|
36
|
+
*/
|
|
37
|
+
function EllipsisContainer(props) {
|
|
38
|
+
const EllipsisContainer = material.styled('div')(p => ({
|
|
39
|
+
[p.theme.breakpoints.up('xs')]: {
|
|
40
|
+
overflow: 'hidden',
|
|
41
|
+
display: '-webkit-box',
|
|
42
|
+
WebkitLineClamp: props.lineClamp.xs.toString() /* number of lines to show */,
|
|
43
|
+
WebkitBoxOrient: 'vertical'
|
|
44
|
+
},
|
|
45
|
+
[p.theme.breakpoints.up('sm')]: {
|
|
46
|
+
overflow: 'hidden',
|
|
47
|
+
display: '-webkit-box',
|
|
48
|
+
WebkitLineClamp: props.lineClamp.sm.toString() /* number of lines to show */,
|
|
49
|
+
WebkitBoxOrient: 'vertical' /* number of lines to show */
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
return jsxRuntime.jsx(EllipsisContainer, {
|
|
53
|
+
children: props.children
|
|
54
|
+
});
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
function ThumbnailListItemTitle(props) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
function ThumbnailListItemTitle(props) {
|
|
58
|
+
const StyledCardContent = material.styled('div')(p => ({
|
|
59
|
+
[p.theme.breakpoints.up('xs')]: {
|
|
60
|
+
padding: p.theme.spacing(1),
|
|
61
|
+
flex: '1 0 auto',
|
|
62
|
+
'&:last-child': {
|
|
63
|
+
paddingBottom: 0
|
|
64
|
+
},
|
|
65
|
+
overflow: 'hidden'
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
console.log('item title rerenders');
|
|
69
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
70
|
+
children: jsxRuntime.jsx(material.Box, {
|
|
71
|
+
children: jsxRuntime.jsxs(StyledCardContent, {
|
|
72
|
+
children: [jsxRuntime.jsx(EllipsisContainer, {
|
|
73
|
+
lineClamp: {
|
|
74
|
+
xs: 1,
|
|
75
|
+
sm: 2
|
|
76
|
+
},
|
|
77
|
+
children: jsxRuntime.jsx(material.Typography, {
|
|
78
|
+
variant: "subtitle2",
|
|
79
|
+
sx: {
|
|
80
|
+
fontWeight: 'bold'
|
|
81
|
+
},
|
|
82
|
+
children: props.title
|
|
83
|
+
})
|
|
84
|
+
}), jsxRuntime.jsx(system.Stack, {
|
|
85
|
+
direction: "row",
|
|
86
|
+
gap: 1,
|
|
87
|
+
children: jsxRuntime.jsx(EllipsisContainer, {
|
|
88
|
+
lineClamp: {
|
|
89
|
+
xs: 1,
|
|
90
|
+
sm: 2
|
|
91
|
+
},
|
|
92
|
+
children: jsxRuntime.jsx(material.Typography, {
|
|
93
|
+
variant: "subtitle2",
|
|
94
|
+
sx: {
|
|
95
|
+
fontSize: '0.84rem'
|
|
96
|
+
},
|
|
97
|
+
color: "text.secondary",
|
|
98
|
+
children: props.subTitle
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
})]
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
});
|
|
66
105
|
}
|
|
67
106
|
|
|
68
|
-
const ThumbnailListItem =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
107
|
+
const ThumbnailListItem = props => {
|
|
108
|
+
console.log('ThumbnailListItems renders');
|
|
109
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
110
|
+
children: jsxRuntime.jsx(material.Card, {
|
|
111
|
+
sx: {
|
|
112
|
+
display: 'flex'
|
|
113
|
+
},
|
|
114
|
+
children: jsxRuntime.jsx(material.CardActionArea, {
|
|
115
|
+
disabled: !props.onClick,
|
|
116
|
+
onClick: () => props.onClick(props.id),
|
|
117
|
+
children: jsxRuntime.jsxs(material.Stack, {
|
|
118
|
+
direction: "row",
|
|
119
|
+
width: "100%",
|
|
120
|
+
children: [jsxRuntime.jsx("img", {
|
|
121
|
+
src: props.thumbnailUrl,
|
|
122
|
+
width: '45%'
|
|
123
|
+
}), jsxRuntime.jsxs(material.Stack, {
|
|
124
|
+
direction: "row",
|
|
125
|
+
justifyContent: "space-between",
|
|
126
|
+
width: "100%",
|
|
127
|
+
gap: 1,
|
|
128
|
+
children: [jsxRuntime.jsx(ThumbnailListItemTitle, {
|
|
129
|
+
title: props.title,
|
|
130
|
+
subTitle: props.subTitle
|
|
131
|
+
}), props.infoLabel]
|
|
132
|
+
})]
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
var ThumbnailListItem$1 = /*#__PURE__*/React__default["default"].memo(ThumbnailListItem);
|
|
73
139
|
|
|
74
|
-
const RatioWrapper = material.styled('div')(() => ({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
140
|
+
const RatioWrapper = material.styled('div')(() => ({
|
|
141
|
+
// Assuming a 16:9 aspect ratio
|
|
142
|
+
paddingTop: '27.75%',
|
|
143
|
+
// 9 / 16 = 0.5625
|
|
144
|
+
position: 'relative',
|
|
145
|
+
width: '100%',
|
|
146
|
+
'& > *': {
|
|
147
|
+
position: 'absolute',
|
|
148
|
+
top: 0,
|
|
149
|
+
left: 0,
|
|
150
|
+
right: 0,
|
|
151
|
+
bottom: 0
|
|
152
|
+
}
|
|
153
|
+
}));
|
|
154
|
+
function ThumbnailListMainContent(props) {
|
|
155
|
+
const {
|
|
156
|
+
items,
|
|
157
|
+
isLoading
|
|
158
|
+
} = useThumbnailListItemContext();
|
|
159
|
+
console.log('main content rerenders');
|
|
160
|
+
const memoizedItems = React.useMemo(() => {
|
|
161
|
+
return items.map(item => jsxRuntime.jsx(material.Grid, {
|
|
162
|
+
item: true,
|
|
163
|
+
xs: props.muiBreakpoints.xs,
|
|
164
|
+
sm: props.muiBreakpoints.sm,
|
|
165
|
+
md: props.muiBreakpoints.md,
|
|
166
|
+
lg: props.muiBreakpoints.lg,
|
|
167
|
+
xl: props.muiBreakpoints.xl,
|
|
168
|
+
children: jsxRuntime.jsx(RatioWrapper, {
|
|
169
|
+
children: jsxRuntime.jsx(ThumbnailListItem$1, {
|
|
170
|
+
id: item.id,
|
|
171
|
+
thumbnailUrl: item.thumbnailUrl,
|
|
172
|
+
title: item.title,
|
|
173
|
+
subTitle: item.subTitle,
|
|
174
|
+
infoLabel: item.label,
|
|
175
|
+
onClick: item.onClick
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
}, item.id));
|
|
179
|
+
}, [items, props.muiBreakpoints]);
|
|
180
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
181
|
+
children: [jsxRuntime.jsx(material.Box, {
|
|
182
|
+
sx: {
|
|
183
|
+
mt: 0.75,
|
|
184
|
+
mb: 0.75
|
|
185
|
+
},
|
|
186
|
+
children: jsxRuntime.jsx(material.LinearProgress, {
|
|
187
|
+
sx: {
|
|
188
|
+
opacity: isLoading ? 1 : 0
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
}), jsxRuntime.jsx(material.Grid, {
|
|
192
|
+
container: true,
|
|
193
|
+
spacing: props.spacing,
|
|
194
|
+
children: memoizedItems
|
|
195
|
+
})]
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
ThumbnailListMainContent.defaultProps = {
|
|
199
|
+
spacing: 2,
|
|
200
|
+
muiBreakpoints: {
|
|
201
|
+
xs: 12,
|
|
202
|
+
sm: 6,
|
|
203
|
+
md: 6,
|
|
204
|
+
lg: 4,
|
|
205
|
+
xl: 3
|
|
206
|
+
}
|
|
98
207
|
};
|
|
99
208
|
|
|
100
|
-
/**
|
|
101
|
-
* Generic method that sorts an array of items based on an item key
|
|
102
|
-
* @param values The array that should be sorted
|
|
103
|
-
* @param orderType The key of the entity that the array should be sorted by
|
|
104
|
-
* @returns A new reference of the ordered array
|
|
105
|
-
*/
|
|
106
|
-
function orderByArray(values, orderType) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
function getComparableValue(value) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
function filterByTag(array, tagType, condition) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Generic method that sorts an array of items based on an item key
|
|
211
|
+
* @param values The array that should be sorted
|
|
212
|
+
* @param orderType The key of the entity that the array should be sorted by
|
|
213
|
+
* @returns A new reference of the ordered array
|
|
214
|
+
*/
|
|
215
|
+
function orderByArray(values, orderType) {
|
|
216
|
+
return [...values].sort((a, b) => {
|
|
217
|
+
const valueA = getComparableValue(a[orderType]);
|
|
218
|
+
const valueB = getComparableValue(b[orderType]);
|
|
219
|
+
return compareValues(valueA, valueB);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function getComparableValue(value) {
|
|
223
|
+
if (typeof value === 'number') {
|
|
224
|
+
return value;
|
|
225
|
+
} else {
|
|
226
|
+
return String(value);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function compareValues(a, b) {
|
|
230
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
231
|
+
return a.localeCompare(b, undefined, {
|
|
232
|
+
sensitivity: 'base'
|
|
233
|
+
});
|
|
234
|
+
} else {
|
|
235
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function filterByTag(array, tagType, condition) {
|
|
239
|
+
const filteredArray = array.filter(item => {
|
|
240
|
+
const tagValue = item[tagType];
|
|
241
|
+
return condition ? condition(tagValue) : !!tagValue;
|
|
242
|
+
});
|
|
243
|
+
console.log('filter array');
|
|
244
|
+
console.log(filteredArray);
|
|
245
|
+
return [...filteredArray];
|
|
137
246
|
}
|
|
138
247
|
|
|
139
|
-
const useTagFilteredThumbnailListItems =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
248
|
+
const useTagFilteredThumbnailListItems = _ref => {
|
|
249
|
+
let {
|
|
250
|
+
allItems,
|
|
251
|
+
initialTag,
|
|
252
|
+
initialCondition
|
|
253
|
+
} = _ref;
|
|
254
|
+
const [tagAndCondition, setTagAndCondition] = React.useState({
|
|
255
|
+
tag: initialTag,
|
|
256
|
+
condition: initialCondition
|
|
257
|
+
});
|
|
258
|
+
const setTagWithCondition = (t, c) => {
|
|
259
|
+
setTagAndCondition({
|
|
260
|
+
tag: t,
|
|
261
|
+
condition: c
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
const tagFilteredItems = React.useMemo(() => {
|
|
265
|
+
const tagFiltered = tagAndCondition.tag === 'id' ? allItems : filterByTag(allItems, tagAndCondition.tag, tagAndCondition.condition);
|
|
266
|
+
return tagFiltered;
|
|
267
|
+
}, [allItems, tagAndCondition]);
|
|
268
|
+
return {
|
|
269
|
+
tagAndCondition,
|
|
270
|
+
setTagAndCondition,
|
|
271
|
+
tagFilteredItems,
|
|
272
|
+
setTagWithCondition
|
|
273
|
+
};
|
|
156
274
|
};
|
|
157
275
|
|
|
158
|
-
/**
|
|
159
|
-
* Filters a list of event by a search term
|
|
160
|
-
* @param allEvents event list that will be formatted
|
|
161
|
-
* @param initialSearchTerm
|
|
162
|
-
* @returns
|
|
163
|
-
*/
|
|
164
|
-
const useFilteredThumbnailListItems = (allItems
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Filters a list of event by a search term
|
|
278
|
+
* @param allEvents event list that will be formatted
|
|
279
|
+
* @param initialSearchTerm
|
|
280
|
+
* @returns
|
|
281
|
+
*/
|
|
282
|
+
const useFilteredThumbnailListItems = function (allItems) {
|
|
283
|
+
let initialSearchTerm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
284
|
+
const [searchTerm, setSearchTerm] = React.useState(initialSearchTerm);
|
|
285
|
+
const filteredItems = React.useMemo(() => {
|
|
286
|
+
const filtered = [...allItems].filter(item => item.title.toLowerCase().includes(searchTerm.toLowerCase()));
|
|
287
|
+
return filtered;
|
|
288
|
+
}, [allItems, searchTerm]);
|
|
289
|
+
return {
|
|
290
|
+
searchTerm,
|
|
291
|
+
setSearchTerm,
|
|
292
|
+
filteredItems
|
|
293
|
+
};
|
|
171
294
|
};
|
|
172
295
|
|
|
173
|
-
const useSortedThumbnailListItems = (allItems, initialSortBy, initialSortAscending) => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
296
|
+
const useSortedThumbnailListItems = (allItems, initialSortBy, initialSortAscending) => {
|
|
297
|
+
const [sortBy, setSortBy] = React.useState(initialSortBy);
|
|
298
|
+
const [sortAscending, setSortAscending] = React.useState(initialSortAscending);
|
|
299
|
+
const sortedItems = React.useMemo(() => {
|
|
300
|
+
let sorted = orderByArray(allItems, sortBy);
|
|
301
|
+
if (!sortAscending) {
|
|
302
|
+
sorted = sorted.reverse();
|
|
303
|
+
}
|
|
304
|
+
return sorted;
|
|
305
|
+
}, [allItems, sortBy, sortAscending]);
|
|
306
|
+
return {
|
|
307
|
+
sortBy,
|
|
308
|
+
sortAscending,
|
|
309
|
+
setSortBy,
|
|
310
|
+
setSortAscending,
|
|
311
|
+
sortedItems
|
|
312
|
+
};
|
|
184
313
|
};
|
|
185
314
|
|
|
186
|
-
const defaultConfiguration = {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
315
|
+
const defaultConfiguration = {
|
|
316
|
+
sortBy: 'id',
|
|
317
|
+
sortAscending: true,
|
|
318
|
+
tag: 'id'
|
|
190
319
|
};
|
|
191
320
|
|
|
192
|
-
const ThumbnailListSearchField = () => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
321
|
+
const ThumbnailListSearchField = () => {
|
|
322
|
+
const [input, setInput] = React.useState('');
|
|
323
|
+
const [showClearIcon, setShowClearIcon] = React.useState('hidden');
|
|
324
|
+
const {
|
|
325
|
+
setSearchTerm
|
|
326
|
+
} = useThumbnailListItemContext();
|
|
327
|
+
console.log('Searchfield rerenders');
|
|
328
|
+
const handleChange = value => {
|
|
329
|
+
setInput(value);
|
|
330
|
+
setShowClearIcon(value === '' ? 'hidden' : '');
|
|
331
|
+
};
|
|
332
|
+
const debouncedSetSearchTerm = React.useCallback(lodash.debounce(setSearchTerm, 50), []);
|
|
333
|
+
React.useEffect(() => {
|
|
334
|
+
debouncedSetSearchTerm(input);
|
|
335
|
+
return () => {
|
|
336
|
+
debouncedSetSearchTerm.cancel();
|
|
337
|
+
};
|
|
338
|
+
}, [input, debouncedSetSearchTerm]);
|
|
339
|
+
return jsxRuntime.jsx(material.Box, {
|
|
340
|
+
sx: {
|
|
341
|
+
marginLeft: 'auto'
|
|
342
|
+
},
|
|
343
|
+
children: jsxRuntime.jsx(material.FormControl, {
|
|
344
|
+
children: jsxRuntime.jsx(material.TextField, {
|
|
345
|
+
fullWidth: true,
|
|
346
|
+
value: input,
|
|
347
|
+
size: "small",
|
|
348
|
+
variant: "outlined",
|
|
349
|
+
onChange: event => handleChange(event.target.value),
|
|
350
|
+
InputProps: {
|
|
351
|
+
startAdornment: jsxRuntime.jsx(material.InputAdornment, {
|
|
352
|
+
position: "start",
|
|
353
|
+
children: jsxRuntime.jsx(SearchIcon__default["default"], {})
|
|
354
|
+
}),
|
|
355
|
+
endAdornment: jsxRuntime.jsx(material.InputAdornment, {
|
|
356
|
+
position: "end",
|
|
357
|
+
children: jsxRuntime.jsx(material.IconButton, {
|
|
358
|
+
onClick: () => handleChange(''),
|
|
359
|
+
sx: {
|
|
360
|
+
visibility: showClearIcon,
|
|
361
|
+
padding: 0
|
|
362
|
+
},
|
|
363
|
+
children: jsxRuntime.jsx(ClearIcon__default["default"], {})
|
|
364
|
+
})
|
|
365
|
+
})
|
|
366
|
+
}
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
ThumbnailListSearchField.defaultProps = {
|
|
372
|
+
align: 'start'
|
|
373
|
+
};
|
|
374
|
+
var ThumbnailListSearchField$1 = /*#__PURE__*/React__default["default"].memo(ThumbnailListSearchField);
|
|
217
375
|
|
|
218
|
-
function ThumbnailListFilterTag(props) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
376
|
+
function ThumbnailListFilterTag(props) {
|
|
377
|
+
var _props$collapseBreakp;
|
|
378
|
+
const theme = material.useTheme();
|
|
379
|
+
const handleOnClick = value => {
|
|
380
|
+
if (props.onClickCallback) {
|
|
381
|
+
props.onClickCallback(value);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
385
|
+
children: material.useMediaQuery(theme.breakpoints.up((_props$collapseBreakp = props.collapseBreakpoint) !== null && _props$collapseBreakp !== void 0 ? _props$collapseBreakp : 0)) || !props.icon ? jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
386
|
+
children: jsxRuntime.jsx(material.Chip, {
|
|
387
|
+
label: props.label,
|
|
388
|
+
variant: props.variant,
|
|
389
|
+
onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined
|
|
390
|
+
})
|
|
391
|
+
}) : jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
392
|
+
children: jsxRuntime.jsx(material.Tooltip, {
|
|
393
|
+
title: props.label,
|
|
394
|
+
children: jsxRuntime.jsx(material.IconButton, {
|
|
395
|
+
onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined,
|
|
396
|
+
children: props.icon
|
|
397
|
+
})
|
|
398
|
+
})
|
|
399
|
+
})
|
|
400
|
+
});
|
|
226
401
|
}
|
|
227
402
|
|
|
228
|
-
function ThumbnailListFilterTags(props) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
403
|
+
function ThumbnailListFilterTags(props) {
|
|
404
|
+
const {
|
|
405
|
+
tagFilterCallback,
|
|
406
|
+
tagAndCondition
|
|
407
|
+
} = useThumbnailListItemContext();
|
|
408
|
+
console.log('filter tags rerenders');
|
|
409
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
410
|
+
children: props.tags.map((tag, index) => {
|
|
411
|
+
return jsxRuntime.jsx(ThumbnailListFilterTag, {
|
|
412
|
+
label: tag.label,
|
|
413
|
+
value: tag.key.toString(),
|
|
414
|
+
variant: tagAndCondition.tag === tag.key ? 'filled' : 'outlined',
|
|
415
|
+
collapseBreakpoint: props.muiCollapseBreakpoint,
|
|
416
|
+
onClickCallback: value => tagFilterCallback({
|
|
417
|
+
tag: value,
|
|
418
|
+
condition: tag.condition
|
|
419
|
+
}),
|
|
420
|
+
icon: tag.icon
|
|
421
|
+
}, "".concat(index, "_").concat(tag.key.toString()));
|
|
422
|
+
})
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
ThumbnailListFilterTags.defaultProps = {
|
|
426
|
+
align: 'start',
|
|
427
|
+
muiCollapseBreakpoint: 'md'
|
|
238
428
|
};
|
|
239
429
|
|
|
240
|
-
/**
|
|
241
|
-
* Displays a generic MUI select dropdown.
|
|
242
|
-
* Optinal collapses to a sort icon at a certain breakpoint
|
|
243
|
-
* @param props.label Select Label
|
|
244
|
-
* @param props.width * Width of the input field
|
|
245
|
-
* @param props.collapseBreakPoint * MUI breakpoint after that the select will collapse to the sort icon
|
|
246
|
-
* @param props.onChangeCallback * Callback function that gets triggered once a item is selected
|
|
247
|
-
* @param props.items * Array of items (name-value-pairs) that will be the select options
|
|
248
|
-
* @returns Drowpdown Input Component
|
|
249
|
-
*/
|
|
250
|
-
function DropdownInput(props) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
430
|
+
/**
|
|
431
|
+
* Displays a generic MUI select dropdown.
|
|
432
|
+
* Optinal collapses to a sort icon at a certain breakpoint
|
|
433
|
+
* @param props.label Select Label
|
|
434
|
+
* @param props.width * Width of the input field
|
|
435
|
+
* @param props.collapseBreakPoint * MUI breakpoint after that the select will collapse to the sort icon
|
|
436
|
+
* @param props.onChangeCallback * Callback function that gets triggered once a item is selected
|
|
437
|
+
* @param props.items * Array of items (name-value-pairs) that will be the select options
|
|
438
|
+
* @returns Drowpdown Input Component
|
|
439
|
+
*/
|
|
440
|
+
function DropdownInput(props) {
|
|
441
|
+
var _props$defaultValue, _props$collapseBreakp;
|
|
442
|
+
const [value, setValue] = React.useState((_props$defaultValue = props.defaultValue) !== null && _props$defaultValue !== void 0 ? _props$defaultValue : '');
|
|
443
|
+
const theme = material.useTheme();
|
|
444
|
+
const [anchorEl, setAnchorEl] = React.useState(null);
|
|
445
|
+
const handleChange = (value, name) => {
|
|
446
|
+
setValue(value);
|
|
447
|
+
setAnchorEl(null);
|
|
448
|
+
props.onChangeCallback(value, name);
|
|
449
|
+
};
|
|
450
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
451
|
+
children: [material.useMediaQuery(theme.breakpoints.up((_props$collapseBreakp = props.collapseBreakpoint) !== null && _props$collapseBreakp !== void 0 ? _props$collapseBreakp : 0)) ? jsxRuntime.jsxs(material.FormControl, {
|
|
452
|
+
sx: {
|
|
453
|
+
width: props.width,
|
|
454
|
+
textAlign: 'start'
|
|
455
|
+
},
|
|
456
|
+
children: [jsxRuntime.jsx(material.InputLabel, {
|
|
457
|
+
size: "small",
|
|
458
|
+
children: props.label
|
|
459
|
+
}), jsxRuntime.jsx(material.Select, {
|
|
460
|
+
value: value,
|
|
461
|
+
size: "small",
|
|
462
|
+
label: props.label,
|
|
463
|
+
onChange: event => handleChange(event.target.value, event.target.name),
|
|
464
|
+
children: props.items.map(item => {
|
|
465
|
+
return jsxRuntime.jsx(material.MenuItem, {
|
|
466
|
+
value: item.value,
|
|
467
|
+
children: item.name
|
|
468
|
+
}, item.value);
|
|
469
|
+
})
|
|
470
|
+
})]
|
|
471
|
+
}) : jsxRuntime.jsx(material.IconButton
|
|
472
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
473
|
+
, {
|
|
474
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
475
|
+
onClick: event => setAnchorEl(event.currentTarget),
|
|
476
|
+
children: props.icon
|
|
477
|
+
}), jsxRuntime.jsx(material.Menu, {
|
|
478
|
+
anchorEl: anchorEl,
|
|
479
|
+
open: Boolean(anchorEl),
|
|
480
|
+
onClose: () => setAnchorEl(null),
|
|
481
|
+
children: props.items.map(item => jsxRuntime.jsx(material.MenuItem, {
|
|
482
|
+
onClick: () => handleChange(item.value),
|
|
483
|
+
children: item.name
|
|
484
|
+
}, item.value))
|
|
485
|
+
})]
|
|
486
|
+
});
|
|
266
487
|
}
|
|
267
488
|
|
|
268
|
-
function ThumbnailListHeaderSort(props) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
489
|
+
function ThumbnailListHeaderSort(props) {
|
|
490
|
+
const {
|
|
491
|
+
setSortAscending,
|
|
492
|
+
sortAscending,
|
|
493
|
+
setSortBy,
|
|
494
|
+
sortBy
|
|
495
|
+
} = useThumbnailListItemContext();
|
|
496
|
+
console.log('Header sort rerenders');
|
|
497
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
498
|
+
children: jsxRuntime.jsxs(material.Box, {
|
|
499
|
+
sx: {
|
|
500
|
+
minWidth: '80px'
|
|
501
|
+
},
|
|
502
|
+
children: [jsxRuntime.jsx(material.Tooltip, {
|
|
503
|
+
title: "asc/desc",
|
|
504
|
+
children: jsxRuntime.jsx(material.IconButton, {
|
|
505
|
+
onClick: () => setSortAscending(!sortAscending),
|
|
506
|
+
children: jsxRuntime.jsx(SwapVertIcon__default["default"], {})
|
|
507
|
+
})
|
|
508
|
+
}), jsxRuntime.jsx(DropdownInput, {
|
|
509
|
+
width: "130px",
|
|
510
|
+
collapseBreakpoint: props.muiBreakpoint,
|
|
511
|
+
label: 'sort',
|
|
512
|
+
defaultValue: sortBy,
|
|
513
|
+
icon: jsxRuntime.jsx(material.Tooltip, {
|
|
514
|
+
title: 'sort',
|
|
515
|
+
children: jsxRuntime.jsx(SortIcon__default["default"], {})
|
|
516
|
+
}),
|
|
517
|
+
items: props.items.map(i => {
|
|
518
|
+
return {
|
|
519
|
+
name: i.label,
|
|
520
|
+
value: i.key.toString()
|
|
521
|
+
};
|
|
522
|
+
}),
|
|
523
|
+
onChangeCallback: value => setSortBy(value)
|
|
524
|
+
})]
|
|
525
|
+
})
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
ThumbnailListHeaderSort.defaultProps = {
|
|
529
|
+
align: 'start',
|
|
530
|
+
muiBreakpoint: 'md'
|
|
278
531
|
};
|
|
279
532
|
|
|
280
|
-
const ThumbnailListHeader = function (props) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
533
|
+
const ThumbnailListHeader = function (props) {
|
|
534
|
+
var _props$justifyContent;
|
|
535
|
+
const startAlignedItems = [];
|
|
536
|
+
const endAlignedItems = [];
|
|
537
|
+
// Iterate through each child to categorize them based on their 'align' prop
|
|
538
|
+
React.Children.forEach(props.children, child => {
|
|
539
|
+
if ( /*#__PURE__*/React__default["default"].isValidElement(child)) {
|
|
540
|
+
const alignment = child.props.align || 'start';
|
|
541
|
+
if (alignment === 'end') {
|
|
542
|
+
endAlignedItems.push(child);
|
|
543
|
+
} else {
|
|
544
|
+
startAlignedItems.push(child);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
549
|
+
children: jsxRuntime.jsxs(material.Stack, {
|
|
550
|
+
direction: "row",
|
|
551
|
+
alignItems: "center",
|
|
552
|
+
justifyContent: (_props$justifyContent = props.justifyContent) !== null && _props$justifyContent !== void 0 ? _props$justifyContent : 'space-between',
|
|
553
|
+
gap: 2,
|
|
554
|
+
children: [jsxRuntime.jsx(material.Stack, {
|
|
555
|
+
direction: "row",
|
|
556
|
+
alignItems: "center",
|
|
557
|
+
gap: 2,
|
|
558
|
+
justifyContent: "start",
|
|
559
|
+
children: startAlignedItems
|
|
560
|
+
}), endAlignedItems]
|
|
561
|
+
})
|
|
562
|
+
});
|
|
563
|
+
};
|
|
564
|
+
ThumbnailListHeader.SearchField = ThumbnailListSearchField$1;
|
|
565
|
+
ThumbnailListHeader.FilterTags = ThumbnailListFilterTags;
|
|
299
566
|
ThumbnailListHeader.Sort = ThumbnailListHeaderSort;
|
|
300
567
|
|
|
301
|
-
/**
|
|
302
|
-
* Main Component: Renders all sub components
|
|
303
|
-
* Includes ThumbnailList Provider for context data
|
|
304
|
-
* @param props react children, items
|
|
305
|
-
* @returns component
|
|
306
|
-
*/
|
|
307
|
-
function ThumbnailList(props) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
568
|
+
/**
|
|
569
|
+
* Main Component: Renders all sub components
|
|
570
|
+
* Includes ThumbnailList Provider for context data
|
|
571
|
+
* @param props react children, items
|
|
572
|
+
* @returns component
|
|
573
|
+
*/
|
|
574
|
+
function ThumbnailList(props) {
|
|
575
|
+
const combinedConfig = {
|
|
576
|
+
...defaultConfiguration,
|
|
577
|
+
...props.config // This will override the defaults with any props that are not undefined
|
|
578
|
+
};
|
|
579
|
+
const [listItems, setListItems] = React.useState(props.items);
|
|
580
|
+
const {
|
|
581
|
+
sortedItems,
|
|
582
|
+
setSortBy,
|
|
583
|
+
setSortAscending,
|
|
584
|
+
sortAscending
|
|
585
|
+
} = useSortedThumbnailListItems(listItems, combinedConfig.sortBy.toString(), combinedConfig.sortAscending);
|
|
586
|
+
const {
|
|
587
|
+
tagFilteredItems,
|
|
588
|
+
setTagAndCondition,
|
|
589
|
+
tagAndCondition
|
|
590
|
+
} = useTagFilteredThumbnailListItems({
|
|
591
|
+
allItems: sortedItems,
|
|
592
|
+
initialTag: combinedConfig.tag.toString()
|
|
593
|
+
});
|
|
594
|
+
const {
|
|
595
|
+
setSearchTerm,
|
|
596
|
+
filteredItems
|
|
597
|
+
} = useFilteredThumbnailListItems(tagFilteredItems);
|
|
598
|
+
console.log('Thumbnaillist renders');
|
|
599
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
600
|
+
children: jsxRuntime.jsx(ThumbnailListItemContext.Provider, {
|
|
601
|
+
value: {
|
|
602
|
+
items: filteredItems,
|
|
603
|
+
setItems: setListItems,
|
|
604
|
+
originalItems: listItems,
|
|
605
|
+
setOriginalItems: setListItems,
|
|
606
|
+
tagFilterCallback: setTagAndCondition,
|
|
607
|
+
tagAndCondition: tagAndCondition,
|
|
608
|
+
setSearchTerm: setSearchTerm,
|
|
609
|
+
setSortAscending: setSortAscending,
|
|
610
|
+
sortAscending: sortAscending,
|
|
611
|
+
setSortBy: setSortBy,
|
|
612
|
+
sortBy: combinedConfig.sortBy.toString(),
|
|
613
|
+
isLoading: false
|
|
614
|
+
},
|
|
615
|
+
children: jsxRuntime.jsx(material.Stack, {
|
|
616
|
+
direction: "column",
|
|
617
|
+
sx: {
|
|
618
|
+
width: '100%',
|
|
619
|
+
minWidth: '425px'
|
|
620
|
+
},
|
|
621
|
+
children: props.children
|
|
622
|
+
})
|
|
623
|
+
})
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
ThumbnailList.MainContent = ThumbnailListMainContent;
|
|
333
627
|
ThumbnailList.Header = ThumbnailListHeader;
|
|
334
628
|
|
|
335
629
|
exports.ThumbnailList = ThumbnailList;
|