@janrankenhohn/react-thumbnail-list 0.4.0 → 0.5.1
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/README.md +1 -70
- package/dist/index.cjs.js +323 -3
- package/dist/index.esm.js +320 -4
- package/package.json +83 -61
package/README.md
CHANGED
|
@@ -1,70 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
|
4
|
-
|
|
5
|
-
## Available Scripts
|
|
6
|
-
|
|
7
|
-
In the project directory, you can run:
|
|
8
|
-
|
|
9
|
-
### `npm start`
|
|
10
|
-
|
|
11
|
-
Runs the app in the development mode.\
|
|
12
|
-
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
|
13
|
-
|
|
14
|
-
The page will reload when you make changes.\
|
|
15
|
-
You may also see any lint errors in the console.
|
|
16
|
-
|
|
17
|
-
### `npm test`
|
|
18
|
-
|
|
19
|
-
Launches the test runner in the interactive watch mode.\
|
|
20
|
-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
|
21
|
-
|
|
22
|
-
### `npm run build`
|
|
23
|
-
|
|
24
|
-
Builds the app for production to the `build` folder.\
|
|
25
|
-
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
26
|
-
|
|
27
|
-
The build is minified and the filenames include the hashes.\
|
|
28
|
-
Your app is ready to be deployed!
|
|
29
|
-
|
|
30
|
-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
|
31
|
-
|
|
32
|
-
### `npm run eject`
|
|
33
|
-
|
|
34
|
-
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
|
35
|
-
|
|
36
|
-
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
|
37
|
-
|
|
38
|
-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
|
39
|
-
|
|
40
|
-
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
|
41
|
-
|
|
42
|
-
## Learn More
|
|
43
|
-
|
|
44
|
-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
|
45
|
-
|
|
46
|
-
To learn React, check out the [React documentation](https://reactjs.org/).
|
|
47
|
-
|
|
48
|
-
### Code Splitting
|
|
49
|
-
|
|
50
|
-
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
|
51
|
-
|
|
52
|
-
### Analyzing the Bundle Size
|
|
53
|
-
|
|
54
|
-
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
|
55
|
-
|
|
56
|
-
### Making a Progressive Web App
|
|
57
|
-
|
|
58
|
-
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
|
59
|
-
|
|
60
|
-
### Advanced Configuration
|
|
61
|
-
|
|
62
|
-
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
|
63
|
-
|
|
64
|
-
### Deployment
|
|
65
|
-
|
|
66
|
-
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
|
67
|
-
|
|
68
|
-
### `npm run build` fails to minify
|
|
69
|
-
|
|
70
|
-
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
|
1
|
+
react-tumbnail-list
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,14 +2,334 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var material = require('@mui/material');
|
|
5
7
|
var React = require('react');
|
|
8
|
+
var system = require('@mui/system');
|
|
9
|
+
var SearchIcon = require('@mui/icons-material/Search');
|
|
10
|
+
var ClearIcon = require('@mui/icons-material/Clear');
|
|
11
|
+
var lodash = require('lodash');
|
|
12
|
+
var SwapVertIcon = require('@mui/icons-material/SwapVert');
|
|
13
|
+
var SortIcon = require('@mui/icons-material/Sort');
|
|
6
14
|
|
|
7
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
16
|
|
|
9
17
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
|
+
var SearchIcon__default = /*#__PURE__*/_interopDefaultLegacy(SearchIcon);
|
|
19
|
+
var ClearIcon__default = /*#__PURE__*/_interopDefaultLegacy(ClearIcon);
|
|
20
|
+
var SwapVertIcon__default = /*#__PURE__*/_interopDefaultLegacy(SwapVertIcon);
|
|
21
|
+
var SortIcon__default = /*#__PURE__*/_interopDefaultLegacy(SortIcon);
|
|
10
22
|
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
30
|
+
};
|
|
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 });
|
|
53
|
+
}
|
|
54
|
+
|
|
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 }) }) })] }) }) }));
|
|
66
|
+
}
|
|
67
|
+
|
|
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);
|
|
73
|
+
|
|
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 },
|
|
98
|
+
};
|
|
99
|
+
|
|
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];
|
|
137
|
+
}
|
|
138
|
+
|
|
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
|
+
};
|
|
156
|
+
};
|
|
157
|
+
|
|
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 };
|
|
171
|
+
};
|
|
172
|
+
|
|
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 };
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const defaultConfiguration = {
|
|
187
|
+
sortBy: 'id',
|
|
188
|
+
sortAscending: true,
|
|
189
|
+
tag: 'id',
|
|
190
|
+
};
|
|
191
|
+
|
|
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);
|
|
217
|
+
|
|
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 }) }) })) }));
|
|
226
|
+
}
|
|
227
|
+
|
|
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',
|
|
238
|
+
};
|
|
239
|
+
|
|
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))) })] }));
|
|
13
266
|
}
|
|
14
267
|
|
|
15
|
-
|
|
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',
|
|
278
|
+
};
|
|
279
|
+
|
|
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;
|
|
299
|
+
ThumbnailListHeader.Sort = ThumbnailListHeaderSort;
|
|
300
|
+
|
|
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;
|
|
333
|
+
ThumbnailList.Header = ThumbnailListHeader;
|
|
334
|
+
|
|
335
|
+
exports.ThumbnailList = ThumbnailList;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,323 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { styled, Box, Typography, Card, CardActionArea, Stack as Stack$1, Grid, LinearProgress, FormControl, TextField, InputAdornment, IconButton, useTheme, useMediaQuery, Chip, Tooltip, InputLabel, Select, MenuItem, Menu } from '@mui/material';
|
|
3
|
+
import React, { createContext, useContext, useMemo, useState, useCallback, useEffect, Children } from 'react';
|
|
4
|
+
import { Stack } from '@mui/system';
|
|
5
|
+
import SearchIcon from '@mui/icons-material/Search';
|
|
6
|
+
import ClearIcon from '@mui/icons-material/Clear';
|
|
7
|
+
import { debounce } from 'lodash';
|
|
8
|
+
import SwapVertIcon from '@mui/icons-material/SwapVert';
|
|
9
|
+
import SortIcon from '@mui/icons-material/Sort';
|
|
2
10
|
|
|
3
|
-
|
|
4
|
-
|
|
11
|
+
const ThumbnailListItemContext = createContext(undefined);
|
|
12
|
+
const useThumbnailListItemContext = () => {
|
|
13
|
+
const context = useContext(ThumbnailListItemContext);
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error('no context provider available');
|
|
16
|
+
}
|
|
17
|
+
return context;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates a ellipies text with webkit css styles
|
|
22
|
+
* @param props lineClamp: lines till ellipses
|
|
23
|
+
* @returns component
|
|
24
|
+
*/
|
|
25
|
+
function EllipsisContainer(props) {
|
|
26
|
+
const EllipsisContainer = styled('div')((p) => ({
|
|
27
|
+
[p.theme.breakpoints.up('xs')]: {
|
|
28
|
+
overflow: 'hidden',
|
|
29
|
+
display: '-webkit-box',
|
|
30
|
+
WebkitLineClamp: props.lineClamp.xs.toString() /* number of lines to show */,
|
|
31
|
+
WebkitBoxOrient: 'vertical',
|
|
32
|
+
},
|
|
33
|
+
[p.theme.breakpoints.up('sm')]: {
|
|
34
|
+
overflow: 'hidden',
|
|
35
|
+
display: '-webkit-box',
|
|
36
|
+
WebkitLineClamp: props.lineClamp.sm.toString() /* number of lines to show */,
|
|
37
|
+
WebkitBoxOrient: 'vertical' /* number of lines to show */,
|
|
38
|
+
},
|
|
39
|
+
}));
|
|
40
|
+
return jsx(EllipsisContainer, { children: props.children });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ThumbnailListItemTitle(props) {
|
|
44
|
+
const StyledCardContent = styled('div')((p) => ({
|
|
45
|
+
[p.theme.breakpoints.up('xs')]: {
|
|
46
|
+
padding: p.theme.spacing(1),
|
|
47
|
+
flex: '1 0 auto',
|
|
48
|
+
'&:last-child': { paddingBottom: 0 },
|
|
49
|
+
overflow: 'hidden',
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
console.log('item title rerenders');
|
|
53
|
+
return (jsx(Fragment, { children: jsx(Box, { children: jsxs(StyledCardContent, { children: [jsx(EllipsisContainer, { lineClamp: { xs: 1, sm: 2 }, children: jsx(Typography, { variant: "subtitle2", sx: { fontWeight: 'bold' }, children: props.title }) }), jsx(Stack, { direction: "row", gap: 1, children: jsx(EllipsisContainer, { lineClamp: { xs: 1, sm: 2 }, children: jsx(Typography, { variant: "subtitle2", sx: { fontSize: '0.84rem' }, color: "text.secondary", children: props.subTitle }) }) })] }) }) }));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const ThumbnailListItem = (props) => {
|
|
57
|
+
console.log('ThumbnailListItems renders');
|
|
58
|
+
return (jsx(Fragment, { children: jsx(Card, { sx: { display: 'flex' }, children: jsx(CardActionArea, { disabled: !props.onClick, onClick: () => props.onClick(props.id), children: jsxs(Stack$1, { direction: "row", width: "100%", children: [jsx("img", { src: props.thumbnailUrl, width: '45%' }), jsxs(Stack$1, { direction: "row", justifyContent: "space-between", width: "100%", gap: 1, children: [jsx(ThumbnailListItemTitle, { title: props.title, subTitle: props.subTitle }), props.infoLabel] })] }) }) }) }));
|
|
59
|
+
};
|
|
60
|
+
var ThumbnailListItem$1 = React.memo(ThumbnailListItem);
|
|
61
|
+
|
|
62
|
+
const RatioWrapper = styled('div')(() => ({
|
|
63
|
+
// Assuming a 16:9 aspect ratio
|
|
64
|
+
paddingTop: '27.75%',
|
|
65
|
+
position: 'relative',
|
|
66
|
+
width: '100%',
|
|
67
|
+
'& > *': {
|
|
68
|
+
position: 'absolute',
|
|
69
|
+
top: 0,
|
|
70
|
+
left: 0,
|
|
71
|
+
right: 0,
|
|
72
|
+
bottom: 0,
|
|
73
|
+
},
|
|
74
|
+
}));
|
|
75
|
+
function ThumbnailListMainContent(props) {
|
|
76
|
+
const { items, isLoading } = useThumbnailListItemContext();
|
|
77
|
+
console.log('main content rerenders');
|
|
78
|
+
const memoizedItems = useMemo(() => {
|
|
79
|
+
return items.map((item) => (jsx(Grid, { item: true, xs: props.muiBreakpoints.xs, sm: props.muiBreakpoints.sm, md: props.muiBreakpoints.md, lg: props.muiBreakpoints.lg, xl: props.muiBreakpoints.xl, children: jsx(RatioWrapper, { children: jsx(ThumbnailListItem$1, { id: item.id, thumbnailUrl: item.thumbnailUrl, title: item.title, subTitle: item.subTitle, infoLabel: item.label, onClick: item.onClick }) }) }, item.id)));
|
|
80
|
+
}, [items, props.muiBreakpoints]);
|
|
81
|
+
return (jsxs(Fragment, { children: [jsx(Box, { sx: { mt: 0.75, mb: 0.75 }, children: jsx(LinearProgress, { sx: { opacity: isLoading ? 1 : 0 } }) }), jsx(Grid, { container: true, spacing: props.spacing, children: memoizedItems })] }));
|
|
82
|
+
}
|
|
83
|
+
ThumbnailListMainContent.defaultProps = {
|
|
84
|
+
spacing: 2,
|
|
85
|
+
muiBreakpoints: { xs: 12, sm: 6, md: 6, lg: 4, xl: 3 },
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Generic method that sorts an array of items based on an item key
|
|
90
|
+
* @param values The array that should be sorted
|
|
91
|
+
* @param orderType The key of the entity that the array should be sorted by
|
|
92
|
+
* @returns A new reference of the ordered array
|
|
93
|
+
*/
|
|
94
|
+
function orderByArray(values, orderType) {
|
|
95
|
+
return [...values].sort((a, b) => {
|
|
96
|
+
const valueA = getComparableValue(a[orderType]);
|
|
97
|
+
const valueB = getComparableValue(b[orderType]);
|
|
98
|
+
return compareValues(valueA, valueB);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function getComparableValue(value) {
|
|
102
|
+
if (typeof value === 'number') {
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return String(value);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function compareValues(a, b) {
|
|
110
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
111
|
+
return a.localeCompare(b, undefined, { sensitivity: 'base' });
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function filterByTag(array, tagType, condition) {
|
|
118
|
+
const filteredArray = array.filter((item) => {
|
|
119
|
+
const tagValue = item[tagType];
|
|
120
|
+
return condition ? condition(tagValue) : !!tagValue;
|
|
121
|
+
});
|
|
122
|
+
console.log('filter array');
|
|
123
|
+
console.log(filteredArray);
|
|
124
|
+
return [...filteredArray];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const useTagFilteredThumbnailListItems = ({ allItems, initialTag, initialCondition, }) => {
|
|
128
|
+
const [tagAndCondition, setTagAndCondition] = useState({ tag: initialTag, condition: initialCondition });
|
|
129
|
+
const setTagWithCondition = (t, c) => {
|
|
130
|
+
setTagAndCondition({ tag: t, condition: c });
|
|
131
|
+
};
|
|
132
|
+
const tagFilteredItems = useMemo(() => {
|
|
133
|
+
const tagFiltered = tagAndCondition.tag === 'id'
|
|
134
|
+
? allItems
|
|
135
|
+
: filterByTag(allItems, tagAndCondition.tag, tagAndCondition.condition);
|
|
136
|
+
return tagFiltered;
|
|
137
|
+
}, [allItems, tagAndCondition]);
|
|
138
|
+
return {
|
|
139
|
+
tagAndCondition,
|
|
140
|
+
setTagAndCondition,
|
|
141
|
+
tagFilteredItems,
|
|
142
|
+
setTagWithCondition,
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Filters a list of event by a search term
|
|
148
|
+
* @param allEvents event list that will be formatted
|
|
149
|
+
* @param initialSearchTerm
|
|
150
|
+
* @returns
|
|
151
|
+
*/
|
|
152
|
+
const useFilteredThumbnailListItems = (allItems, initialSearchTerm = '') => {
|
|
153
|
+
const [searchTerm, setSearchTerm] = useState(initialSearchTerm);
|
|
154
|
+
const filteredItems = useMemo(() => {
|
|
155
|
+
const filtered = [...allItems].filter((item) => item.title.toLowerCase().includes(searchTerm.toLowerCase()));
|
|
156
|
+
return filtered;
|
|
157
|
+
}, [allItems, searchTerm]);
|
|
158
|
+
return { searchTerm, setSearchTerm, filteredItems };
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const useSortedThumbnailListItems = (allItems, initialSortBy, initialSortAscending) => {
|
|
162
|
+
const [sortBy, setSortBy] = useState(initialSortBy);
|
|
163
|
+
const [sortAscending, setSortAscending] = useState(initialSortAscending);
|
|
164
|
+
const sortedItems = useMemo(() => {
|
|
165
|
+
let sorted = orderByArray(allItems, sortBy);
|
|
166
|
+
if (!sortAscending) {
|
|
167
|
+
sorted = sorted.reverse();
|
|
168
|
+
}
|
|
169
|
+
return sorted;
|
|
170
|
+
}, [allItems, sortBy, sortAscending]);
|
|
171
|
+
return { sortBy, sortAscending, setSortBy, setSortAscending, sortedItems };
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const defaultConfiguration = {
|
|
175
|
+
sortBy: 'id',
|
|
176
|
+
sortAscending: true,
|
|
177
|
+
tag: 'id',
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const ThumbnailListSearchField = () => {
|
|
181
|
+
const [input, setInput] = useState('');
|
|
182
|
+
const [showClearIcon, setShowClearIcon] = useState('hidden');
|
|
183
|
+
const { setSearchTerm } = useThumbnailListItemContext();
|
|
184
|
+
console.log('Searchfield rerenders');
|
|
185
|
+
const handleChange = (value) => {
|
|
186
|
+
setInput(value);
|
|
187
|
+
setShowClearIcon(value === '' ? 'hidden' : '');
|
|
188
|
+
};
|
|
189
|
+
const debouncedSetSearchTerm = useCallback(debounce(setSearchTerm, 50), []);
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
debouncedSetSearchTerm(input);
|
|
192
|
+
return () => {
|
|
193
|
+
debouncedSetSearchTerm.cancel();
|
|
194
|
+
};
|
|
195
|
+
}, [input, debouncedSetSearchTerm]);
|
|
196
|
+
return (jsx(Box, { sx: { marginLeft: 'auto' }, children: jsx(FormControl, { children: jsx(TextField, { fullWidth: true, value: input, size: "small", variant: "outlined", onChange: (event) => handleChange(event.target.value), InputProps: {
|
|
197
|
+
startAdornment: (jsx(InputAdornment, { position: "start", children: jsx(SearchIcon, {}) })),
|
|
198
|
+
endAdornment: (jsx(InputAdornment, { position: "end", children: jsx(IconButton, { onClick: () => handleChange(''), sx: { visibility: showClearIcon, padding: 0 }, children: jsx(ClearIcon, {}) }) })),
|
|
199
|
+
} }) }) }));
|
|
200
|
+
};
|
|
201
|
+
ThumbnailListSearchField.defaultProps = {
|
|
202
|
+
align: 'start',
|
|
203
|
+
};
|
|
204
|
+
var ThumbnailListSearchField$1 = React.memo(ThumbnailListSearchField);
|
|
205
|
+
|
|
206
|
+
function ThumbnailListFilterTag(props) {
|
|
207
|
+
const theme = useTheme();
|
|
208
|
+
const handleOnClick = (value) => {
|
|
209
|
+
if (props.onClickCallback) {
|
|
210
|
+
props.onClickCallback(value);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
return (jsx(Fragment, { children: useMediaQuery(theme.breakpoints.up(props.collapseBreakpoint ?? 0)) || !props.icon ? (jsx(Fragment, { children: jsx(Chip, { label: props.label, variant: props.variant, onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined }) })) : (jsx(Fragment, { children: jsx(Tooltip, { title: props.label, children: jsx(IconButton, { onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined, children: props.icon }) }) })) }));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function ThumbnailListFilterTags(props) {
|
|
217
|
+
const { tagFilterCallback, tagAndCondition } = useThumbnailListItemContext();
|
|
218
|
+
console.log('filter tags rerenders');
|
|
219
|
+
return (jsx(Fragment, { children: props.tags.map((tag, index) => {
|
|
220
|
+
return (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()}`));
|
|
221
|
+
}) }));
|
|
222
|
+
}
|
|
223
|
+
ThumbnailListFilterTags.defaultProps = {
|
|
224
|
+
align: 'start',
|
|
225
|
+
muiCollapseBreakpoint: 'md',
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Displays a generic MUI select dropdown.
|
|
230
|
+
* Optinal collapses to a sort icon at a certain breakpoint
|
|
231
|
+
* @param props.label Select Label
|
|
232
|
+
* @param props.width * Width of the input field
|
|
233
|
+
* @param props.collapseBreakPoint * MUI breakpoint after that the select will collapse to the sort icon
|
|
234
|
+
* @param props.onChangeCallback * Callback function that gets triggered once a item is selected
|
|
235
|
+
* @param props.items * Array of items (name-value-pairs) that will be the select options
|
|
236
|
+
* @returns Drowpdown Input Component
|
|
237
|
+
*/
|
|
238
|
+
function DropdownInput(props) {
|
|
239
|
+
const [value, setValue] = useState(props.defaultValue ?? '');
|
|
240
|
+
const theme = useTheme();
|
|
241
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
242
|
+
const handleChange = (value, name) => {
|
|
243
|
+
setValue(value);
|
|
244
|
+
setAnchorEl(null);
|
|
245
|
+
props.onChangeCallback(value, name);
|
|
246
|
+
};
|
|
247
|
+
return (jsxs(Fragment, { children: [useMediaQuery(theme.breakpoints.up(props.collapseBreakpoint ?? 0)) ? (jsxs(FormControl, { sx: { width: props.width, textAlign: 'start' }, children: [jsx(InputLabel, { size: "small", children: props.label }), jsx(Select, { value: value, size: "small", label: props.label, onChange: (event) => handleChange(event.target.value, event.target.name), children: props.items.map((item) => {
|
|
248
|
+
return (jsx(MenuItem, { value: item.value, children: item.name }, item.value));
|
|
249
|
+
}) })] })) : (jsx(IconButton
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
251
|
+
, {
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
253
|
+
onClick: (event) => setAnchorEl(event.currentTarget), children: props.icon })), jsx(Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: () => setAnchorEl(null), children: props.items.map((item) => (jsx(MenuItem, { onClick: () => handleChange(item.value), children: item.name }, item.value))) })] }));
|
|
5
254
|
}
|
|
6
255
|
|
|
7
|
-
|
|
256
|
+
function ThumbnailListHeaderSort(props) {
|
|
257
|
+
const { setSortAscending, sortAscending, setSortBy, sortBy } = useThumbnailListItemContext();
|
|
258
|
+
console.log('Header sort rerenders');
|
|
259
|
+
return (jsx(Fragment, { children: jsxs(Box, { sx: { minWidth: '80px' }, children: [jsx(Tooltip, { title: "asc/desc", children: jsx(IconButton, { onClick: () => setSortAscending(!sortAscending), children: jsx(SwapVertIcon, {}) }) }), jsx(DropdownInput, { width: "130px", collapseBreakpoint: props.muiBreakpoint, label: 'sort', defaultValue: sortBy, icon: jsx(Tooltip, { title: 'sort', children: jsx(SortIcon, {}) }), items: props.items.map((i) => {
|
|
260
|
+
return { name: i.label, value: i.key.toString() };
|
|
261
|
+
}), onChangeCallback: (value) => setSortBy(value) })] }) }));
|
|
262
|
+
}
|
|
263
|
+
ThumbnailListHeaderSort.defaultProps = {
|
|
264
|
+
align: 'start',
|
|
265
|
+
muiBreakpoint: 'md',
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const ThumbnailListHeader = function (props) {
|
|
269
|
+
const startAlignedItems = [];
|
|
270
|
+
const endAlignedItems = [];
|
|
271
|
+
// Iterate through each child to categorize them based on their 'align' prop
|
|
272
|
+
Children.forEach(props.children, (child) => {
|
|
273
|
+
if (React.isValidElement(child)) {
|
|
274
|
+
const alignment = child.props.align || 'start';
|
|
275
|
+
if (alignment === 'end') {
|
|
276
|
+
endAlignedItems.push(child);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
startAlignedItems.push(child);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
return (jsx(Fragment, { children: jsxs(Stack$1, { direction: "row", alignItems: "center", justifyContent: props.justifyContent ?? 'space-between', gap: 2, children: [jsx(Stack$1, { direction: "row", alignItems: "center", gap: 2, justifyContent: "start", children: startAlignedItems }), endAlignedItems] }) }));
|
|
284
|
+
};
|
|
285
|
+
ThumbnailListHeader.SearchField = ThumbnailListSearchField$1;
|
|
286
|
+
ThumbnailListHeader.FilterTags = ThumbnailListFilterTags;
|
|
287
|
+
ThumbnailListHeader.Sort = ThumbnailListHeaderSort;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Main Component: Renders all sub components
|
|
291
|
+
* Includes ThumbnailList Provider for context data
|
|
292
|
+
* @param props react children, items
|
|
293
|
+
* @returns component
|
|
294
|
+
*/
|
|
295
|
+
function ThumbnailList(props) {
|
|
296
|
+
const combinedConfig = {
|
|
297
|
+
...defaultConfiguration,
|
|
298
|
+
...props.config, // This will override the defaults with any props that are not undefined
|
|
299
|
+
};
|
|
300
|
+
const [listItems, setListItems] = useState(props.items);
|
|
301
|
+
const { sortedItems, setSortBy, setSortAscending, sortAscending } = useSortedThumbnailListItems(listItems, combinedConfig.sortBy.toString(), combinedConfig.sortAscending);
|
|
302
|
+
const { tagFilteredItems, setTagAndCondition, tagAndCondition } = useTagFilteredThumbnailListItems({ allItems: sortedItems, initialTag: combinedConfig.tag.toString() });
|
|
303
|
+
const { setSearchTerm, filteredItems } = useFilteredThumbnailListItems(tagFilteredItems);
|
|
304
|
+
console.log('Thumbnaillist renders');
|
|
305
|
+
return (jsx(Fragment, { children: jsx(ThumbnailListItemContext.Provider, { value: {
|
|
306
|
+
items: filteredItems,
|
|
307
|
+
setItems: setListItems,
|
|
308
|
+
originalItems: listItems,
|
|
309
|
+
setOriginalItems: setListItems,
|
|
310
|
+
tagFilterCallback: setTagAndCondition,
|
|
311
|
+
tagAndCondition: tagAndCondition,
|
|
312
|
+
setSearchTerm: setSearchTerm,
|
|
313
|
+
setSortAscending: setSortAscending,
|
|
314
|
+
sortAscending: sortAscending,
|
|
315
|
+
setSortBy: setSortBy,
|
|
316
|
+
sortBy: combinedConfig.sortBy.toString(),
|
|
317
|
+
isLoading: false,
|
|
318
|
+
}, children: jsx(Stack$1, { direction: "column", sx: { width: '100%', minWidth: '425px' }, children: props.children }) }) }));
|
|
319
|
+
}
|
|
320
|
+
ThumbnailList.MainContent = ThumbnailListMainContent;
|
|
321
|
+
ThumbnailList.Header = ThumbnailListHeader;
|
|
322
|
+
|
|
323
|
+
export { ThumbnailList };
|
package/package.json
CHANGED
|
@@ -1,61 +1,83 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@janrankenhohn/react-thumbnail-list",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"react-scripts
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@janrankenhohn/react-thumbnail-list",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"main": "dist/index.cjs.js",
|
|
5
|
+
"module": "dist/index.esm.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"./dist"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/JanRankenhohn/react-thumbnail-list.git"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rollup -c",
|
|
15
|
+
"build-watch": "rollup -c -w",
|
|
16
|
+
"start-playground": "cd playground && npm run start",
|
|
17
|
+
"i-all": "npm i && cd playground && npm i",
|
|
18
|
+
"dev": "npm-run-all --parallel build-watch start-playground",
|
|
19
|
+
"start": "react-scripts start",
|
|
20
|
+
"test": "react-scripts test",
|
|
21
|
+
"eject": "react-scripts eject"
|
|
22
|
+
},
|
|
23
|
+
"eslintConfig": {
|
|
24
|
+
"extends": [
|
|
25
|
+
"react-app",
|
|
26
|
+
"react-app/jest"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"browserslist": {
|
|
30
|
+
"production": [
|
|
31
|
+
">0.2%",
|
|
32
|
+
"not dead",
|
|
33
|
+
"not op_mini all"
|
|
34
|
+
],
|
|
35
|
+
"development": [
|
|
36
|
+
"last 1 chrome version",
|
|
37
|
+
"last 1 firefox version",
|
|
38
|
+
"last 1 safari version"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@babel/cli": "^7.23.9",
|
|
43
|
+
"@babel/core": "^7.23.9",
|
|
44
|
+
"@babel/preset-env": "^7.23.9",
|
|
45
|
+
"@babel/preset-react": "^7.23.3",
|
|
46
|
+
"@eslint/js": "^9.1.1",
|
|
47
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
48
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
49
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
50
|
+
"@rollup/plugin-typescript": "^8.3.3",
|
|
51
|
+
"@testing-library/jest-dom": "^5.17.0",
|
|
52
|
+
"@testing-library/react": "^13.4.0",
|
|
53
|
+
"@testing-library/user-event": "^13.5.0",
|
|
54
|
+
"@types/lodash": "^4.17.0",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
|
56
|
+
"@typescript-eslint/parser": "^7.8.0",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"eslint-config-prettier": "^9.1.0",
|
|
59
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
60
|
+
"eslint-plugin-react": "^7.34.1",
|
|
61
|
+
"globals": "^15.1.0",
|
|
62
|
+
"jest": "^27.5.1",
|
|
63
|
+
"npm-run-all": "^4.1.5",
|
|
64
|
+
"prettier": "^3.2.5",
|
|
65
|
+
"react-router": "^6.26.1",
|
|
66
|
+
"rollup": "^2.79.1",
|
|
67
|
+
"rollup-plugin-delete": "^2.0.0",
|
|
68
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
69
|
+
"rollup-plugin-ts": "^3.4.5",
|
|
70
|
+
"typescript-eslint": "^7.8.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"@emotion/react": "^11.11.4",
|
|
74
|
+
"@emotion/styled": "^11.11.0",
|
|
75
|
+
"@mui/icons-material": "^5.15.11",
|
|
76
|
+
"@mui/material": "^5.15.11",
|
|
77
|
+
"lodash.debounce": "^4.0.8",
|
|
78
|
+
"react": "^18.0.0",
|
|
79
|
+
"react-dom": "^18.0.0",
|
|
80
|
+
"react-scripts": "5.0.1",
|
|
81
|
+
"web-vitals": "^2.1.4"
|
|
82
|
+
}
|
|
83
|
+
}
|