@jasperoosthoek/react-toolbox 0.9.4 → 0.10.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.
Files changed (38) hide show
  1. package/README.md +455 -155
  2. package/change-log.md +18 -1
  3. package/dist/components/forms/FormField.d.ts +13 -0
  4. package/dist/components/forms/FormModal.d.ts +3 -2
  5. package/dist/components/forms/FormProvider.d.ts +3 -0
  6. package/dist/components/forms/fields/FormInput.d.ts +1 -1
  7. package/dist/components/indicators/FixedLoadingIndicator.d.ts +16 -0
  8. package/dist/components/tables/DataTable.d.ts +2 -2
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.es.js +2235 -0
  11. package/dist/index.es.js.map +1 -0
  12. package/dist/index.umd.js +28 -0
  13. package/dist/index.umd.js.map +1 -0
  14. package/package.json +26 -12
  15. package/src/components/forms/FormField.tsx +6 -2
  16. package/src/components/forms/FormModal.tsx +38 -20
  17. package/src/components/forms/FormProvider.tsx +7 -1
  18. package/src/components/forms/fields/FormBadgesSelection.tsx +20 -9
  19. package/src/components/forms/fields/FormCheckbox.tsx +8 -10
  20. package/src/components/forms/fields/FormDropdown.tsx +4 -5
  21. package/src/components/forms/fields/FormInput.tsx +6 -6
  22. package/src/components/forms/fields/FormSelect.tsx +4 -3
  23. package/src/components/indicators/FixedLoadingIndicator.tsx +49 -0
  24. package/src/components/tables/DataTable.tsx +27 -30
  25. package/src/index.ts +1 -0
  26. package/dist/index.js +0 -3
  27. package/dist/index.js.LICENSE.txt +0 -15
  28. package/src/__tests__/buttons.test.tsx +0 -545
  29. package/src/__tests__/errors.test.tsx +0 -339
  30. package/src/__tests__/forms.test.tsx +0 -3021
  31. package/src/__tests__/hooks.test.tsx +0 -413
  32. package/src/__tests__/indicators.test.tsx +0 -284
  33. package/src/__tests__/localization.test.tsx +0 -462
  34. package/src/__tests__/login.test.tsx +0 -417
  35. package/src/__tests__/setupTests.ts +0 -328
  36. package/src/__tests__/tables.test.tsx +0 -609
  37. package/src/__tests__/timeAndDate.test.tsx +0 -308
  38. package/src/__tests__/utils.test.tsx +0 -422
