@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 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
- const context = React.useContext(ThumbnailListItemContext);
26
- if (!context) {
27
- throw new Error('no context provider available');
28
- }
29
- return context;
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
- 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, { children: props.children });
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
- const StyledCardContent = material.styled('div')((p) => ({
57
- [p.theme.breakpoints.up('xs')]: {
58
- padding: p.theme.spacing(1),
59
- flex: '1 0 auto',
60
- '&:last-child': { paddingBottom: 0 },
61
- overflow: 'hidden',
62
- },
63
- }));
64
- console.log('item title rerenders');
65
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(material.Box, { children: jsxRuntime.jsxs(StyledCardContent, { children: [jsxRuntime.jsx(EllipsisContainer, { lineClamp: { xs: 1, sm: 2 }, children: jsxRuntime.jsx(material.Typography, { variant: "subtitle2", sx: { fontWeight: 'bold' }, children: props.title }) }), jsxRuntime.jsx(system.Stack, { direction: "row", gap: 1, children: jsxRuntime.jsx(EllipsisContainer, { lineClamp: { xs: 1, sm: 2 }, children: jsxRuntime.jsx(material.Typography, { variant: "subtitle2", sx: { fontSize: '0.84rem' }, color: "text.secondary", children: props.subTitle }) }) })] }) }) }));
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 = (props) => {
69
- console.log('ThumbnailListItems renders');
70
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(material.Card, { sx: { display: 'flex' }, children: jsxRuntime.jsx(material.CardActionArea, { disabled: !props.onClick, onClick: () => props.onClick(props.id), children: jsxRuntime.jsxs(material.Stack, { direction: "row", width: "100%", children: [jsxRuntime.jsx("img", { src: props.thumbnailUrl, width: '45%' }), jsxRuntime.jsxs(material.Stack, { direction: "row", justifyContent: "space-between", width: "100%", gap: 1, children: [jsxRuntime.jsx(ThumbnailListItemTitle, { title: props.title, subTitle: props.subTitle }), props.infoLabel] })] }) }) }) }));
71
- };
72
- var ThumbnailListItem$1 = React__default["default"].memo(ThumbnailListItem);
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
- // Assuming a 16:9 aspect ratio
76
- paddingTop: '27.75%',
77
- position: 'relative',
78
- width: '100%',
79
- '& > *': {
80
- position: 'absolute',
81
- top: 0,
82
- left: 0,
83
- right: 0,
84
- bottom: 0,
85
- },
86
- }));
87
- function ThumbnailListMainContent(props) {
88
- const { items, isLoading } = useThumbnailListItemContext();
89
- console.log('main content rerenders');
90
- const memoizedItems = React.useMemo(() => {
91
- return items.map((item) => (jsxRuntime.jsx(material.Grid, { item: true, xs: props.muiBreakpoints.xs, sm: props.muiBreakpoints.sm, md: props.muiBreakpoints.md, lg: props.muiBreakpoints.lg, xl: props.muiBreakpoints.xl, children: jsxRuntime.jsx(RatioWrapper, { children: jsxRuntime.jsx(ThumbnailListItem$1, { id: item.id, thumbnailUrl: item.thumbnailUrl, title: item.title, subTitle: item.subTitle, infoLabel: item.label, onClick: item.onClick }) }) }, item.id)));
92
- }, [items, props.muiBreakpoints]);
93
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(material.Box, { sx: { mt: 0.75, mb: 0.75 }, children: jsxRuntime.jsx(material.LinearProgress, { sx: { opacity: isLoading ? 1 : 0 } }) }), jsxRuntime.jsx(material.Grid, { container: true, spacing: props.spacing, children: memoizedItems })] }));
94
- }
95
- ThumbnailListMainContent.defaultProps = {
96
- spacing: 2,
97
- muiBreakpoints: { xs: 12, sm: 6, md: 6, lg: 4, xl: 3 },
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
- return [...values].sort((a, b) => {
108
- const valueA = getComparableValue(a[orderType]);
109
- const valueB = getComparableValue(b[orderType]);
110
- return compareValues(valueA, valueB);
111
- });
112
- }
113
- function getComparableValue(value) {
114
- if (typeof value === 'number') {
115
- return value;
116
- }
117
- else {
118
- return String(value);
119
- }
120
- }
121
- function compareValues(a, b) {
122
- if (typeof a === 'string' && typeof b === 'string') {
123
- return a.localeCompare(b, undefined, { sensitivity: 'base' });
124
- }
125
- else {
126
- return a < b ? -1 : a > b ? 1 : 0;
127
- }
128
- }
129
- function filterByTag(array, tagType, condition) {
130
- const filteredArray = array.filter((item) => {
131
- const tagValue = item[tagType];
132
- return condition ? condition(tagValue) : !!tagValue;
133
- });
134
- console.log('filter array');
135
- console.log(filteredArray);
136
- return [...filteredArray];
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 = ({ allItems, initialTag, initialCondition, }) => {
140
- const [tagAndCondition, setTagAndCondition] = React.useState({ tag: initialTag, condition: initialCondition });
141
- const setTagWithCondition = (t, c) => {
142
- setTagAndCondition({ tag: t, condition: c });
143
- };
144
- const tagFilteredItems = React.useMemo(() => {
145
- const tagFiltered = tagAndCondition.tag === 'id'
146
- ? allItems
147
- : filterByTag(allItems, tagAndCondition.tag, tagAndCondition.condition);
148
- return tagFiltered;
149
- }, [allItems, tagAndCondition]);
150
- return {
151
- tagAndCondition,
152
- setTagAndCondition,
153
- tagFilteredItems,
154
- setTagWithCondition,
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, initialSearchTerm = '') => {
165
- const [searchTerm, setSearchTerm] = React.useState(initialSearchTerm);
166
- const filteredItems = React.useMemo(() => {
167
- const filtered = [...allItems].filter((item) => item.title.toLowerCase().includes(searchTerm.toLowerCase()));
168
- return filtered;
169
- }, [allItems, searchTerm]);
170
- return { searchTerm, setSearchTerm, filteredItems };
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
- const [sortBy, setSortBy] = React.useState(initialSortBy);
175
- const [sortAscending, setSortAscending] = React.useState(initialSortAscending);
176
- const sortedItems = React.useMemo(() => {
177
- let sorted = orderByArray(allItems, sortBy);
178
- if (!sortAscending) {
179
- sorted = sorted.reverse();
180
- }
181
- return sorted;
182
- }, [allItems, sortBy, sortAscending]);
183
- return { sortBy, sortAscending, setSortBy, setSortAscending, sortedItems };
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
- sortBy: 'id',
188
- sortAscending: true,
189
- tag: 'id',
315
+ const defaultConfiguration = {
316
+ sortBy: 'id',
317
+ sortAscending: true,
318
+ tag: 'id'
190
319
  };
191
320
 
192
- const ThumbnailListSearchField = () => {
193
- const [input, setInput] = React.useState('');
194
- const [showClearIcon, setShowClearIcon] = React.useState('hidden');
195
- const { setSearchTerm } = useThumbnailListItemContext();
196
- console.log('Searchfield rerenders');
197
- const handleChange = (value) => {
198
- setInput(value);
199
- setShowClearIcon(value === '' ? 'hidden' : '');
200
- };
201
- const debouncedSetSearchTerm = React.useCallback(lodash.debounce(setSearchTerm, 50), []);
202
- React.useEffect(() => {
203
- debouncedSetSearchTerm(input);
204
- return () => {
205
- debouncedSetSearchTerm.cancel();
206
- };
207
- }, [input, debouncedSetSearchTerm]);
208
- return (jsxRuntime.jsx(material.Box, { sx: { marginLeft: 'auto' }, children: jsxRuntime.jsx(material.FormControl, { children: jsxRuntime.jsx(material.TextField, { fullWidth: true, value: input, size: "small", variant: "outlined", onChange: (event) => handleChange(event.target.value), InputProps: {
209
- startAdornment: (jsxRuntime.jsx(material.InputAdornment, { position: "start", children: jsxRuntime.jsx(SearchIcon__default["default"], {}) })),
210
- endAdornment: (jsxRuntime.jsx(material.InputAdornment, { position: "end", children: jsxRuntime.jsx(material.IconButton, { onClick: () => handleChange(''), sx: { visibility: showClearIcon, padding: 0 }, children: jsxRuntime.jsx(ClearIcon__default["default"], {}) }) })),
211
- } }) }) }));
212
- };
213
- ThumbnailListSearchField.defaultProps = {
214
- align: 'start',
215
- };
216
- var ThumbnailListSearchField$1 = React__default["default"].memo(ThumbnailListSearchField);
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
- const theme = material.useTheme();
220
- const handleOnClick = (value) => {
221
- if (props.onClickCallback) {
222
- props.onClickCallback(value);
223
- }
224
- };
225
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: material.useMediaQuery(theme.breakpoints.up(props.collapseBreakpoint ?? 0)) || !props.icon ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(material.Chip, { label: props.label, variant: props.variant, onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined }) })) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(material.Tooltip, { title: props.label, children: jsxRuntime.jsx(material.IconButton, { onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined, children: props.icon }) }) })) }));
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
- const { tagFilterCallback, tagAndCondition } = useThumbnailListItemContext();
230
- console.log('filter tags rerenders');
231
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.tags.map((tag, index) => {
232
- return (jsxRuntime.jsx(ThumbnailListFilterTag, { label: tag.label, value: tag.key.toString(), variant: tagAndCondition.tag === tag.key ? 'filled' : 'outlined', collapseBreakpoint: props.muiCollapseBreakpoint, onClickCallback: (value) => tagFilterCallback({ tag: value, condition: tag.condition }), icon: tag.icon }, `${index}_${tag.key.toString()}`));
233
- }) }));
234
- }
235
- ThumbnailListFilterTags.defaultProps = {
236
- align: 'start',
237
- muiCollapseBreakpoint: 'md',
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
- const [value, setValue] = React.useState(props.defaultValue ?? '');
252
- const theme = material.useTheme();
253
- const [anchorEl, setAnchorEl] = React.useState(null);
254
- const handleChange = (value, name) => {
255
- setValue(value);
256
- setAnchorEl(null);
257
- props.onChangeCallback(value, name);
258
- };
259
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [material.useMediaQuery(theme.breakpoints.up(props.collapseBreakpoint ?? 0)) ? (jsxRuntime.jsxs(material.FormControl, { sx: { width: props.width, textAlign: 'start' }, children: [jsxRuntime.jsx(material.InputLabel, { size: "small", children: props.label }), jsxRuntime.jsx(material.Select, { value: value, size: "small", label: props.label, onChange: (event) => handleChange(event.target.value, event.target.name), children: props.items.map((item) => {
260
- return (jsxRuntime.jsx(material.MenuItem, { value: item.value, children: item.name }, item.value));
261
- }) })] })) : (jsxRuntime.jsx(material.IconButton
262
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
263
- , {
264
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
265
- onClick: (event) => setAnchorEl(event.currentTarget), children: props.icon })), jsxRuntime.jsx(material.Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: () => setAnchorEl(null), children: props.items.map((item) => (jsxRuntime.jsx(material.MenuItem, { onClick: () => handleChange(item.value), children: item.name }, item.value))) })] }));
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
- const { setSortAscending, sortAscending, setSortBy, sortBy } = useThumbnailListItemContext();
270
- console.log('Header sort rerenders');
271
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(material.Box, { sx: { minWidth: '80px' }, children: [jsxRuntime.jsx(material.Tooltip, { title: "asc/desc", children: jsxRuntime.jsx(material.IconButton, { onClick: () => setSortAscending(!sortAscending), children: jsxRuntime.jsx(SwapVertIcon__default["default"], {}) }) }), jsxRuntime.jsx(DropdownInput, { width: "130px", collapseBreakpoint: props.muiBreakpoint, label: 'sort', defaultValue: sortBy, icon: jsxRuntime.jsx(material.Tooltip, { title: 'sort', children: jsxRuntime.jsx(SortIcon__default["default"], {}) }), items: props.items.map((i) => {
272
- return { name: i.label, value: i.key.toString() };
273
- }), onChangeCallback: (value) => setSortBy(value) })] }) }));
274
- }
275
- ThumbnailListHeaderSort.defaultProps = {
276
- align: 'start',
277
- muiBreakpoint: 'md',
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
- const startAlignedItems = [];
282
- const endAlignedItems = [];
283
- // Iterate through each child to categorize them based on their 'align' prop
284
- React.Children.forEach(props.children, (child) => {
285
- if (React__default["default"].isValidElement(child)) {
286
- const alignment = child.props.align || 'start';
287
- if (alignment === 'end') {
288
- endAlignedItems.push(child);
289
- }
290
- else {
291
- startAlignedItems.push(child);
292
- }
293
- }
294
- });
295
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(material.Stack, { direction: "row", alignItems: "center", justifyContent: props.justifyContent ?? 'space-between', gap: 2, children: [jsxRuntime.jsx(material.Stack, { direction: "row", alignItems: "center", gap: 2, justifyContent: "start", children: startAlignedItems }), endAlignedItems] }) }));
296
- };
297
- ThumbnailListHeader.SearchField = ThumbnailListSearchField$1;
298
- ThumbnailListHeader.FilterTags = ThumbnailListFilterTags;
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
- const combinedConfig = {
309
- ...defaultConfiguration,
310
- ...props.config, // This will override the defaults with any props that are not undefined
311
- };
312
- const [listItems, setListItems] = React.useState(props.items);
313
- const { sortedItems, setSortBy, setSortAscending, sortAscending } = useSortedThumbnailListItems(listItems, combinedConfig.sortBy.toString(), combinedConfig.sortAscending);
314
- const { tagFilteredItems, setTagAndCondition, tagAndCondition } = useTagFilteredThumbnailListItems({ allItems: sortedItems, initialTag: combinedConfig.tag.toString() });
315
- const { setSearchTerm, filteredItems } = useFilteredThumbnailListItems(tagFilteredItems);
316
- console.log('Thumbnaillist renders');
317
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ThumbnailListItemContext.Provider, { value: {
318
- items: filteredItems,
319
- setItems: setListItems,
320
- originalItems: listItems,
321
- setOriginalItems: setListItems,
322
- tagFilterCallback: setTagAndCondition,
323
- tagAndCondition: tagAndCondition,
324
- setSearchTerm: setSearchTerm,
325
- setSortAscending: setSortAscending,
326
- sortAscending: sortAscending,
327
- setSortBy: setSortBy,
328
- sortBy: combinedConfig.sortBy.toString(),
329
- isLoading: false,
330
- }, children: jsxRuntime.jsx(material.Stack, { direction: "column", sx: { width: '100%', minWidth: '425px' }, children: props.children }) }) }));
331
- }
332
- ThumbnailList.MainContent = ThumbnailListMainContent;
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;