@jasperoosthoek/react-toolbox 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,155 @@
1
1
  # React Toolbox
2
2
 
3
- A library of useful [React](https://react.dev/) components for building user interfaces.
4
-
5
- ### Dependencies
6
- - [React 19](https://react.dev/)
7
- - [Bootstrap 5](https://getbootstrap.com/docs/5.1/getting-started/introduction/)
8
- - [`react-bootstrap`](https://react-bootstrap.netlify.app/)
9
- - [`react-icons`](https://react-icons.github.io/react-icons/) A library combining many open source icons
10
- - [`react-dnd`](https://react-dnd.github.io/react-dnd/about) Drag and drop functionality for React components
11
- - [`react-localization`](https://www.npmjs.com/package/react-localization)
12
- - [`react-redux`](https://react-redux.js.org/)
13
- - [`redux-thunk`](https://github.com/reduxjs/redux-thunk)
14
- - [`moment`](https://momentjs.com/)
3
+ A library of useful [React](https://react.dev/) components for building user interfaces. A [Dashboard Demo](https://github.com/jasperoosthoek/dashboard-demo) repository and [live demo](https://dashboard-demo-olive-eight.vercel.app/employees) is available that showcases what this module is capable of including many code examples.
4
+
5
+ ### The DataTable component
6
+ This is a highly customizable and interactive DataTable component. It provides a seamless user experience with powerful features, making it ideal for displaying and managing data efficiently while keeping development time to a minimum.
7
+
8
+ #### Key features
9
+
10
+ - **Column Sorting**: Click column headers to sort data in ascending or descending order.
11
+ - **Pagination**: Navigate through large datasets smoothly with built-in pagination.
12
+ - **Drag & Drop**: Easily reorder rows or columns via intuitive drag-and-drop functionality based on [`react-dnd`](https://react-dnd.github.io/react-dnd/about).
13
+ - **Row Click to Edit**: Open a modal with an edit form when clicking a row for quick updates.
14
+ - **Search & Filter**: Instantly find relevant data with a easy to configure real-time search input.
15
+ </ul>
16
+
17
+ ### Custom hooks
18
+
19
+ #### useLocalStorage
20
+
21
+ Provides a state and setter function similar to `useState` of which the value is kept in `localStorage`.
22
+
23
+ ```typescript
24
+ const MyComponent = () => {
25
+ const [lang, setLang] = useLocalStorage<'en', 'fr', 'nl'>('lang-key', 'en');
26
+ ...
27
+ ```
28
+
29
+ ### IconButtons
30
+ Button component that takes an icon from [`react-icons`](https://react-icons.github.io/react-icons/) and has [`Button`](https://react-bootstrap.github.io/docs/components/buttons) properties of React Bootstrap. The `loading` replaces the icon by a spinner identical in size.
31
+
32
+ ```typescript
33
+ import { AiOutlineCheck, DownloadButton } from 'react-icons/ai';
34
+ import { makeIconButton } from '@jasperoosthoek/react-toolbox';
35
+
36
+ const CheckButton = () => (
37
+ <IconButton
38
+ size='lg'
39
+ icon={AiOutlineCheck}
40
+ loading={isLoading}
41
+ />
42
+ )
43
+ // Or Simply use makeIconButton to creare a button component
44
+ const DownloadButton = makeIconButton(AiOutlineDownload);
45
+ ```
46
+
47
+ A number of IconButton have been selected from `react-icons` by the author:
48
+
49
+ ```typescript
50
+ import {
51
+ CheckButton, CopyButton, PasteButton, CloseButton, CogButton, CreateButton,
52
+ CreateFolderButton, CreateSubFolderButton, CreateFileButton, DeleteButton, DownButton,
53
+ DownloadButton, EditButton, FlagButton, HideButton, LinkButton, ListButton, MenuButton,
54
+ MoveButton, NotesButton, PencilButton, PlayButton, SaveButton, SearchButton, ShowButton,
55
+ SortButton, SortUpButton, SortDownButton, StopButton, SyncButton, UnCheckButton,
56
+ UnlockButton, UpButton, UploadButton, QuestionnaireButton, DropdownButton, ResetButton
57
+ } from '@jasperoosthoek/react-toolbox';
58
+
59
+ ```
60
+
61
+ ### Confirm button
62
+
63
+ The `ConfirmButton` provides a confirmation modal (popup) to a button component defined before. You can provide it a custom:
64
+
65
+ - `modalTitle`: Title of the modal
66
+ - `modalBody`: Body of the modal or empty
67
+ - `confirmText`: Something like "Are you sure?"
68
+ - `cancelText`: The "Cancel" text to show on the cancel button.
69
+
70
+ The `ConfirmButton` can be used go conveniently go through asynchronous state such as an api operation. Note that the cancel button just closes the modal and nothing happens.
71
+
72
+ - `onConfirm`: What to do when the user presses the "Ok" button, performed inside the component
73
+ - `loading`: A spinner appears next to the "Ok" button and the "Ok" button is disabled.
74
+ - `closeUsingCallback`: (Optional) The `onConfirm` function has finished, `closeUsingCallback` is called if it is a function and the modal is closed.
75
+ - `buttonComponent`: The button component such as `DownloadButton` created above with `makeIconButton`.
76
+
77
+ ```typescript
78
+ import { MoveButton } from '@jasperoosthoek/react-toolbox';
79
+
80
+ const SomeComponent = () => {
81
+ const loading = useMoveLoadingState();
82
+ const handleMove = () => {
83
+ ...
84
+ }
85
+
86
+ return (
87
+ <div>
88
+ ...
89
+
90
+ <ConfirmModal
91
+ modalTitle='Do you want to move the object?'
92
+ loading={loading}
93
+ onConfirm={handleMove}
94
+ buttonComponent={MoveButton}
95
+ />
96
+ </div>
97
+ )
98
+ }
99
+ ```
100
+
101
+ ### The DeleteConfirmButton
102
+
103
+ Very similar to the ConfirmButton but specialized to deleting something. Note that the `buttonComponent` is the `DeleteButton`.
104
+
105
+ ```typescript
106
+ import { MoveButton } from '@jasperoosthoek/react-toolbox';
107
+
108
+ const SomeComponent = () => {
109
+ const loading = useDeleteLoadingState();
110
+ const handleDelete = () => {
111
+ ...
112
+ }
113
+
114
+ return (
115
+ <div>
116
+ ...
117
+
118
+ <DeleteConfirmButton
119
+ loading={loading}
120
+ onDelete={handleMove}
121
+ />
122
+ </div>
123
+ )
124
+ }
125
+ ```
126
+
127
+ ### The ErrorBoundary component
128
+
129
+ Simple `ErrorBoundary` context provider with `useError` hook that can be used to get and clear the error anywhere in the application:
130
+
131
+ ```typescript
132
+ export const App = () => (
133
+ <ErrorBoundary>
134
+ <BrowserRouter />
135
+ // Rest of the app
136
+ </ErrorBoundary>
137
+ );
138
+
139
+
140
+ // React component somewhere in the tree
141
+ const MyComponent = () => {
142
+ const { error, clearError } = useError();
143
+ if (error) console.error(error);
144
+
145
+ return (
146
+ <div
147
+ className='display-error'
148
+ onClick={() => clearError()}
149
+ >
150
+ {error && 'An error occurred, click to clear'}
151
+ <div>
152
+ )
153
+ }
154
+
155
+ ```
package/change-log.md CHANGED
@@ -293,4 +293,7 @@
293
293
 
294
294
  ##### Version 0.7.2
295
295
  - Fix error when supplying `FormModal` with empty `FormFields`
296
- - Fix placing `selected` on `option` html tag that breaks Reacts best practices
296
+ - Fix placing `selected` on `option` html tag that breaks Reacts best practices
297
+
298
+ ##### Version 0.7.3
299
+ - Upgrade to React@19.1.0
@@ -1,6 +1,6 @@
1
1
  import React, { ReactElement } from 'react';
2
2
  import { Button } from 'react-bootstrap';
3
- import { ButtonProps } from './IconButtons';
3
+ import { type ButtonProps } from './IconButtons';
4
4
  export interface ConfirmButtonProps extends ButtonProps {
5
5
  modalTitle?: ReactElement | string;
6
6
  modalBody?: ReactElement | string;