@jasperoosthoek/react-toolbox 0.9.3 → 0.9.5
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 +455 -155
- package/change-log.md +11 -1
- package/dist/components/forms/FormField.d.ts +1 -0
- package/dist/components/forms/FormModal.d.ts +3 -2
- package/dist/components/forms/FormModalProvider.d.ts +4 -10
- package/dist/components/forms/FormProvider.d.ts +3 -0
- package/dist/components/forms/fields/FormInput.d.ts +1 -1
- package/dist/index.es.js +2188 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +28 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +26 -12
- package/src/components/forms/FormField.tsx +3 -0
- package/src/components/forms/FormModal.tsx +32 -19
- package/src/components/forms/FormModalProvider.tsx +5 -5
- package/src/components/forms/FormProvider.tsx +7 -1
- package/src/components/forms/fields/FormBadgesSelection.tsx +3 -2
- package/src/components/forms/fields/FormCheckbox.tsx +8 -10
- package/src/components/forms/fields/FormDropdown.tsx +4 -4
- package/src/components/forms/fields/FormInput.tsx +6 -6
- package/src/components/forms/fields/FormSelect.tsx +4 -3
- package/src/components/tables/DataTable.tsx +1 -7
- package/dist/index.js +0 -3
- package/dist/index.js.LICENSE.txt +0 -15
- package/src/__tests__/buttons.test.tsx +0 -545
- package/src/__tests__/errors.test.tsx +0 -339
- package/src/__tests__/forms.test.tsx +0 -3021
- package/src/__tests__/hooks.test.tsx +0 -413
- package/src/__tests__/indicators.test.tsx +0 -284
- package/src/__tests__/localization.test.tsx +0 -462
- package/src/__tests__/login.test.tsx +0 -417
- package/src/__tests__/setupTests.ts +0 -328
- package/src/__tests__/tables.test.tsx +0 -609
- package/src/__tests__/timeAndDate.test.tsx +0 -308
- package/src/__tests__/utils.test.tsx +0 -422
package/README.md
CHANGED
|
@@ -1,155 +1,455 @@
|
|
|
1
|
-
# React Toolbox
|
|
2
|
-
|
|
3
|
-
A library of
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
@@ -336,4 +336,14 @@
|
|
|
336
336
|
- Make types in `FormModalProvider` more flexible
|
|
337
337
|
|
|
338
338
|
##### Version 0.9.3
|
|
339
|
-
- Fix types of updater functions in `FormModalProvider`
|
|
339
|
+
- Fix types of updater functions in `FormModalProvider`
|
|
340
|
+
|
|
341
|
+
##### Version 0.9.4
|
|
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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
2
|
export type ModalTitle = ReactElement | string;
|
|
3
3
|
export type Width = 25 | 50 | 75 | 100;
|
|
4
4
|
export type FormModalProps = {
|
|
@@ -9,7 +9,8 @@ export type FormModalProps = {
|
|
|
9
9
|
width?: Width;
|
|
10
10
|
submitText?: string;
|
|
11
11
|
cancelText?: string;
|
|
12
|
+
children?: React.ReactNode;
|
|
12
13
|
};
|
|
13
|
-
export declare const FormModal: ({ show, onHide, modalTitle, dialogClassName, width, submitText, cancelText, }: FormModalProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export declare const FormModal: ({ show, onHide, modalTitle, dialogClassName, width, submitText, cancelText, children, }: FormModalProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
14
15
|
export declare const FormFieldsRenderer: () => import("react/jsx-runtime").JSX.Element | null;
|
|
15
16
|
export declare const DisabledFormField: ({ value }: any) => import("react/jsx-runtime").JSX.Element;
|