@bsol-oss/react-datatable5 12.0.0-beta.7 → 12.0.0-beta.70

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 (52) hide show
  1. package/README.md +192 -0
  2. package/dist/index.d.ts +277 -83
  3. package/dist/index.js +1577 -469
  4. package/dist/index.mjs +1585 -477
  5. package/dist/types/components/DataTable/DataTable.d.ts +3 -1
  6. package/dist/types/components/DataTable/DataTableServer.d.ts +6 -4
  7. package/dist/types/components/DataTable/DefaultTable.d.ts +6 -9
  8. package/dist/types/components/DataTable/context/DataTableContext.d.ts +21 -3
  9. package/dist/types/components/DataTable/context/useDataTableContext.d.ts +2 -2
  10. package/dist/types/components/DataTable/controls/ReloadButton.d.ts +1 -2
  11. package/dist/types/components/DataTable/controls/ResetFilteringButton.d.ts +1 -4
  12. package/dist/types/components/DataTable/controls/ResetSelectionButton.d.ts +1 -4
  13. package/dist/types/components/DataTable/controls/ResetSortingButton.d.ts +1 -4
  14. package/dist/types/components/DataTable/controls/TableControls.d.ts +10 -2
  15. package/dist/types/components/DataTable/display/TableBody.d.ts +1 -2
  16. package/dist/types/components/DataTable/display/TableCardContainer.d.ts +6 -3
  17. package/dist/types/components/DataTable/display/TableDataDisplay.d.ts +6 -1
  18. package/dist/types/components/DataTable/display/TableFooter.d.ts +1 -5
  19. package/dist/types/components/DataTable/display/TableHeader.d.ts +46 -8
  20. package/dist/types/components/DataTable/useDataTableServer.d.ts +55 -3
  21. package/dist/types/components/DatePicker/DatePicker.d.ts +23 -0
  22. package/dist/types/components/DatePicker/DateTimePicker.d.ts +11 -0
  23. package/dist/types/components/DatePicker/DurationPicker.d.ts +12 -0
  24. package/dist/types/components/DatePicker/IsoTimePicker.d.ts +16 -0
  25. package/dist/types/components/DatePicker/PickerDemo.d.ts +1 -0
  26. package/dist/types/components/DatePicker/UniversalPicker.d.ts +9 -0
  27. package/dist/types/components/DatePicker/index.d.ts +7 -0
  28. package/dist/types/components/Filter/TagFilter.d.ts +5 -1
  29. package/dist/types/components/Form/SchemaFormContext.d.ts +8 -1
  30. package/dist/types/components/Form/components/core/DefaultForm.d.ts +1 -0
  31. package/dist/types/components/Form/components/core/FormRoot.d.ts +9 -2
  32. package/dist/types/components/Form/components/fields/CustomInput.d.ts +8 -0
  33. package/dist/types/components/Form/components/fields/DatePicker.d.ts +2 -7
  34. package/dist/types/components/Form/components/fields/DateTimePicker.d.ts +2 -0
  35. package/dist/types/components/Form/components/fields/EnumPicker.d.ts +2 -1
  36. package/dist/types/components/Form/components/fields/FilePicker.d.ts +2 -5
  37. package/dist/types/components/Form/components/fields/StringInputField.d.ts +19 -5
  38. package/dist/types/components/Form/components/fields/TextAreaInput.d.ts +12 -0
  39. package/dist/types/components/Form/components/fields/TimePicker.d.ts +7 -0
  40. package/dist/types/components/Form/components/fields/types.d.ts +6 -0
  41. package/dist/types/components/Form/components/types/CustomJSONSchema7.d.ts +19 -1
  42. package/dist/types/components/Form/components/viewers/CustomViewer.d.ts +8 -0
  43. package/dist/types/components/Form/components/viewers/DateTimeViewer.d.ts +7 -0
  44. package/dist/types/components/Form/components/viewers/TextAreaViewer.d.ts +12 -0
  45. package/dist/types/components/Form/components/viewers/TimeViewer.d.ts +7 -0
  46. package/dist/types/components/Form/utils/translateWrapper.d.ts +6 -0
  47. package/dist/types/components/Form/utils/validateData.d.ts +9 -0
  48. package/dist/types/components/Form/utils/validation.d.ts +104 -0
  49. package/dist/types/components/TextArea/TextArea.d.ts +22 -0
  50. package/dist/types/components/TimePicker/TimePicker.d.ts +21 -0
  51. package/dist/types/index.d.ts +17 -2
  52. package/package.json +9 -2
