Skip to content

Commit d5ba0ab

Browse files
committed
types: types for UI Schema
1 parent 5a51102 commit d5ba0ab

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

src/types/UISchema.type.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { InputProps, AutocompleteProps, ButtonProps } from '@mui/material';
2+
import { UIWidgetType } from './ui/UIWidget.type';
3+
import { UISchemaPageType } from './ui/UIPage.type';
4+
import { UISchemaValidations } from './ui/UIValidations.type';
5+
6+
interface UISchemaAutoCompleteProps<T> extends Omit<AutocompleteProps<{}, boolean, boolean, false>, 'options' | 'renderInput'> {
7+
options?: ReadonlyArray<T>;
8+
renderInput?: any;
9+
}
10+
11+
type UISchemaOptions = InputProps
12+
| UISchemaAutoCompleteProps<{}>
13+
| ButtonProps
14+
| HTMLInputElement & { isMulti?: boolean; buttonTitle?: string; icon?: string; }
15+
16+
type UISchemaProps = {
17+
'ui:widget'?: UIWidgetType;
18+
'ui:autofocus'?: boolean;
19+
'ui:emptyValue'?: string;
20+
'ui:isClearable'?: boolean;
21+
'ui:help'?: string;
22+
'ui:placeholder'?: string;
23+
'ui:activeCompColor'?: string;
24+
'ui:component'?: string;
25+
'ui:interceptor'?: string;
26+
'ui:title'?: string;
27+
'ui:description'?: string;
28+
'mui:className'?: string;
29+
'mui:inputProps'?: InputProps;
30+
'ui:validations'?: UISchemaValidations;
31+
'ui:options'?: string | UISchemaOptions; // add types
32+
'ui:props'?: UISchemaOptions;
33+
};
34+
35+
type UISchemaPropsObj = {
36+
[key: string]: UISchemaProps;
37+
};
38+
39+
export type UISchemaType<T> = {
40+
[key in keyof T]: UISchemaPropsObj | UISchemaProps | UISchemaPageType;
41+
} & {
42+
'ui:page'?: UISchemaPageType;
43+
};

src/types/ui/UIPage.type.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { CSSProperties } from 'react';
2+
3+
export type UILayoutTabs = 'tabs';
4+
export type UILayoutSteps = 'steps';
5+
export type UIPageProps = {
6+
'ui:schemaErrors'?: boolean;
7+
};
8+
9+
export type UISchemaPageType = {
10+
'ui:layout': UILayoutTabs | UILayoutSteps;
11+
'props'?: UIPageProps;
12+
'style'?: CSSProperties;
13+
'tabs'?: {
14+
'style': CSSProperties;
15+
},
16+
'tab'?: {
17+
'style': CSSProperties;
18+
}
19+
};

src/types/ui/UIValidations.type.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type UIValidationMinLength = 'minLength';
2+
export type UIValidationMaxLength = 'maxLength';
3+
export type UIValidationMaximum = 'maximum';
4+
export type UIValidationMinimum = 'minimum';
5+
export type UIValidationPattern = 'pattern';
6+
7+
type ValidationNames = UIValidationMinLength
8+
| UIValidationMaxLength
9+
| UIValidationMaximum
10+
| UIValidationMinimum
11+
| UIValidationPattern;
12+
type ValidationValues = {
13+
'value': number;
14+
'message': string;
15+
'inline': boolean;
16+
};
17+
18+
export type UISchemaValidations = {
19+
[key in ValidationNames]?: ValidationValues;
20+
};

src/types/ui/UIWidget.type.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export type UISchemaTypeAutoComplete = 'material-auto-complete';
2+
export type UISchemaTypeMaterialSelect = 'material-select';
3+
export type UISchemaTypeUpload = 'upload';
4+
export type UISchemaTypeTextArea = 'textarea';
5+
export type UISchemaTypePassword = 'password';
6+
export type UISchemaTypeMaterialDate = 'material-date';
7+
export type UISchemaTypeUpDown = 'updown';
8+
export type UISchemaTypeRadio = 'radio';
9+
export type UISchemaTypeMaterialMultiSelect = 'material-multiselect';
10+
export type UISchemaTypeCreatableSelect = 'creatable-select';
11+
export type UISchemaTypeCheckBoxes = 'checkboxes';
12+
13+
export type UIWidgetType = UISchemaTypeAutoComplete
14+
| UISchemaTypeMaterialSelect
15+
| UISchemaTypeUpload
16+
| UISchemaTypeTextArea
17+
| UISchemaTypePassword
18+
| UISchemaTypeMaterialDate
19+
| UISchemaTypeUpDown
20+
| UISchemaTypeRadio
21+
| UISchemaTypeMaterialMultiSelect
22+
| UISchemaTypeCreatableSelect
23+
| UISchemaTypeCheckBoxes;

0 commit comments

Comments
 (0)