@janrankenhohn/react-thumbnail-list 0.4.0 → 0.5.0
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 +320 -15
- package/dist/index.esm.js +307 -7
- package/package.json +72 -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
|
@@ -1,15 +1,320 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var material = require('@mui/material');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var system = require('@mui/system');
|
|
9
|
+
var SearchIcon = require('@mui/icons-material/Search');
|
|
10
|
+
var ClearIcon = require('@mui/icons-material/Clear');
|
|
11
|
+
var SwapVertIcon = require('@mui/icons-material/SwapVert');
|
|
12
|
+
var SortIcon = require('@mui/icons-material/Sort');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
+
|
|
16
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
17
|
+
var SearchIcon__default = /*#__PURE__*/_interopDefaultLegacy(SearchIcon);
|
|
18
|
+
var ClearIcon__default = /*#__PURE__*/_interopDefaultLegacy(ClearIcon);
|
|
19
|
+
var SwapVertIcon__default = /*#__PURE__*/_interopDefaultLegacy(SwapVertIcon);
|
|
20
|
+
var SortIcon__default = /*#__PURE__*/_interopDefaultLegacy(SortIcon);
|
|
21
|
+
|
|
22
|
+
function HelloWorld() {
|
|
23
|
+
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("h1", null, "Hello World"), /*#__PURE__*/React__default["default"].createElement(material.Button, {
|
|
24
|
+
variant: "contained"
|
|
25
|
+
}, "Contained"));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
29
|
+
const ThumbnailListItemContext = React.createContext(undefined);
|
|
30
|
+
// Create a custom hook to consume the context
|
|
31
|
+
const useThumbnailListItemContext = () => {
|
|
32
|
+
const context = React.useContext(ThumbnailListItemContext);
|
|
33
|
+
if (!context) {
|
|
34
|
+
throw new Error('useMyContext must be used within a MyContextProvider');
|
|
35
|
+
}
|
|
36
|
+
return context;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Can be used as parent component to crop a wrapped image
|
|
41
|
+
* @param props width: width for cropping
|
|
42
|
+
* height: height for cropping
|
|
43
|
+
* seperate xs and sm values for mui breakpoints
|
|
44
|
+
* @returns component
|
|
45
|
+
*/
|
|
46
|
+
function ImageCropper(props) {
|
|
47
|
+
const ThumbnailImageCrop = material.styled('div')((p) => ({
|
|
48
|
+
[p.theme.breakpoints.up('xs')]: {
|
|
49
|
+
minWidth: props.width.xs,
|
|
50
|
+
maxWidth: props.width.xs,
|
|
51
|
+
height: props.height.xs,
|
|
52
|
+
overflow: 'hidden'
|
|
53
|
+
},
|
|
54
|
+
[p.theme.breakpoints.up('sm')]: {
|
|
55
|
+
minWidth: props.width.sm,
|
|
56
|
+
maxwWidth: props.width.sm,
|
|
57
|
+
height: props.height.sm,
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ThumbnailImageCrop, { children: props.children }) }));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Creates a ellipies text with webkit css styles
|
|
65
|
+
* @param props lineClamp: lines till ellipses
|
|
66
|
+
* @returns component
|
|
67
|
+
*/
|
|
68
|
+
function EllipsisContainer(props) {
|
|
69
|
+
const EllipsisContainer = material.styled('div')((p) => ({
|
|
70
|
+
[p.theme.breakpoints.up('xs')]: {
|
|
71
|
+
overflow: 'hidden',
|
|
72
|
+
display: '-webkit-box',
|
|
73
|
+
WebkitLineClamp: props.lineClamp.xs.toString(),
|
|
74
|
+
WebkitBoxOrient: 'vertical',
|
|
75
|
+
},
|
|
76
|
+
[p.theme.breakpoints.up('sm')]: {
|
|
77
|
+
overflow: 'hidden',
|
|
78
|
+
display: '-webkit-box',
|
|
79
|
+
WebkitLineClamp: props.lineClamp.sm.toString(),
|
|
80
|
+
WebkitBoxOrient: 'vertical', /* number of lines to show */
|
|
81
|
+
},
|
|
82
|
+
}));
|
|
83
|
+
return (jsxRuntime.jsx(EllipsisContainer, { children: props.children }));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function ThumbnailListItemTitle(props) {
|
|
87
|
+
const StyledCardContent = material.styled('div')((props) => ({
|
|
88
|
+
[props.theme.breakpoints.up('xs')]: {
|
|
89
|
+
'padding': props.theme.spacing(1),
|
|
90
|
+
'flex': '1 0 auto',
|
|
91
|
+
'&:last-child': { paddingBottom: 0 },
|
|
92
|
+
'overflow': 'hidden',
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
const children = React.Children.toArray(props.children);
|
|
96
|
+
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: 'h4', children: props.title }) }), jsxRuntime.jsx(system.Stack, { direction: "row", gap: 1, children: children.map((child, index) => jsxRuntime.jsx(material.Typography, { variant: "subtitle2", color: "text.secondary", children: child }, index)) })] }) }) });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function ThumbnailListItemInfoLabel(props) {
|
|
100
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(material.Stack, { textAlign: "right", justifyContent: "space-between", children: [jsxRuntime.jsx(material.Box, { textAlign: "right", padding: 1, children: props.topContent }), jsxRuntime.jsx(material.Box, { textAlign: "right", padding: 1, children: props.bottomContent })] }) });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// import {Link} from 'react-router-dom';
|
|
104
|
+
const ThumbnailListItem = (props) => {
|
|
105
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(material.Card, { sx: { display: 'flex' }, children: jsxRuntime.jsx(material.CardActionArea, { children: jsxRuntime.jsxs(material.Stack, { direction: "row", width: "100%", children: [jsxRuntime.jsx(ImageCropper, { width: { xs: '98px', sm: '160px' }, height: { xs: '54px', sm: '90px' }, children: jsxRuntime.jsx(material.Box, { children: "Placeholder for image" }) }), jsxRuntime.jsx(material.Stack, { direction: "row", justifyContent: "space-between", width: "100%", gap: 1, children: props.children })] }) }) }) });
|
|
106
|
+
};
|
|
107
|
+
ThumbnailListItem.Title = ThumbnailListItemTitle;
|
|
108
|
+
ThumbnailListItem.InfoLabel = ThumbnailListItemInfoLabel;
|
|
109
|
+
|
|
110
|
+
function ThumbnailListMainContent( /* props: {children: ReactNode}*/) {
|
|
111
|
+
// const children = Children.toArray(props.children);
|
|
112
|
+
const { items } = useThumbnailListItemContext();
|
|
113
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: items.map((item) => {
|
|
114
|
+
return (jsxRuntime.jsx(material.Grid, { item: true, xs: 12, lg: 6, xl: 3, children: jsxRuntime.jsxs(ThumbnailListItem, { id: item.id,
|
|
115
|
+
// link={item.link}
|
|
116
|
+
thumbnailUrl: item.thumbnailUrl, children: [jsxRuntime.jsx(ThumbnailListItem.Title, { title: item.title, children: item.subTitle }), item.label] }) }, item.id));
|
|
117
|
+
}) }));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const ThumbnailListSearchField = () => {
|
|
121
|
+
const [input, setInput] = React.useState('');
|
|
122
|
+
const [showClearIcon, setShowClearIcon] = React.useState('hidden');
|
|
123
|
+
const { setSearchTerm } = useThumbnailListItemContext();
|
|
124
|
+
const handleChange = (value) => {
|
|
125
|
+
setInput(value);
|
|
126
|
+
setShowClearIcon(value === '' ? 'hidden' : '');
|
|
127
|
+
setSearchTerm(value);
|
|
128
|
+
};
|
|
129
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(material.FormControl, { children: jsxRuntime.jsx(material.TextField, { sx: { input: { color: 'white' } }, fullWidth: true, value: input, size: "small", variant: "outlined", onChange: (event) => handleChange(event.target.value), InputProps: {
|
|
130
|
+
startAdornment: (jsxRuntime.jsx(material.InputAdornment, { position: "start", children: jsxRuntime.jsx(SearchIcon__default["default"], {}) })),
|
|
131
|
+
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"], {}) }) })),
|
|
132
|
+
} }) }) }));
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
function ThumbnailListFilterTag(props) {
|
|
136
|
+
const theme = material.useTheme();
|
|
137
|
+
const handleOnClick = (value) => {
|
|
138
|
+
if (props.onClickCallback) {
|
|
139
|
+
props.onClickCallback(value);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: material.useMediaQuery(theme.breakpoints.up(props.collapseBreakpoint ?? 0)) || !props.icon ?
|
|
143
|
+
jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(material.Chip, { label: props.label, variant: props.variant, onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined }) }) :
|
|
144
|
+
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 }) }) }) }));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function ThumbnailListFilterTags(props) {
|
|
148
|
+
const { tagFilterCallback, tagAndCondition } = useThumbnailListItemContext();
|
|
149
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.tags.map((tag) => {
|
|
150
|
+
return (jsxRuntime.jsx(ThumbnailListFilterTag, { label: tag.label, value: tag.value, variant: tagAndCondition.tag === tag.value ? 'filled' : 'outlined', collapseBreakpoint: props.collapseBreakpoint, onClickCallback: (value) => tagFilterCallback({ tag: value, condition: tag.condition }), icon: tag.icon }));
|
|
151
|
+
}) }));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Displays a generic MUI select dropdown.
|
|
156
|
+
* Optinal collapses to a sort icon at a certain breakpoint
|
|
157
|
+
* @param props.label Select Label
|
|
158
|
+
* @param props.width * Width of the input field
|
|
159
|
+
* @param props.collapseBreakPoint * MUI breakpoint after that the select will collapse to the sort icon
|
|
160
|
+
* @param props.onChangeCallback * Callback function that gets triggered once a item is selected
|
|
161
|
+
* @param props.items * Array of items (name-value-pairs) that will be the select options
|
|
162
|
+
* @returns Drowpdown Input Component
|
|
163
|
+
*/
|
|
164
|
+
function DropdownInput(props) {
|
|
165
|
+
const [value, setValue] = React.useState(props.defaultValue ?? '');
|
|
166
|
+
const theme = material.useTheme();
|
|
167
|
+
const [anchorEl, setAnchorEl] = React.useState(null);
|
|
168
|
+
const handleChange = (value, name) => {
|
|
169
|
+
setValue(value);
|
|
170
|
+
setAnchorEl(null);
|
|
171
|
+
props.onChangeCallback(value, name);
|
|
172
|
+
};
|
|
173
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [material.useMediaQuery(theme.breakpoints.up(props.collapseBreakpoint ?? 0)) ?
|
|
174
|
+
jsxRuntime.jsxs(material.FormControl, { sx: { width: props.width, textAlign: 'start' }, children: [jsxRuntime.jsx(material.InputLabel, { size: 'small', id: "demo-simple-select-label", 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) => {
|
|
175
|
+
return jsxRuntime.jsx(material.MenuItem, { value: item.value, children: item.name }, item.value);
|
|
176
|
+
}) })] }) : (jsxRuntime.jsx(material.IconButton
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
+
, {
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
180
|
+
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))) })] }));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function ThumbnailListHeaderSort(props) {
|
|
184
|
+
const { setSortAscending, sortAscending, setSortBy } = useThumbnailListItemContext();
|
|
185
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(material.Box, { sx: { width: '-webkit-fill-available', textAlign: 'end' }, 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: 'md', label: 'sort', defaultValue: "creationTimeStamp", icon: jsxRuntime.jsx(material.Tooltip, { title: 'sort', children: jsxRuntime.jsx(SortIcon__default["default"], {}) }), items: props.items, onChangeCallback: (value) => setSortBy(value) })] }) }));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const ThumbnailListHeader = function (props) {
|
|
189
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(material.Grid, { item: true, xs: 12, children: jsxRuntime.jsx(material.Stack, { direction: "row", alignItems: "center", justifyContent: props.justifyContent ?? 'space-between', gap: 2, children: props.children }) }) }));
|
|
190
|
+
};
|
|
191
|
+
ThumbnailListHeader.SearchField = ThumbnailListSearchField;
|
|
192
|
+
ThumbnailListHeader.FilterTags = ThumbnailListFilterTags;
|
|
193
|
+
ThumbnailListHeader.Sort = ThumbnailListHeaderSort;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Generic method that sorts an array of items based on an item key
|
|
197
|
+
* @param values The array that should be sorted
|
|
198
|
+
* @param orderType The key of the entity that the array should be sorted by
|
|
199
|
+
* @returns A new reference of the ordered array
|
|
200
|
+
*/
|
|
201
|
+
function orderByArray(values, orderType) {
|
|
202
|
+
return [...values].sort((a, b) => {
|
|
203
|
+
const valueA = getComparableValue(a[orderType]);
|
|
204
|
+
const valueB = getComparableValue(b[orderType]);
|
|
205
|
+
return compareValues(valueA, valueB);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function getComparableValue(value) {
|
|
209
|
+
if (typeof value === 'number') {
|
|
210
|
+
return value;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
return String(value);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function compareValues(a, b) {
|
|
217
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
218
|
+
return a.localeCompare(b, undefined, { sensitivity: 'base' });
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function filterByTag(array, tagType, condition) {
|
|
225
|
+
const filteredArray = array.filter((item) => {
|
|
226
|
+
const tagValue = item[tagType];
|
|
227
|
+
return condition ? condition(tagValue) : !!tagValue;
|
|
228
|
+
});
|
|
229
|
+
console.log('filter array');
|
|
230
|
+
console.log(filteredArray);
|
|
231
|
+
return [...filteredArray];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// /* eslint-disable @typescript-eslint/no-explicit-any */
|
|
235
|
+
const useTagFilteredThumbnailListItems = ({ allItems, initialTag, initialCondition }) => {
|
|
236
|
+
const [tagAndCondition, setTagAndCondition] = React.useState({ tag: initialTag, condition: initialCondition });
|
|
237
|
+
const [tagFilteredItems, setTagFilteredItems] = React.useState(allItems);
|
|
238
|
+
const setTagWithCondition = (t, c) => {
|
|
239
|
+
setTagAndCondition({ tag: t, condition: c });
|
|
240
|
+
};
|
|
241
|
+
React.useEffect(() => {
|
|
242
|
+
const tagFiltered = tagAndCondition.tag === 'id' ?
|
|
243
|
+
allItems :
|
|
244
|
+
filterByTag(allItems, tagAndCondition.tag, tagAndCondition.condition);
|
|
245
|
+
setTagFilteredItems(tagFiltered);
|
|
246
|
+
}, [allItems, tagAndCondition]);
|
|
247
|
+
return {
|
|
248
|
+
tagAndCondition,
|
|
249
|
+
setTagAndCondition,
|
|
250
|
+
tagFilteredItems,
|
|
251
|
+
setTagWithCondition,
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Filters a list of event by a search term
|
|
257
|
+
* @param allEvents event list that will be formatted
|
|
258
|
+
* @param initialSearchTerm
|
|
259
|
+
* @returns
|
|
260
|
+
*/
|
|
261
|
+
const useFilteredThumbnailListItems = (allItems, initialSearchTerm = '') => {
|
|
262
|
+
const [searchTerm, setSearchTerm] = React.useState(initialSearchTerm);
|
|
263
|
+
const [filteredItems, setFilteredItems] = React.useState(allItems);
|
|
264
|
+
React.useEffect(() => {
|
|
265
|
+
const filterEvents = () => {
|
|
266
|
+
const filtered = [...allItems].filter((item) => item.title.toLowerCase().includes(searchTerm.toLowerCase()));
|
|
267
|
+
setFilteredItems(filtered);
|
|
268
|
+
};
|
|
269
|
+
filterEvents();
|
|
270
|
+
}, [allItems, searchTerm]);
|
|
271
|
+
return { searchTerm, setSearchTerm, filteredItems };
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const useSortedThumbnailListItems = (allItems, initialSortBy, initialSortAscending) => {
|
|
275
|
+
const [sortBy, setSortBy] = React.useState(initialSortBy);
|
|
276
|
+
const [sortAscending, setSortAscending] = React.useState(initialSortAscending);
|
|
277
|
+
const [sortedItems, setSortedItems] = React.useState(allItems);
|
|
278
|
+
React.useEffect(() => {
|
|
279
|
+
let sorted = orderByArray(allItems, sortBy);
|
|
280
|
+
if (!sortAscending) {
|
|
281
|
+
sorted = sorted.reverse();
|
|
282
|
+
}
|
|
283
|
+
setSortedItems(sorted);
|
|
284
|
+
}, [allItems, sortBy, sortAscending, initialSortBy, initialSortAscending]);
|
|
285
|
+
return { sortBy, sortAscending, setSortBy, setSortAscending, sortedItems };
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const ThumbnailList = function (props) {
|
|
289
|
+
// const [originalItems, setOriginalItems] = useState(props.items);
|
|
290
|
+
const [listItems, setListItems] = React.useState(props.items);
|
|
291
|
+
const { sortedItems, setSortBy, setSortAscending, sortAscending } = useSortedThumbnailListItems(listItems, 'creationTimeStamp', false);
|
|
292
|
+
const { setSearchTerm, filteredItems } = useFilteredThumbnailListItems(sortedItems);
|
|
293
|
+
const { tagFilteredItems, setTagAndCondition, tagAndCondition } = useTagFilteredThumbnailListItems({ allItems: filteredItems, initialTag: 'id' });
|
|
294
|
+
console.log('tag filterd');
|
|
295
|
+
console.log(tagFilteredItems);
|
|
296
|
+
console.log(listItems);
|
|
297
|
+
React.useEffect(() => {
|
|
298
|
+
if (props.items) {
|
|
299
|
+
// setOriginalItems(props.items);
|
|
300
|
+
setListItems(props.items);
|
|
301
|
+
}
|
|
302
|
+
}, [props.items]);
|
|
303
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ThumbnailListItemContext.Provider, { value: {
|
|
304
|
+
items: tagFilteredItems,
|
|
305
|
+
setItems: setListItems,
|
|
306
|
+
originalItems: listItems,
|
|
307
|
+
setOriginalItems: setListItems,
|
|
308
|
+
tagFilterCallback: setTagAndCondition,
|
|
309
|
+
tagAndCondition: tagAndCondition,
|
|
310
|
+
setSearchTerm: setSearchTerm,
|
|
311
|
+
setSortAscending: setSortAscending,
|
|
312
|
+
sortAscending: sortAscending,
|
|
313
|
+
setSortBy: setSortBy,
|
|
314
|
+
}, children: jsxRuntime.jsx(material.Grid, { container: true, spacing: 2, children: props.children }) }) }));
|
|
315
|
+
};
|
|
316
|
+
ThumbnailList.MainContent = ThumbnailListMainContent;
|
|
317
|
+
ThumbnailList.Header = ThumbnailListHeader;
|
|
318
|
+
|
|
319
|
+
exports.HelloWorld = HelloWorld;
|
|
320
|
+
exports.ThumbnailList = ThumbnailList;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,307 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Button, styled, Box, Typography, Stack as Stack$1, Card, CardActionArea, Grid, FormControl, TextField, InputAdornment, IconButton, useTheme, useMediaQuery, Chip, Tooltip, InputLabel, Select, MenuItem, Menu } from '@mui/material';
|
|
2
|
+
import React, { createContext, useContext, Children, useState, useEffect } from 'react';
|
|
3
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
import { Stack } from '@mui/system';
|
|
5
|
+
import SearchIcon from '@mui/icons-material/Search';
|
|
6
|
+
import ClearIcon from '@mui/icons-material/Clear';
|
|
7
|
+
import SwapVertIcon from '@mui/icons-material/SwapVert';
|
|
8
|
+
import SortIcon from '@mui/icons-material/Sort';
|
|
9
|
+
|
|
10
|
+
function HelloWorld() {
|
|
11
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("h1", null, "Hello World"), /*#__PURE__*/React.createElement(Button, {
|
|
12
|
+
variant: "contained"
|
|
13
|
+
}, "Contained"));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
17
|
+
const ThumbnailListItemContext = createContext(undefined);
|
|
18
|
+
// Create a custom hook to consume the context
|
|
19
|
+
const useThumbnailListItemContext = () => {
|
|
20
|
+
const context = useContext(ThumbnailListItemContext);
|
|
21
|
+
if (!context) {
|
|
22
|
+
throw new Error('useMyContext must be used within a MyContextProvider');
|
|
23
|
+
}
|
|
24
|
+
return context;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Can be used as parent component to crop a wrapped image
|
|
29
|
+
* @param props width: width for cropping
|
|
30
|
+
* height: height for cropping
|
|
31
|
+
* seperate xs and sm values for mui breakpoints
|
|
32
|
+
* @returns component
|
|
33
|
+
*/
|
|
34
|
+
function ImageCropper(props) {
|
|
35
|
+
const ThumbnailImageCrop = styled('div')((p) => ({
|
|
36
|
+
[p.theme.breakpoints.up('xs')]: {
|
|
37
|
+
minWidth: props.width.xs,
|
|
38
|
+
maxWidth: props.width.xs,
|
|
39
|
+
height: props.height.xs,
|
|
40
|
+
overflow: 'hidden'
|
|
41
|
+
},
|
|
42
|
+
[p.theme.breakpoints.up('sm')]: {
|
|
43
|
+
minWidth: props.width.sm,
|
|
44
|
+
maxwWidth: props.width.sm,
|
|
45
|
+
height: props.height.sm,
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
return (jsx(Fragment, { children: jsx(ThumbnailImageCrop, { children: props.children }) }));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a ellipies text with webkit css styles
|
|
53
|
+
* @param props lineClamp: lines till ellipses
|
|
54
|
+
* @returns component
|
|
55
|
+
*/
|
|
56
|
+
function EllipsisContainer(props) {
|
|
57
|
+
const EllipsisContainer = styled('div')((p) => ({
|
|
58
|
+
[p.theme.breakpoints.up('xs')]: {
|
|
59
|
+
overflow: 'hidden',
|
|
60
|
+
display: '-webkit-box',
|
|
61
|
+
WebkitLineClamp: props.lineClamp.xs.toString(),
|
|
62
|
+
WebkitBoxOrient: 'vertical',
|
|
63
|
+
},
|
|
64
|
+
[p.theme.breakpoints.up('sm')]: {
|
|
65
|
+
overflow: 'hidden',
|
|
66
|
+
display: '-webkit-box',
|
|
67
|
+
WebkitLineClamp: props.lineClamp.sm.toString(),
|
|
68
|
+
WebkitBoxOrient: 'vertical', /* number of lines to show */
|
|
69
|
+
},
|
|
70
|
+
}));
|
|
71
|
+
return (jsx(EllipsisContainer, { children: props.children }));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ThumbnailListItemTitle(props) {
|
|
75
|
+
const StyledCardContent = styled('div')((props) => ({
|
|
76
|
+
[props.theme.breakpoints.up('xs')]: {
|
|
77
|
+
'padding': props.theme.spacing(1),
|
|
78
|
+
'flex': '1 0 auto',
|
|
79
|
+
'&:last-child': { paddingBottom: 0 },
|
|
80
|
+
'overflow': 'hidden',
|
|
81
|
+
},
|
|
82
|
+
}));
|
|
83
|
+
const children = Children.toArray(props.children);
|
|
84
|
+
return jsx(Fragment, { children: jsx(Box, { children: jsxs(StyledCardContent, { children: [jsx(EllipsisContainer, { lineClamp: { xs: 1, sm: 2 }, children: jsx(Typography, { variant: 'h4', children: props.title }) }), jsx(Stack, { direction: "row", gap: 1, children: children.map((child, index) => jsx(Typography, { variant: "subtitle2", color: "text.secondary", children: child }, index)) })] }) }) });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function ThumbnailListItemInfoLabel(props) {
|
|
88
|
+
return jsx(Fragment, { children: jsxs(Stack$1, { textAlign: "right", justifyContent: "space-between", children: [jsx(Box, { textAlign: "right", padding: 1, children: props.topContent }), jsx(Box, { textAlign: "right", padding: 1, children: props.bottomContent })] }) });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// import {Link} from 'react-router-dom';
|
|
92
|
+
const ThumbnailListItem = (props) => {
|
|
93
|
+
return jsx(Fragment, { children: jsx(Card, { sx: { display: 'flex' }, children: jsx(CardActionArea, { children: jsxs(Stack$1, { direction: "row", width: "100%", children: [jsx(ImageCropper, { width: { xs: '98px', sm: '160px' }, height: { xs: '54px', sm: '90px' }, children: jsx(Box, { children: "Placeholder for image" }) }), jsx(Stack$1, { direction: "row", justifyContent: "space-between", width: "100%", gap: 1, children: props.children })] }) }) }) });
|
|
94
|
+
};
|
|
95
|
+
ThumbnailListItem.Title = ThumbnailListItemTitle;
|
|
96
|
+
ThumbnailListItem.InfoLabel = ThumbnailListItemInfoLabel;
|
|
97
|
+
|
|
98
|
+
function ThumbnailListMainContent( /* props: {children: ReactNode}*/) {
|
|
99
|
+
// const children = Children.toArray(props.children);
|
|
100
|
+
const { items } = useThumbnailListItemContext();
|
|
101
|
+
return (jsx(Fragment, { children: items.map((item) => {
|
|
102
|
+
return (jsx(Grid, { item: true, xs: 12, lg: 6, xl: 3, children: jsxs(ThumbnailListItem, { id: item.id,
|
|
103
|
+
// link={item.link}
|
|
104
|
+
thumbnailUrl: item.thumbnailUrl, children: [jsx(ThumbnailListItem.Title, { title: item.title, children: item.subTitle }), item.label] }) }, item.id));
|
|
105
|
+
}) }));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const ThumbnailListSearchField = () => {
|
|
109
|
+
const [input, setInput] = useState('');
|
|
110
|
+
const [showClearIcon, setShowClearIcon] = useState('hidden');
|
|
111
|
+
const { setSearchTerm } = useThumbnailListItemContext();
|
|
112
|
+
const handleChange = (value) => {
|
|
113
|
+
setInput(value);
|
|
114
|
+
setShowClearIcon(value === '' ? 'hidden' : '');
|
|
115
|
+
setSearchTerm(value);
|
|
116
|
+
};
|
|
117
|
+
return (jsx(Fragment, { children: jsx(FormControl, { children: jsx(TextField, { sx: { input: { color: 'white' } }, fullWidth: true, value: input, size: "small", variant: "outlined", onChange: (event) => handleChange(event.target.value), InputProps: {
|
|
118
|
+
startAdornment: (jsx(InputAdornment, { position: "start", children: jsx(SearchIcon, {}) })),
|
|
119
|
+
endAdornment: (jsx(InputAdornment, { position: "end", children: jsx(IconButton, { onClick: () => handleChange(''), sx: { visibility: showClearIcon, padding: 0 }, children: jsx(ClearIcon, {}) }) })),
|
|
120
|
+
} }) }) }));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
function ThumbnailListFilterTag(props) {
|
|
124
|
+
const theme = useTheme();
|
|
125
|
+
const handleOnClick = (value) => {
|
|
126
|
+
if (props.onClickCallback) {
|
|
127
|
+
props.onClickCallback(value);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return (jsx(Fragment, { children: useMediaQuery(theme.breakpoints.up(props.collapseBreakpoint ?? 0)) || !props.icon ?
|
|
131
|
+
jsx(Fragment, { children: jsx(Chip, { label: props.label, variant: props.variant, onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined }) }) :
|
|
132
|
+
jsx(Fragment, { children: jsx(Tooltip, { title: props.label, children: jsx(IconButton, { onClick: props.onClickCallback ? () => handleOnClick(props.value) : undefined, children: props.icon }) }) }) }));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function ThumbnailListFilterTags(props) {
|
|
136
|
+
const { tagFilterCallback, tagAndCondition } = useThumbnailListItemContext();
|
|
137
|
+
return (jsx(Fragment, { children: props.tags.map((tag) => {
|
|
138
|
+
return (jsx(ThumbnailListFilterTag, { label: tag.label, value: tag.value, variant: tagAndCondition.tag === tag.value ? 'filled' : 'outlined', collapseBreakpoint: props.collapseBreakpoint, onClickCallback: (value) => tagFilterCallback({ tag: value, condition: tag.condition }), icon: tag.icon }));
|
|
139
|
+
}) }));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Displays a generic MUI select dropdown.
|
|
144
|
+
* Optinal collapses to a sort icon at a certain breakpoint
|
|
145
|
+
* @param props.label Select Label
|
|
146
|
+
* @param props.width * Width of the input field
|
|
147
|
+
* @param props.collapseBreakPoint * MUI breakpoint after that the select will collapse to the sort icon
|
|
148
|
+
* @param props.onChangeCallback * Callback function that gets triggered once a item is selected
|
|
149
|
+
* @param props.items * Array of items (name-value-pairs) that will be the select options
|
|
150
|
+
* @returns Drowpdown Input Component
|
|
151
|
+
*/
|
|
152
|
+
function DropdownInput(props) {
|
|
153
|
+
const [value, setValue] = useState(props.defaultValue ?? '');
|
|
154
|
+
const theme = useTheme();
|
|
155
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
156
|
+
const handleChange = (value, name) => {
|
|
157
|
+
setValue(value);
|
|
158
|
+
setAnchorEl(null);
|
|
159
|
+
props.onChangeCallback(value, name);
|
|
160
|
+
};
|
|
161
|
+
return (jsxs(Fragment, { children: [useMediaQuery(theme.breakpoints.up(props.collapseBreakpoint ?? 0)) ?
|
|
162
|
+
jsxs(FormControl, { sx: { width: props.width, textAlign: 'start' }, children: [jsx(InputLabel, { size: 'small', id: "demo-simple-select-label", 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) => {
|
|
163
|
+
return jsx(MenuItem, { value: item.value, children: item.name }, item.value);
|
|
164
|
+
}) })] }) : (jsx(IconButton
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
166
|
+
, {
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
|
+
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))) })] }));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function ThumbnailListHeaderSort(props) {
|
|
172
|
+
const { setSortAscending, sortAscending, setSortBy } = useThumbnailListItemContext();
|
|
173
|
+
return (jsx(Fragment, { children: jsxs(Box, { sx: { width: '-webkit-fill-available', textAlign: 'end' }, children: [jsx(Tooltip, { title: "asc/desc", children: jsx(IconButton, { onClick: () => setSortAscending(!sortAscending), children: jsx(SwapVertIcon, {}) }) }), jsx(DropdownInput, { width: "130px", collapseBreakpoint: 'md', label: 'sort', defaultValue: "creationTimeStamp", icon: jsx(Tooltip, { title: 'sort', children: jsx(SortIcon, {}) }), items: props.items, onChangeCallback: (value) => setSortBy(value) })] }) }));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const ThumbnailListHeader = function (props) {
|
|
177
|
+
return (jsx(Fragment, { children: jsx(Grid, { item: true, xs: 12, children: jsx(Stack$1, { direction: "row", alignItems: "center", justifyContent: props.justifyContent ?? 'space-between', gap: 2, children: props.children }) }) }));
|
|
178
|
+
};
|
|
179
|
+
ThumbnailListHeader.SearchField = ThumbnailListSearchField;
|
|
180
|
+
ThumbnailListHeader.FilterTags = ThumbnailListFilterTags;
|
|
181
|
+
ThumbnailListHeader.Sort = ThumbnailListHeaderSort;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Generic method that sorts an array of items based on an item key
|
|
185
|
+
* @param values The array that should be sorted
|
|
186
|
+
* @param orderType The key of the entity that the array should be sorted by
|
|
187
|
+
* @returns A new reference of the ordered array
|
|
188
|
+
*/
|
|
189
|
+
function orderByArray(values, orderType) {
|
|
190
|
+
return [...values].sort((a, b) => {
|
|
191
|
+
const valueA = getComparableValue(a[orderType]);
|
|
192
|
+
const valueB = getComparableValue(b[orderType]);
|
|
193
|
+
return compareValues(valueA, valueB);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function getComparableValue(value) {
|
|
197
|
+
if (typeof value === 'number') {
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return String(value);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function compareValues(a, b) {
|
|
205
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
206
|
+
return a.localeCompare(b, undefined, { sensitivity: 'base' });
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function filterByTag(array, tagType, condition) {
|
|
213
|
+
const filteredArray = array.filter((item) => {
|
|
214
|
+
const tagValue = item[tagType];
|
|
215
|
+
return condition ? condition(tagValue) : !!tagValue;
|
|
216
|
+
});
|
|
217
|
+
console.log('filter array');
|
|
218
|
+
console.log(filteredArray);
|
|
219
|
+
return [...filteredArray];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// /* eslint-disable @typescript-eslint/no-explicit-any */
|
|
223
|
+
const useTagFilteredThumbnailListItems = ({ allItems, initialTag, initialCondition }) => {
|
|
224
|
+
const [tagAndCondition, setTagAndCondition] = useState({ tag: initialTag, condition: initialCondition });
|
|
225
|
+
const [tagFilteredItems, setTagFilteredItems] = useState(allItems);
|
|
226
|
+
const setTagWithCondition = (t, c) => {
|
|
227
|
+
setTagAndCondition({ tag: t, condition: c });
|
|
228
|
+
};
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
const tagFiltered = tagAndCondition.tag === 'id' ?
|
|
231
|
+
allItems :
|
|
232
|
+
filterByTag(allItems, tagAndCondition.tag, tagAndCondition.condition);
|
|
233
|
+
setTagFilteredItems(tagFiltered);
|
|
234
|
+
}, [allItems, tagAndCondition]);
|
|
235
|
+
return {
|
|
236
|
+
tagAndCondition,
|
|
237
|
+
setTagAndCondition,
|
|
238
|
+
tagFilteredItems,
|
|
239
|
+
setTagWithCondition,
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Filters a list of event by a search term
|
|
245
|
+
* @param allEvents event list that will be formatted
|
|
246
|
+
* @param initialSearchTerm
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
249
|
+
const useFilteredThumbnailListItems = (allItems, initialSearchTerm = '') => {
|
|
250
|
+
const [searchTerm, setSearchTerm] = useState(initialSearchTerm);
|
|
251
|
+
const [filteredItems, setFilteredItems] = useState(allItems);
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
const filterEvents = () => {
|
|
254
|
+
const filtered = [...allItems].filter((item) => item.title.toLowerCase().includes(searchTerm.toLowerCase()));
|
|
255
|
+
setFilteredItems(filtered);
|
|
256
|
+
};
|
|
257
|
+
filterEvents();
|
|
258
|
+
}, [allItems, searchTerm]);
|
|
259
|
+
return { searchTerm, setSearchTerm, filteredItems };
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const useSortedThumbnailListItems = (allItems, initialSortBy, initialSortAscending) => {
|
|
263
|
+
const [sortBy, setSortBy] = useState(initialSortBy);
|
|
264
|
+
const [sortAscending, setSortAscending] = useState(initialSortAscending);
|
|
265
|
+
const [sortedItems, setSortedItems] = useState(allItems);
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
let sorted = orderByArray(allItems, sortBy);
|
|
268
|
+
if (!sortAscending) {
|
|
269
|
+
sorted = sorted.reverse();
|
|
270
|
+
}
|
|
271
|
+
setSortedItems(sorted);
|
|
272
|
+
}, [allItems, sortBy, sortAscending, initialSortBy, initialSortAscending]);
|
|
273
|
+
return { sortBy, sortAscending, setSortBy, setSortAscending, sortedItems };
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const ThumbnailList = function (props) {
|
|
277
|
+
// const [originalItems, setOriginalItems] = useState(props.items);
|
|
278
|
+
const [listItems, setListItems] = useState(props.items);
|
|
279
|
+
const { sortedItems, setSortBy, setSortAscending, sortAscending } = useSortedThumbnailListItems(listItems, 'creationTimeStamp', false);
|
|
280
|
+
const { setSearchTerm, filteredItems } = useFilteredThumbnailListItems(sortedItems);
|
|
281
|
+
const { tagFilteredItems, setTagAndCondition, tagAndCondition } = useTagFilteredThumbnailListItems({ allItems: filteredItems, initialTag: 'id' });
|
|
282
|
+
console.log('tag filterd');
|
|
283
|
+
console.log(tagFilteredItems);
|
|
284
|
+
console.log(listItems);
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
if (props.items) {
|
|
287
|
+
// setOriginalItems(props.items);
|
|
288
|
+
setListItems(props.items);
|
|
289
|
+
}
|
|
290
|
+
}, [props.items]);
|
|
291
|
+
return (jsx(Fragment, { children: jsx(ThumbnailListItemContext.Provider, { value: {
|
|
292
|
+
items: tagFilteredItems,
|
|
293
|
+
setItems: setListItems,
|
|
294
|
+
originalItems: listItems,
|
|
295
|
+
setOriginalItems: setListItems,
|
|
296
|
+
tagFilterCallback: setTagAndCondition,
|
|
297
|
+
tagAndCondition: tagAndCondition,
|
|
298
|
+
setSearchTerm: setSearchTerm,
|
|
299
|
+
setSortAscending: setSortAscending,
|
|
300
|
+
sortAscending: sortAscending,
|
|
301
|
+
setSortBy: setSortBy,
|
|
302
|
+
}, children: jsx(Grid, { container: true, spacing: 2, children: props.children }) }) }));
|
|
303
|
+
};
|
|
304
|
+
ThumbnailList.MainContent = ThumbnailListMainContent;
|
|
305
|
+
ThumbnailList.Header = ThumbnailListHeader;
|
|
306
|
+
|
|
307
|
+
export { HelloWorld, ThumbnailList };
|
package/package.json
CHANGED
|
@@ -1,61 +1,72 @@
|
|
|
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
|
-
"rollup": "^2.
|
|
58
|
-
"rollup-plugin-
|
|
59
|
-
"rollup-plugin-
|
|
60
|
-
}
|
|
61
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@janrankenhohn/react-thumbnail-list",
|
|
3
|
+
"version": "0.5.0",
|
|
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
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
47
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
48
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
49
|
+
"@rollup/plugin-typescript": "^8.3.3",
|
|
50
|
+
"@testing-library/jest-dom": "^5.17.0",
|
|
51
|
+
"@testing-library/react": "^13.4.0",
|
|
52
|
+
"@testing-library/user-event": "^13.5.0",
|
|
53
|
+
"@types/lodash": "^4.17.0",
|
|
54
|
+
"eslint-plugin-react": "^7.34.1",
|
|
55
|
+
"npm-run-all": "^4.1.5",
|
|
56
|
+
"rollup": "^2.79.1",
|
|
57
|
+
"rollup-plugin-delete": "^2.0.0",
|
|
58
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
59
|
+
"rollup-plugin-ts": "^3.4.5"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@emotion/react": "^11.11.4",
|
|
63
|
+
"@emotion/styled": "^11.11.0",
|
|
64
|
+
"@mui/icons-material": "^5.15.11",
|
|
65
|
+
"@mui/material": "^5.15.11",
|
|
66
|
+
"react": "^18.0.0",
|
|
67
|
+
"react-dom": "^18.0.0",
|
|
68
|
+
"react-scripts": "5.0.1",
|
|
69
|
+
"web-vitals": "^2.1.4",
|
|
70
|
+
"lodash.debounce": "^4.0.8"
|
|
71
|
+
}
|
|
72
|
+
}
|