package/README.md CHANGED
@@ -8,6 +8,12 @@ The datetable package is built on top of `@tanstack/react-table` and `chakra-ui`
8
8
  npm install @tanstack/react-table @chakra-ui/react @emotion/react @bsol-oss/react-datatable5
9
9
  ```
10
10
 
11
+ For form validation features with internationalization support, also install:
12
+
13
+ ```bash
14
+ npm install ajv ajv-formats ajv-i18n
15
+ ```
16
+
11
17
  ## Usage
12
18
 
13
19
  ### Hook
@@ -82,6 +88,192 @@ GET http://localhost:8081/api/g/core_people?offset=0&limit=10&sorting[0][id]=id&
82
88
  </DataTable>
83
89
  ```
84
90
 
91
+ ### Form Validation with AJV and Internationalization
92
+
93
+ The package now includes built-in JSON Schema validation using AJV (Another JSON Schema Validator) with format support and comprehensive internationalization (i18n) capabilities, including full Traditional Chinese (Hong Kong/Taiwan) support.
94
+
95
+ #### Features
96
+
97
+ - **JSON Schema Validation**: Full JSON Schema Draft 7 support
98
+ - **Format Validation**: Built-in support for date, time, email, UUID, and other formats via `ajv-formats`
99
+ - **Multi-language Support**: Complete i18n support with Traditional Chinese (Hong Kong/Taiwan) and Simplified Chinese
100
+ - **Enhanced Error Messages**: Culturally appropriate error messages in multiple languages
101
+ - **Automatic Validation**: Validation occurs before form submission and confirmation
102
+ - **Custom Error Display**: Collapsible error panels with localized validation feedback
103
+
104
+ #### Supported Languages
105
+
106
+ - **🇺🇸 English (en)** - Default language
107
+ - **🇭🇰 Traditional Chinese - Hong Kong (zh-HK)** - 繁體中文(香港)
108
+ - **🇹🇼 Traditional Chinese - Taiwan (zh-TW)** - 繁體中文(台灣)
109
+ - **🇨🇳 Simplified Chinese (zh-CN, zh)** - 简体中文
110
+
111
+ #### Basic Usage with Internationalization
112
+
113
+ ```tsx
114
+ import { FormRoot, FormBody, validateData, SupportedLocale } from "@bsol-oss/react-datatable5";
115
+
116
+ const schema = {
117
+ type: "object",
118
+ required: ["email", "age"],
119
+ properties: {
120
+ email: {
121
+ type: "string",
122
+ format: "email"
123
+ },
124
+ age: {
125
+ type: "integer",
126
+ minimum: 18,
127
+ maximum: 120
128
+ },
129
+ name: {
130
+ type: "string",
131
+ minLength: 2,
132
+ maxLength: 50
133
+ }
134
+ }
135
+ };
136
+
137
+ // Use Traditional Chinese (Hong Kong) for validation errors
138
+ <FormRoot
139
+ schema={schema}
140
+ validationLocale="zh-HK"
141
+ /* other props */
142
+ >
143
+ <FormBody />
144
+ </FormRoot>
145
+ ```
146
+
147
+ #### Language-specific Examples
148
+
149
+ **Traditional Chinese (Hong Kong):**
150
+ ```tsx
151
+ <FormRoot
152
+ schema={schema}
153
+ validationLocale="zh-HK"
154
+ /* other props */
155
+ >
156
+ <FormBody />
157
+ </FormRoot>
158
+ ```
159
+
160
+ **Traditional Chinese (Taiwan):**
161
+ ```tsx
162
+ <FormRoot
163
+ schema={schema}
164
+ validationLocale="zh-TW"
165
+ /* other props */
166
+ >
167
+ <FormBody />
168
+ </FormRoot>
169
+ ```
170
+
171
+ **Simplified Chinese:**
172
+ ```tsx
173
+ <FormRoot
174
+ schema={schema}
175
+ validationLocale="zh-CN"
176
+ /* other props */
177
+ >
178
+ <FormBody />
179
+ </FormRoot>
180
+ ```
181
+
182
+ #### Manual Validation with Internationalization
183
+
184
+ You can also use the validation utilities directly with language support:
185
+
186
+ ```tsx
187
+ import { validateData, ValidationResult, SupportedLocale } from "@bsol-oss/react-datatable5";
188
+
189
+ // Validate with Traditional Chinese (Hong Kong) error messages
190
+ const result: ValidationResult = validateData(formData, schema, {
191
+ locale: 'zh-HK'
192
+ });
193
+
194
+ if (!result.isValid) {
195
+ console.log("驗證錯誤:", result.errors);
196
+ // Error messages will be in Traditional Chinese
197
+ }
198
+
199
+ // Check supported locales
200
+ import { getSupportedLocales, isLocaleSupported } from "@bsol-oss/react-datatable5";
201
+
202
+ const supportedLocales = getSupportedLocales(); // ['en', 'zh-HK', 'zh-TW', 'zh-CN', 'zh']
203
+ const isSupported = isLocaleSupported('zh-HK'); // true
204
+ ```
205
+
206
+ #### Validation Error Structure
207
+
208
+ ```tsx
209
+ interface ValidationError {
210
+ field: string; // The field that failed validation
211
+ message: string; // User-friendly error message (localized)
212
+ value?: unknown; // The current value that failed
213
+ schemaPath?: string; // JSON Schema path for debugging
214
+ }
215
+ ```
216
+
217
+ #### Dynamic Language Switching
218
+
219
+ ```tsx
220
+ import { SupportedLocale } from "@bsol-oss/react-datatable5";
221
+
222
+ const MyForm = () => {
223
+ const [locale, setLocale] = useState<SupportedLocale>('zh-HK');
224
+
225
+ return (
226
+ <div>
227
+ {/* Language selector */}
228
+ <select value={locale} onChange={(e) => setLocale(e.target.value as SupportedLocale)}>
229
+ <option value="en">English</option>
230
+ <option value="zh-HK">繁體中文(香港)</option>
231
+ <option value="zh-TW">繁體中文(台灣)</option>
232
+ <option value="zh-CN">简体中文</option>
233
+ </select>
234
+
235
+ {/* Form with dynamic locale */}
236
+ <FormRoot
237
+ schema={schema}
238
+ validationLocale={locale}
239
+ /* other props */
240
+ >
241
+ <FormBody />
242
+ </FormRoot>
243
+ </div>
244
+ );
245
+ };
246
+ ```
247
+
248
+ #### Example Validation Messages
249
+
250
+ **English:**
251
+ - "email is required"
252
+ - "Invalid email format"
253
+ - "Must be at least 18"
254
+
255
+ **Traditional Chinese (Hong Kong/Taiwan):**
256
+ - "email 為必填"
257
+ - "無效的 email 格式"
258
+ - "必須至少為 18"
259
+
260
+ **Simplified Chinese:**
261
+ - "email 为必填"
262
+ - "无效的 email 格式"
263
+ - "必须至少为 18"
264
+
265
+ #### Supported Validation Types
266
+
267
+ - **Type validation**: string, number, integer, boolean, object, array
268
+ - **Format validation**: email, date, time, date-time, uuid, uri, etc.
269
+ - **String constraints**: minLength, maxLength, pattern (regex)
270
+ - **Numeric constraints**: minimum, maximum, multipleOf
271
+ - **Array constraints**: minItems, maxItems, uniqueItems
272
+ - **Object constraints**: required properties, additionalProperties
273
+ - **Enum validation**: restricted value sets
274
+
275
+ All validation types are fully supported across all languages with culturally appropriate translations.
276
+
85
277
  For more details of props and examples, please review the stories in storybook platform.
86
278
 
87
279
  ## Development