package/README.md CHANGED
@@ -1,155 +1,455 @@
1
- # React Toolbox
2
-
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
- ```
1
+ # React Toolbox
2
+
3
+ A comprehensive library of React components that integrates seamlessly with [react-bootstrap](https://react-bootstrap.github.io/). Build modern, interactive applications faster with pre-built, customizable components.
4
+
5
+ **[Live Dashboard Demo](https://dashboard-demo-olive-eight.vercel.app/employees)** | **[Dashboard Demo Source](https://github.com/jasperoosthoek/dashboard-demo)**
6
+
7
+ ## Table of Contents
8
+
9
+ - [Installation](#installation)
10
+ - [Quick Start](#quick-start)
11
+ - [Examples](#examples)
12
+ - [Components](#components)
13
+ - [DataTable](#datatable)
14
+ - [Form System](#form-system)
15
+ - [Button Components](#button-components)
16
+ - [Utilities](#utilities)
17
+ - [Development](#development)
18
+ - [Contributing](#contributing)
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install @jasperoosthoek/react-toolbox
24
+ ```
25
+
26
+ ### Required Peer Dependencies
27
+
28
+ ```bash
29
+ npm install react react-dom react-bootstrap bootstrap date-fns date-fns-tz react-dnd react-icons react-localization
30
+ ```
31
+
32
+ ### Setup
33
+
34
+ Add Bootstrap CSS to your project:
35
+
36
+ ```typescript
37
+ import 'bootstrap/dist/css/bootstrap.min.css';
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ### Run Examples Locally
43
+
44
+ ```bash
45
+ git clone https://github.com/jasperoosthoek/react-toolbox.git
46
+ cd react-toolbox
47
+ npm install
48
+ npm run dev # Opens interactive examples at localhost:5173
49
+ ```
50
+
51
+ ### Basic Usage
52
+
53
+ ```typescript
54
+ import { FormProvider, FormInput, DataTable } from '@jasperoosthoek/react-toolbox';
55
+
56
+ const App = () => {
57
+ const formFields = {
58
+ name: { required: true, initialValue: '' },
59
+ email: { required: true, initialValue: '' }
60
+ };
61
+
62
+ const handleSubmit = (data) => {
63
+ console.log('Form submitted:', data);
64
+ };
65
+
66
+ return (
67
+ <FormProvider formFields={formFields} onSubmit={handleSubmit}>
68
+ <FormInput name="name" label="Full Name" />
69
+ <FormInput name="email" label="Email" type="email" />
70
+ <button type="submit">Submit</button>
71
+ </FormProvider>
72
+ );
73
+ };
74
+ ```
75
+
76
+ ## Examples
77
+
78
+ The [`src/examples`](https://github.com/jasperoosthoek/react-toolbox/tree/main/src/examples) directory contains comprehensive, working examples demonstrating all components and usage patterns.
79
+
80
+ ### Available Examples
81
+
82
+ | Category | Example | Description | Source Code |
83
+ |----------|---------|-------------|-------------|
84
+ | **DataTable** | Basic DataTable | Column sorting and basic functionality | [DataTableExamples.tsx#L20-L50](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/DataTableExamples.tsx#L20-L50) |
85
+ | | Paginated DataTable | Search, pagination, and page size controls | [DataTableExamples.tsx#L52-L85](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/DataTableExamples.tsx#L52-L85) |
86
+ | | Editable DataTable | Row click to edit with modal forms | [DataTableExamples.tsx#L87-L180](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/DataTableExamples.tsx#L87-L180) |
87
+ | | Drag & Drop DataTable | Reorderable rows with drag and drop | [DataTableExamples.tsx#L182-L220](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/DataTableExamples.tsx#L182-L220) |
88
+ | | Custom Renderer DataTable | Advanced cell rendering and actions | [DataTableExamples.tsx#L222-L320](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/DataTableExamples.tsx#L222-L320) |
89
+ | | Integrated Form DataTable | Full CRUD with FormModalProvider | [DataTableExamples.tsx#L322-L450](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/DataTableExamples.tsx#L322-L450) |
90
+ | **Forms** | Custom Form Layout | FormProvider with direct component usage | [FormExamples.tsx#L15-L75](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/FormExamples.tsx#L15-L75) |
91
+ | | Modal Forms | FormModalProvider for create/edit modals | [FormExamples.tsx#L88-L125](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/FormExamples.tsx#L88-L125) |
92
+ | | Flexible Forms | FormProvider with FormModal integration | [FormExamples.tsx#L128-L165](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/FormExamples.tsx#L128-L165) |
93
+ | | Auto-Rendered Forms | FormFieldsRenderer with automatic components | [FormExamples.tsx#L168-L215](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/FormExamples.tsx#L168-L215) |
94
+ | | Mixed Form Approach | Direct components with convenience wrappers | [FormExamples.tsx#L235-L295](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/FormExamples.tsx#L235-L295) |
95
+ | **IconButtons** | All IconButtons | Complete showcase of available buttons | [IconButtonsExamples.tsx#L15-L120](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/IconButtonsExamples.tsx#L15-L120) |
96
+ | | Button Sizes & Variants | Different sizes and Bootstrap variants | [IconButtonsExamples.tsx#L122-L180](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/IconButtonsExamples.tsx#L122-L180) |
97
+ | | Custom IconButtons | Creating custom buttons with makeIconButton | [IconButtonsExamples.tsx#L182-L240](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/IconButtonsExamples.tsx#L182-L240) |
98
+ | | Buttons with Text | IconButtons with text labels | [IconButtonsExamples.tsx#L242-L290](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/IconButtonsExamples.tsx#L242-L290) |
99
+ | | Button Groups | IconButtons in toolbars and groups | [IconButtonsExamples.tsx#L292-L350](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/IconButtonsExamples.tsx#L292-L350) |
100
+ | | Upload Text Button | File upload with text reading | [IconButtonsExamples.tsx#L352-L400](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/IconButtonsExamples.tsx#L352-L400) |
101
+ | **Confirm Buttons** | ConfirmButton | Modal confirmations for actions | [ButtonComponentsExamples.tsx#L15-L120](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/ButtonComponentsExamples.tsx#L15-L120) |
102
+ | | DeleteConfirmButton | Specialized delete confirmations | [ButtonComponentsExamples.tsx#L122-L180](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/ButtonComponentsExamples.tsx#L122-L180) |
103
+ | | Advanced Patterns | Complex confirmation scenarios | [ButtonComponentsExamples.tsx#L182-L280](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/ButtonComponentsExamples.tsx#L182-L280) |
104
+ | **Localization** | Basic Localization | Using text`localization_string` pattern | [LocalizationExamples.tsx#L20-L120](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/LocalizationExamples.tsx#L20-L120) |
105
+ | | Custom Strings | Adding custom localization with functions | [LocalizationExamples.tsx#L122-L200](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/LocalizationExamples.tsx#L122-L200) |
106
+ | | Form Localization | Localized forms and validation | [LocalizationExamples.tsx#L202-L250](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/LocalizationExamples.tsx#L202-L250) |
107
+ | | DataTable Localization | Localized table components | [LocalizationExamples.tsx#L252-L290](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/LocalizationExamples.tsx#L252-L290) |
108
+ | | Language Switcher | Building language switching components | [LocalizationExamples.tsx#L292-L330](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/LocalizationExamples.tsx#L292-L330) |
109
+ | | Complete Reference | All available localization strings | [LocalizationExamples.tsx#L332-L400](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/LocalizationExamples.tsx#L332-L400) |
110
+
111
+ ### Development Examples
112
+
113
+ - **Local Development**: `npm run dev` - Interactive examples with hot reload
114
+ - **Build Examples**: `npm run build:examples` - Static build for deployment
115
+ - **Test Components**: `npm test` - Complete test suite
116
+
117
+ ## Components
118
+
119
+ ### DataTable
120
+
121
+ The flagship component - a highly customizable and interactive data table with powerful features for modern applications.
122
+
123
+ #### Key Features
124
+
125
+ - **Column Sorting**: Click headers to sort ascending/descending
126
+ - **Pagination**: Navigate large datasets smoothly
127
+ - **Drag & Drop**: Reorder rows/columns with intuitive drag-and-drop
128
+ - **Row Click to Edit**: Open modal forms for quick updates
129
+ - **Real-time Search**: Filter data with configurable search
130
+ - **Flexible Rendering**: Custom cell renderers and formatters
131
+
132
+ #### Basic Usage
133
+
134
+ ```typescript
135
+ import { DataTable } from '@jasperoosthoek/react-toolbox';
136
+
137
+ const columns = [
138
+ { name: 'Name', orderBy: 'name' },
139
+ { name: 'Email', orderBy: 'email' },
140
+ { name: 'Actions', className: 'text-center' }
141
+ ];
142
+
143
+ <DataTable
144
+ data={users}
145
+ columns={columns}
146
+ onRowClick={(user) => openEditModal(user)}
147
+ searchable
148
+ pagination
149
+ pageSize={10}
150
+ />
151
+ ```
152
+
153
+ **[Full DataTable Documentation](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/components/tables/DataTable.tsx)** | **[See Live Demo](https://dashboard-demo-olive-eight.vercel.app/employees)**
154
+
155
+ ### Form System
156
+
157
+ A comprehensive form architecture with provider pattern, validation, and modal integration.
158
+
159
+ #### Components
160
+
161
+ - **FormProvider**: Context provider for form state management
162
+ - **FormModal**: Modal forms with built-in submit/cancel actions
163
+ - **FormModalProvider**: Simplified provider for create/edit modals
164
+ - **Form Fields**: `FormInput`, `FormSelect`, `FormCheckbox`, `FormTextarea`, `FormDropdown`, `FormBadgesSelection`
165
+
166
+ #### Quick Examples
167
+
168
+ **Basic Form with Validation**
169
+ ```typescript
170
+ // See complete example: FormExamples.tsx#L15-L75
171
+ const formFields = {
172
+ name: { required: true, initialValue: '' },
173
+ email: { required: true, initialValue: '' }
174
+ };
175
+
176
+ const validate = (data) => {
177
+ const errors = {};
178
+ if (data.email && !data.email.includes('@')) {
179
+ errors.email = 'Invalid email format';
180
+ }
181
+ return errors;
182
+ };
183
+
184
+ <FormProvider formFields={formFields} onSubmit={handleSubmit} validate={validate}>
185
+ <FormInput name="name" label="Full Name" />
186
+ <FormInput name="email" label="Email" type="email" />
187
+ </FormProvider>
188
+ ```
189
+
190
+ **Modal Forms**
191
+ ```typescript
192
+ // See complete example: FormExamples.tsx#L88-L125
193
+ <FormModalProvider
194
+ formFields={formFields}
195
+ onCreate={handleCreate}
196
+ onUpdate={handleUpdate}
197
+ createModalTitle="Create New Item"
198
+ >
199
+ <FormCreateModalButton>Create New Item</FormCreateModalButton>
200
+ </FormModalProvider>
201
+ ```
202
+
203
+ **[View All Form Examples](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/FormExamples.tsx)**
204
+
205
+ ### Button Components
206
+
207
+ Rich collection of icon buttons with loading states and confirmation dialogs.
208
+
209
+ #### IconButtons
210
+
211
+ Over 30 pre-built icon buttons using [react-icons](https://react-icons.github.io/react-icons/):
212
+
213
+ ```typescript
214
+ import {
215
+ CheckButton, EditButton, DeleteButton, SaveButton,
216
+ DownloadButton, UploadButton, CreateButton, CopyButton,
217
+ SearchButton, SortButton, SyncButton, MoveButton,
218
+ // ... and many more
219
+ } from '@jasperoosthoek/react-toolbox';
220
+
221
+ <EditButton onClick={handleEdit} loading={isLoading} />
222
+ <DeleteButton onClick={handleDelete} disabled={!canDelete} />
223
+ ```
224
+
225
+ #### Custom IconButtons
226
+
227
+ ```typescript
228
+ import { makeIconButton } from '@jasperoosthoek/react-toolbox';
229
+ import { AiOutlineCheck } from 'react-icons/ai';
230
+
231
+ const CustomCheckButton = makeIconButton(AiOutlineCheck);
232
+
233
+ <CustomCheckButton onClick={handleCheck} loading={isLoading} />
234
+ ```
235
+
236
+ #### Confirmation Dialogs
237
+
238
+ ```typescript
239
+ import { ConfirmButton, DeleteConfirmButton } from '@jasperoosthoek/react-toolbox';
240
+
241
+ <ConfirmButton
242
+ modalTitle="Are you sure?"
243
+ confirmText="This action cannot be undone"
244
+ onConfirm={handleAction}
245
+ loading={isLoading}
246
+ buttonComponent={EditButton}
247
+ />
248
+
249
+ <DeleteConfirmButton
250
+ onDelete={handleDelete}
251
+ loading={isDeleting}
252
+ />
253
+ ```
254
+
255
+ **[View All Button Components](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/components/buttons/IconButtons.tsx)** | **[See Button Examples](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/IconButtonsExamples.tsx)**
256
+
257
+ ### Localization System
258
+
259
+ Comprehensive internationalization support with template string syntax and function interpolation.
260
+
261
+ #### Features
262
+
263
+ - **Template String Syntax**: Use `text`localization_string`` for clean, readable code
264
+ - **Multi-language Support**: Built-in English, French, and Dutch translations
265
+ - **Function Interpolation**: Dynamic strings with parameters and pluralization
266
+ - **Custom Strings**: Add your own localization strings easily
267
+ - **Component Integration**: All components automatically use localized strings
268
+
269
+ #### Basic Usage
270
+
271
+ ```typescript
272
+ import { LocalizationProvider, useLocalization } from '@jasperoosthoek/react-toolbox';
273
+
274
+ const MyComponent = () => {
275
+ const { text, lang, setLanguage } = useLocalization();
276
+
277
+ return (
278
+ <div>
279
+ <h1>{text`save`}</h1>
280
+ <p>{text`are_you_sure`}</p>
281
+ <button onClick={() => setLanguage('fr')}>
282
+ Switch to French
283
+ </button>
284
+ </div>
285
+ );
286
+ };
287
+
288
+ // Wrap your app with LocalizationProvider
289
+ <LocalizationProvider lang="en">
290
+ <MyComponent />
291
+ </LocalizationProvider>
292
+ ```
293
+
294
+ #### Custom Localization Strings
295
+
296
+ ```typescript
297
+ const customStrings = {
298
+ en: {
299
+ welcome_message: "Welcome to our app!",
300
+ user_count: (count) => `${count} user${count === 1 ? '' : 's'} online`,
301
+ greeting: (name) => `Hello, ${name}!`,
302
+ },
303
+ fr: {
304
+ welcome_message: "Bienvenue dans notre application!",
305
+ user_count: (count) => `${count} utilisateur${count === 1 ? '' : 's'} en ligne`,
306
+ greeting: (name) => `Bonjour, ${name}!`,
307
+ },
308
+ };
309
+
310
+ const { setLocalization, text } = useLocalization();
311
+ setLocalization(customStrings);
312
+
313
+ // Usage with parameters
314
+ <h1>{text`welcome_message`}</h1>
315
+ <p>{text`user_count${userCount}`}</p>
316
+ <span>{text`greeting${'John'}`}</span>
317
+ ```
318
+
319
+ #### Available Default Strings
320
+
321
+ - **UI Elements**: `save`, `cancel`, `delete`, `search`, `select`, `close`, `ok`
322
+ - **Authentication**: `login`, `logout`, `your_email`, `enter_password`, `forgot_password`
323
+ - **Form Elements**: `required_field`, `choose_one`, `everything`
324
+ - **Table Elements**: `number_of_rows`, `no_information_to_display`, `information_is_being_loaded`
325
+ - **Modal Elements**: `modal_create`, `modal_edit`, `are_you_sure`
326
+
327
+ **[View All Localization Examples](https://github.com/jasperoosthoek/react-toolbox/blob/main/src/examples/LocalizationExamples.tsx)**
328
+
329
+ ### Utilities
330
+
331
+ #### Custom Hooks
332
+
333
+ **useLocalStorage** - Persistent state management
334
+ ```typescript
335
+ const [theme, setTheme] = useLocalStorage('theme', 'light');
336
+ ```
337
+
338
+ **useError** - Global error handling with ErrorBoundary
339
+ ```typescript
340
+ const { error, clearError } = useError();
341
+ ```
342
+
343
+ **useLocalization** - Internationalization support
344
+ ```typescript
345
+ const { getString } = useLocalization();
346
+ ```
347
+
348
+ #### Additional Components
349
+
350
+ - **LoadingIndicator**: Consistent loading states
351
+ - **CheckIndicator**: Success/validation indicators
352
+ - **SearchBox**: Integrated search functionality
353
+ - **DragAndDropList**: Reorderable lists with react-dnd
354
+ - **LoginPage**: Pre-built authentication forms
355
+
356
+ **[View All Utilities](https://github.com/jasperoosthoek/react-toolbox/tree/main/src/utils)**
357
+
358
+ ## Development
359
+
360
+ ### Project Structure
361
+
362
+ ```
363
+ src/
364
+ ├── components/
365
+ │ ├── buttons/ # Icon buttons, confirmations
366
+ │ ├── forms/ # Form providers, modals, fields
367
+ │ ├── tables/ # DataTable, search, drag & drop
368
+ │ ├── indicators/ # Loading, success indicators
369
+ │ ├── errors/ # Error boundaries
370
+ │ └── login/ # Authentication components
371
+ ├── utils/ # Hooks, utilities, helpers
372
+ ├── localization/ # i18n support
373
+ └── examples/ # Working examples & demos
374
+ ├── DataTableExamples.tsx # DataTable demonstrations
375
+ ├── FormExamples.tsx # Form system examples
376
+ ├── IconButtonsExamples.tsx # IconButton showcase
377
+ ├── ButtonComponentsExamples.tsx # Confirm button examples
378
+ ├── LocalizationExamples.tsx # Localization system examples
379
+ └── data/ # Mock data for examples
380
+ ```
381
+
382
+ ### Available Scripts
383
+
384
+ ```bash
385
+ # Development
386
+ npm run dev # Start examples with hot reload
387
+ npm run build:examples # Build examples for deployment
388
+
389
+ # Library
390
+ npm run build # Build library for distribution
391
+ npm run test # Run test suite
392
+ npm run test:watch # Watch mode testing
393
+ npm run test:coverage # Coverage report
394
+
395
+ # Publishing
396
+ npm run prepublishOnly # Test + build before publishing
397
+ ```
398
+
399
+ ### Testing
400
+
401
+ Comprehensive test suite with Jest and React Testing Library:
402
+
403
+ ```bash
404
+ npm test # Run all tests
405
+ npm run test:watch # Watch mode for development
406
+ npm run test:coverage # Generate coverage report
407
+ ```
408
+
409
+ ### TypeScript Support
410
+
411
+ Full TypeScript support with strict type checking:
412
+
413
+ - **Library Types**: `dist/index.d.ts`
414
+ - **Type Safety**: Strict TypeScript configuration
415
+ - **IntelliSense**: Full autocomplete and type hints
416
+
417
+ ## Contributing
418
+
419
+ We welcome contributions! Here's how to get started:
420
+
421
+ ### Development Setup
422
+
423
+ ```bash
424
+ git clone https://github.com/jasperoosthoek/react-toolbox.git
425
+ cd react-toolbox
426
+ npm install
427
+ npm run dev # Start development server
428
+ ```
429
+
430
+ ### Guidelines
431
+
432
+ 1. **Add Examples**: New components should include working examples
433
+ 2. **Write Tests**: Maintain test coverage for all components
434
+ 3. **Update Documentation**: Keep README and examples in sync
435
+ 4. **Follow TypeScript**: Use strict typing for all components
436
+ 5. **Test Locally**: Run examples and tests before submitting
437
+
438
+ ### Reporting Issues
439
+
440
+ Found a bug? Have a feature request? Please create an issue on [GitHub](https://github.com/jasperoosthoek/react-toolbox/issues).
441
+
442
+ ## License
443
+
444
+ MIT License - see [LICENSE](LICENSE) for details.
445
+
446
+ ## Links
447
+
448
+ - **[Dashboard Demo](https://dashboard-demo-olive-eight.vercel.app/employees)** - Live demonstration
449
+ - **[Dashboard Source](https://github.com/jasperoosthoek/dashboard-demo)** - Complete application example
450
+ - **[GitHub Repository](https://github.com/jasperoosthoek/react-toolbox)** - Source code and issues
451
+ - **[NPM Package](https://www.npmjs.com/package/@jasperoosthoek/react-toolbox)** - Installation and versions
452
+
453
+ ---
454
+
455
+ **Built with React, TypeScript, and react-bootstrap**
package/change-log.md CHANGED
@@ -339,4 +339,21 @@
339
339
  - Fix types of updater functions in `FormModalProvider`
340
340
 
341
341
  ##### Version 0.9.4
342
- - Make `initialState` in `FormModalProvider` optional
342
+ - Make `initialState` in `FormModalProvider` optional
343
+
344
+ ##### Version 0.9.5
345
+ - Move examples to src directory and turn into React app using Vite
346
+ - Build module using Vite instead of Webpack
347
+ - Make `onChange` argument of `FormInput` optional as it can get it from the form context
348
+ - No longer show "Select" option in number of rows dropdown of `DataTables` component
349
+ - New `formId` in form context that is used to generate unique `controlIds` in case of multiple forms
350
+
351
+ ##### Version 0.10.0
352
+ - **BREAKING**: Replace `filterColumn` argument in `DataTable` component by `search` prop on `columns`
353
+ - Fix: sums row in `DataTable` component does not respond to search box and changes of input data
354
+ - Fix: missing `key` prop in `FormFieldsRenderer` component
355
+ - Improve performance of search algorithm in `DataTable` component to be able to handle larger data sets
356
+ - All form input components accept `className` prop that is given to `Form.Group` component
357
+ - Add 'mt-2' class to `FormCheckbox` improve vertical spacing
358
+ - `FormBadgesSelection` uses same value/label inputs as `FormSelect`
359
+ - Move `FixedLoadingIndicator` from examples to `/src/components/indicators`
@@ -11,6 +11,17 @@ export declare const useFormField: (componentProps: {
11
11
  required?: boolean;
12
12
  [key: string]: any;
13
13
  }) => {
14
+ value: string;
15
+ onChange: () => void;
16
+ isInvalid: boolean;
17
+ error: null;
18
+ label: undefined;
19
+ required: boolean;
20
+ mergedProps: {};
21
+ submit: () => void;
22
+ formId: string;
23
+ className?: undefined;
24
+ } | {
14
25
  value: FormValue;
15
26
  onChange: (value: FormValue) => void;
16
27
  isInvalid: boolean;
@@ -19,4 +30,6 @@ export declare const useFormField: (componentProps: {
19
30
  required: boolean | undefined;
20
31
  mergedProps: any;
21
32
  submit: () => void;
33
+ formId: string;
34
+ className: any;
22
35
  };