@bsol-oss/react-datatable5 12.0.0-beta.56 → 12.0.0-beta.58
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 +192 -0
- package/dist/index.d.ts +76 -2
- package/dist/index.js +676 -60
- package/dist/index.mjs +674 -62
- package/dist/types/components/DatePicker/DatePicker.d.ts +23 -0
- package/dist/types/components/DatePicker/DateTimePicker.d.ts +11 -0
- package/dist/types/components/DatePicker/DurationPicker.d.ts +12 -0
- package/dist/types/components/DatePicker/IsoTimePicker.d.ts +16 -0
- package/dist/types/components/DatePicker/PickerDemo.d.ts +1 -0
- package/dist/types/components/DatePicker/UniversalPicker.d.ts +9 -0
- package/dist/types/components/DatePicker/index.d.ts +7 -0
- package/dist/types/components/Form/SchemaFormContext.d.ts +3 -0
- package/dist/types/components/Form/components/core/FormRoot.d.ts +3 -1
- package/dist/types/components/Form/components/fields/DateTimePicker.d.ts +2 -0
- package/dist/types/components/Form/components/viewers/DateTimeViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/TimeViewer.d.ts +1 -1
- package/dist/types/components/Form/utils/validation.d.ts +49 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +7 -1
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
|
package/dist/index.d.ts
CHANGED
|
@@ -11,10 +11,12 @@ import { RankingInfo } from '@tanstack/match-sorter-utils';
|
|
|
11
11
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
12
12
|
import { JSONSchema7 } from 'json-schema';
|
|
13
13
|
import { ForeignKeyProps as ForeignKeyProps$1 } from '@/components/Form/components/fields/StringInputField';
|
|
14
|
+
import { SupportedLocale as SupportedLocale$1 } from '@/components/Form/utils/validation';
|
|
14
15
|
import { AxiosRequestConfig } from 'axios';
|
|
15
16
|
import * as react_hook_form from 'react-hook-form';
|
|
16
17
|
import { UseFormReturn, FieldValues, SubmitHandler } from 'react-hook-form';
|
|
17
18
|
import { RenderProps, Props } from '@bsol-oss/dayzed-react19';
|
|
19
|
+
import * as ajv_i18n_localize_types from 'ajv-i18n/localize/types';
|
|
18
20
|
|
|
19
21
|
interface DensityToggleButtonProps {
|
|
20
22
|
icon?: React__default.ReactElement;
|
|
@@ -547,6 +549,7 @@ interface FormRootProps<TData extends FieldValues> {
|
|
|
547
549
|
requestOptions?: AxiosRequestConfig;
|
|
548
550
|
getUpdatedData?: () => TData | Promise<TData> | void;
|
|
549
551
|
customErrorRenderer?: (error: unknown) => ReactNode;
|
|
552
|
+
validationLocale?: SupportedLocale$1;
|
|
550
553
|
}
|
|
551
554
|
interface CustomJSONSchema7Definition extends JSONSchema7 {
|
|
552
555
|
variant: string;
|
|
@@ -563,7 +566,7 @@ declare const idPickerSanityCheck: (column: string, foreign_key?: {
|
|
|
563
566
|
column?: string | undefined;
|
|
564
567
|
display_column?: string | undefined;
|
|
565
568
|
} | undefined) => void;
|
|
566
|
-
declare const FormRoot: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, children, order, ignore, include, onSubmit, rowNumber, requestOptions, getUpdatedData, customErrorRenderer, }: FormRootProps<TData>) => react_jsx_runtime.JSX.Element;
|
|
569
|
+
declare const FormRoot: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, children, order, ignore, include, onSubmit, rowNumber, requestOptions, getUpdatedData, customErrorRenderer, validationLocale, }: FormRootProps<TData>) => react_jsx_runtime.JSX.Element;
|
|
567
570
|
|
|
568
571
|
interface DefaultFormProps<TData extends FieldValues> {
|
|
569
572
|
formConfig: Omit<FormRootProps<TData>, "children">;
|
|
@@ -600,6 +603,29 @@ interface GetVariantProps {
|
|
|
600
603
|
selectable: boolean;
|
|
601
604
|
}
|
|
602
605
|
interface DatePickerProps extends Props {
|
|
606
|
+
onDateSelected?: (obj: {
|
|
607
|
+
date: Date;
|
|
608
|
+
}) => void;
|
|
609
|
+
selected: Date | Date[];
|
|
610
|
+
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
611
|
+
showOutsideDays?: boolean;
|
|
612
|
+
date?: Date;
|
|
613
|
+
minDate?: Date;
|
|
614
|
+
maxDate?: Date;
|
|
615
|
+
monthsToDisplay?: number;
|
|
616
|
+
labels?: {
|
|
617
|
+
monthNamesShort: string[];
|
|
618
|
+
weekdayNamesShort: string[];
|
|
619
|
+
backButtonLabel?: string;
|
|
620
|
+
forwardButtonLabel?: string;
|
|
621
|
+
};
|
|
622
|
+
render?: (dayzedData: any) => React__default.ReactNode;
|
|
623
|
+
}
|
|
624
|
+
interface DatePickerLabels {
|
|
625
|
+
monthNamesShort: string[];
|
|
626
|
+
weekdayNamesShort: string[];
|
|
627
|
+
backButtonLabel?: string;
|
|
628
|
+
forwardButtonLabel?: string;
|
|
603
629
|
}
|
|
604
630
|
|
|
605
631
|
interface GetMultiDatesProps {
|
|
@@ -638,6 +664,54 @@ interface RecordDisplayProps {
|
|
|
638
664
|
}
|
|
639
665
|
declare const RecordDisplay: ({ object, boxProps, translate, prefix, }: RecordDisplayProps) => react_jsx_runtime.JSX.Element;
|
|
640
666
|
|
|
667
|
+
declare const localize: {
|
|
668
|
+
en: () => void;
|
|
669
|
+
'zh-HK': ajv_i18n_localize_types.Localize;
|
|
670
|
+
'zh-TW': ajv_i18n_localize_types.Localize;
|
|
671
|
+
'zh-CN': ajv_i18n_localize_types.Localize;
|
|
672
|
+
zh: ajv_i18n_localize_types.Localize;
|
|
673
|
+
};
|
|
674
|
+
type SupportedLocale = keyof typeof localize;
|
|
675
|
+
interface ValidationError {
|
|
676
|
+
field: string;
|
|
677
|
+
message: string;
|
|
678
|
+
value?: unknown;
|
|
679
|
+
schemaPath?: string;
|
|
680
|
+
}
|
|
681
|
+
interface ValidationResult {
|
|
682
|
+
isValid: boolean;
|
|
683
|
+
errors: ValidationError[];
|
|
684
|
+
}
|
|
685
|
+
interface ValidationOptions {
|
|
686
|
+
locale?: SupportedLocale;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Validates data against a JSON Schema using AJV with i18n support
|
|
690
|
+
* @param data - The data to validate
|
|
691
|
+
* @param schema - The JSON Schema to validate against
|
|
692
|
+
* @param options - Validation options including locale
|
|
693
|
+
* @returns ValidationResult containing validation status and errors
|
|
694
|
+
*/
|
|
695
|
+
declare const validateData: (data: unknown, schema: JSONSchema7, options?: ValidationOptions) => ValidationResult;
|
|
696
|
+
/**
|
|
697
|
+
* Creates a reusable validator function for a specific schema with i18n support
|
|
698
|
+
* @param schema - The JSON Schema to create validator for
|
|
699
|
+
* @param locale - The locale to use for error messages
|
|
700
|
+
* @returns A function that validates data against the schema
|
|
701
|
+
*/
|
|
702
|
+
declare const createSchemaValidator: (schema: JSONSchema7, locale?: SupportedLocale) => (data: unknown) => ValidationResult;
|
|
703
|
+
/**
|
|
704
|
+
* Get available locales for validation error messages
|
|
705
|
+
* @returns Array of supported locale codes
|
|
706
|
+
*/
|
|
707
|
+
declare const getSupportedLocales: () => SupportedLocale[];
|
|
708
|
+
/**
|
|
709
|
+
* Check if a locale is supported
|
|
710
|
+
* @param locale - The locale to check
|
|
711
|
+
* @returns Boolean indicating if the locale is supported
|
|
712
|
+
*/
|
|
713
|
+
declare const isLocaleSupported: (locale: string) => locale is "en" | "zh-HK" | "zh-TW" | "zh-CN" | "zh";
|
|
714
|
+
|
|
641
715
|
declare module "@tanstack/react-table" {
|
|
642
716
|
interface ColumnMeta<TData extends RowData, TValue> {
|
|
643
717
|
/**
|
|
@@ -710,4 +784,4 @@ declare module "@tanstack/react-table" {
|
|
|
710
784
|
}
|
|
711
785
|
}
|
|
712
786
|
|
|
713
|
-
export { type CalendarProps, CardHeader, type CardHeaderProps, type CustomJSONSchema7Definition, DataDisplay, type DataDisplayProps, type DataResponse, DataTable, type DataTableDefaultState, type DataTableProps, DataTableServer, type DataTableServerProps, type DatePickerProps, DefaultCardTitle, DefaultForm, type DefaultFormProps, DefaultTable, type DefaultTableProps, DensityToggleButton, type DensityToggleButtonProps, type EditFilterButtonProps, EditSortingButton, type EditSortingButtonProps, type EditViewButtonProps, EmptyState, type EmptyStateProps, ErrorAlert, type ErrorAlertProps, FilterDialog, FormBody, FormRoot, type FormRootProps, FormTitle, type GetColumnsConfigs, type GetDateColorProps, type GetMultiDatesProps, type GetRangeDatesProps, type GetStyleProps, type GetVariantProps, GlobalFilter, PageSizeControl, type PageSizeControlProps, Pagination, type RangeCalendarProps, type RangeDatePickerProps, RecordDisplay, type RecordDisplayProps, ReloadButton, type ReloadButtonProps, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, type Result, RowCountText, Table, TableBody, type TableBodyProps, TableCardContainer, type TableCardContainerProps, TableCards, type TableCardsProps, TableComponent, TableControls, type TableControlsProps, TableDataDisplay, type TableDataDisplayProps, TableFilter, TableFilterTags, TableFooter, type TableFooterProps, TableHeader, type TableHeaderProps, type TableHeaderTexts, TableLoadingComponent, type TableLoadingComponentProps, type TableProps, type TableRendererProps, type TableRowSelectorProps, TableSelector, TableSorter, TableViewer, TextCell, type TextCellProps, type UseDataTableProps, type UseDataTableReturn, type UseDataTableServerProps, type UseDataTableServerReturn, type UseFormProps, ViewDialog, getColumns, getMultiDates, getRangeDates, idPickerSanityCheck, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };
|
|
787
|
+
export { type CalendarProps, CardHeader, type CardHeaderProps, type CustomJSONSchema7Definition, DataDisplay, type DataDisplayProps, type DataResponse, DataTable, type DataTableDefaultState, type DataTableProps, DataTableServer, type DataTableServerProps, type DatePickerLabels, type DatePickerProps, DefaultCardTitle, DefaultForm, type DefaultFormProps, DefaultTable, type DefaultTableProps, DensityToggleButton, type DensityToggleButtonProps, type EditFilterButtonProps, EditSortingButton, type EditSortingButtonProps, type EditViewButtonProps, EmptyState, type EmptyStateProps, ErrorAlert, type ErrorAlertProps, FilterDialog, FormBody, FormRoot, type FormRootProps, FormTitle, type GetColumnsConfigs, type GetDateColorProps, type GetMultiDatesProps, type GetRangeDatesProps, type GetStyleProps, type GetVariantProps, GlobalFilter, PageSizeControl, type PageSizeControlProps, Pagination, type RangeCalendarProps, type RangeDatePickerProps, RecordDisplay, type RecordDisplayProps, ReloadButton, type ReloadButtonProps, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, type Result, RowCountText, type SupportedLocale, Table, TableBody, type TableBodyProps, TableCardContainer, type TableCardContainerProps, TableCards, type TableCardsProps, TableComponent, TableControls, type TableControlsProps, TableDataDisplay, type TableDataDisplayProps, TableFilter, TableFilterTags, TableFooter, type TableFooterProps, TableHeader, type TableHeaderProps, type TableHeaderTexts, TableLoadingComponent, type TableLoadingComponentProps, type TableProps, type TableRendererProps, type TableRowSelectorProps, TableSelector, TableSorter, TableViewer, TextCell, type TextCellProps, type UseDataTableProps, type UseDataTableReturn, type UseDataTableServerProps, type UseDataTableServerReturn, type UseFormProps, type ValidationError, type ValidationOptions, type ValidationResult, ViewDialog, createSchemaValidator, getColumns, getMultiDates, getRangeDates, getSupportedLocales, idPickerSanityCheck, isLocaleSupported, useDataTable, useDataTableContext, useDataTableServer, useForm, validateData, widthSanityCheck };
|