@jasperoosthoek/react-toolbox 0.5.6 → 0.6.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/change-log.md +6 -0
- package/dist/components/forms/FormFields.d.ts +1 -7
- package/dist/components/tables/DataTable.d.ts +4 -1
- package/dist/index.js +2 -2
- package/dist/index.js.LICENSE.txt +2 -2
- package/package.json +6 -8
- package/src/components/buttons/IconButtons.tsx +2 -2
- package/src/components/forms/FormFields.tsx +0 -4
- package/src/components/tables/DataTable.tsx +30 -0
- package/src/components/tables/DragAndDropList.tsx +0 -1
- package/src/utils/hooks.ts +3 -1
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @license React
|
|
9
|
-
* react-jsx-runtime.production.
|
|
9
|
+
* react-jsx-runtime.production.js
|
|
10
10
|
*
|
|
11
|
-
* Copyright (c)
|
|
11
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
12
12
|
*
|
|
13
13
|
* This source code is licensed under the MIT license found in the
|
|
14
14
|
* LICENSE file in the root directory of this source tree.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jasperoosthoek/react-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"author": "jasperoosthoek",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@babel/preset-typescript": "^7.18.6",
|
|
23
23
|
"@babel/register": "^7.13.16",
|
|
24
24
|
"@testing-library/jest-dom": "^5.16.5",
|
|
25
|
-
"@testing-library/react": "^
|
|
25
|
+
"@testing-library/react": "^16.2.0",
|
|
26
26
|
"@types/jest": "^29.5.2",
|
|
27
27
|
"@types/lodash": "^4.14.191",
|
|
28
28
|
"@types/node": "^18.11.19",
|
|
@@ -50,19 +50,17 @@
|
|
|
50
50
|
"url": "https://github.com/jasperoosthoek/react-toolbox/issues"
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/jasperoosthoek/react-toolbox#readme",
|
|
53
|
-
"dependencies": {
|
|
54
|
-
},
|
|
55
53
|
"peerDependencies": {
|
|
56
54
|
"axios": "^1.4.0",
|
|
57
55
|
"bootstrap": "^5.1.3",
|
|
58
56
|
"moment": "^2.29.4",
|
|
59
|
-
"react": "^
|
|
57
|
+
"react": "^19.0.0",
|
|
60
58
|
"react-bootstrap": "^2.7.4",
|
|
61
59
|
"react-dnd": "^16.0.1",
|
|
62
|
-
"react-dom": "^
|
|
60
|
+
"react-dom": "^19.0.0",
|
|
63
61
|
"react-icons": "^5.3.0",
|
|
64
|
-
"react-localization": "^
|
|
65
|
-
"react-redux": "^9.
|
|
62
|
+
"react-localization": "^2.0.5",
|
|
63
|
+
"react-redux": "^9.2.0",
|
|
66
64
|
"redux": "^5.0.1",
|
|
67
65
|
"redux-thunk": "^3.1.0"
|
|
68
66
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { Button, ButtonProps as ReactBootstrapButtonProps,
|
|
1
|
+
import React, { useRef, ChangeEvent } from 'react';
|
|
2
|
+
import { Button, ButtonProps as ReactBootstrapButtonProps, Form } from 'react-bootstrap';
|
|
3
3
|
import {
|
|
4
4
|
AiFillCaretDown,
|
|
5
5
|
AiFillCaretUp,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { ReactElement, ChangeEvent, KeyboardEvent } from 'react';
|
|
2
2
|
import { Form, FormControl, Badge, Dropdown, BadgeProps, FormControlProps, FormCheckProps } from 'react-bootstrap';
|
|
3
3
|
import { Variant} from 'react-bootstrap/types';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
4
|
import { useLocalization } from '../../localization/LocalizationContext';
|
|
6
5
|
import moment, { Moment } from 'moment';
|
|
7
6
|
|
|
@@ -264,9 +263,6 @@ export const FormSelect = ({
|
|
|
264
263
|
</Form.Group>
|
|
265
264
|
</>;
|
|
266
265
|
}
|
|
267
|
-
FormSelect.propTypes = {
|
|
268
|
-
onChange: PropTypes.func.isRequired,
|
|
269
|
-
}
|
|
270
266
|
|
|
271
267
|
export interface BadgeSelectionProps extends BadgeProps {
|
|
272
268
|
selected: boolean;
|
|
@@ -6,6 +6,7 @@ import React, {
|
|
|
6
6
|
ReactElement,
|
|
7
7
|
ReactNode,
|
|
8
8
|
ChangeEvent,
|
|
9
|
+
useMemo,
|
|
9
10
|
Ref,
|
|
10
11
|
} from 'react';
|
|
11
12
|
import { FaSort, FaSortUp, FaSortDown } from 'react-icons/fa';
|
|
@@ -45,6 +46,8 @@ export type DataTableColumn<R> = {
|
|
|
45
46
|
orderBy?: OrderByColumn<R>;
|
|
46
47
|
optionsDropdown?: OptionsDropdown;
|
|
47
48
|
className?: string;
|
|
49
|
+
value?: number | string | ((row: R) => number);
|
|
50
|
+
formatSum?: ((value: number) => ReactElement | string | number) | ReactElement | string | number;
|
|
48
51
|
selector: number | string | ((row: R) => ReactElement | string | number | (ReactElement | string | number)[]);
|
|
49
52
|
onClick?: OnClickRow<R>;
|
|
50
53
|
}
|
|
@@ -87,6 +90,7 @@ export type DataTableProps<D extends any[]> = {
|
|
|
87
90
|
className?: string;
|
|
88
91
|
rowClassName?: string | ((row: D[number]) => string);
|
|
89
92
|
style?: any;
|
|
93
|
+
showSum?: boolean;
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
export const DataTable = <D extends any[]>({
|
|
@@ -107,6 +111,7 @@ export const DataTable = <D extends any[]>({
|
|
|
107
111
|
className,
|
|
108
112
|
rowClassName,
|
|
109
113
|
style,
|
|
114
|
+
showSum,
|
|
110
115
|
...restProps
|
|
111
116
|
}: DataTableProps<D>) => {
|
|
112
117
|
const { showEditModal, hasProvider } = useFormModal();
|
|
@@ -198,6 +203,12 @@ export const DataTable = <D extends any[]>({
|
|
|
198
203
|
)}
|
|
199
204
|
</tr>
|
|
200
205
|
);
|
|
206
|
+
|
|
207
|
+
const sums = useMemo(() => columns.map(({ value }) => (
|
|
208
|
+
value && data.reduce((sum, row) => (
|
|
209
|
+
sum + (typeof value === 'function' ? value(row) : row[value])
|
|
210
|
+
), 0)
|
|
211
|
+
)), [columns])
|
|
201
212
|
|
|
202
213
|
if (!Component) return null;
|
|
203
214
|
return (
|
|
@@ -414,6 +425,25 @@ export const DataTable = <D extends any[]>({
|
|
|
414
425
|
: data.map((row, index) => <Component row={row} key={index} />)
|
|
415
426
|
}
|
|
416
427
|
</tbody>
|
|
428
|
+
{showSum && (
|
|
429
|
+
<tfoot>
|
|
430
|
+
<tr>
|
|
431
|
+
|
|
432
|
+
{columns.map(({ value, formatSum }, index) =>
|
|
433
|
+
<td
|
|
434
|
+
key={index}
|
|
435
|
+
>
|
|
436
|
+
{value
|
|
437
|
+
? (typeof formatSum === 'function'
|
|
438
|
+
? formatSum(sums[index])
|
|
439
|
+
: sums[index]
|
|
440
|
+
)
|
|
441
|
+
: formatSum}
|
|
442
|
+
</td>
|
|
443
|
+
)}
|
|
444
|
+
</tr>
|
|
445
|
+
</tfoot>
|
|
446
|
+
)}
|
|
417
447
|
</Table>
|
|
418
448
|
</div>
|
|
419
449
|
)
|
package/src/utils/hooks.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { useDispatch } from 'react-redux';
|
|
|
3
3
|
|
|
4
4
|
// https://stackoverflow.com/questions/53446020/how-to-compare-oldvalues-and-newvalues-on-react-hooks-useeffect
|
|
5
5
|
export const usePrevious = <T>(value: T): T | undefined => {
|
|
6
|
-
|
|
6
|
+
// Explicitly set initial value to `undefined`
|
|
7
|
+
const ref = useRef<T | undefined>(undefined);
|
|
8
|
+
|
|
7
9
|
useEffect(() => {
|
|
8
10
|
ref.current = value;
|
|
9
11
|
});
|