Skip to content

Commit 73e3b16

Browse files
committed
fix(renderer): fixed typing issues
- fixed constants not properly exporting the definitions objecs - fixed condtion type not allowing nested condition schema - fixed FieldArray not exporting component type with props - fixed field schema not allowing single condition - fixed field schema not accepting actions object - make form renderer extend final form props - fixed Form type net being exported as react component - fixed schema validator not accepting any arguments - changed useFieldApi type input value default to any type
1 parent 3ee2298 commit 73e3b16

File tree

12 files changed

+65
-51
lines changed

12 files changed

+65
-51
lines changed
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
export type ComponentType = 'text-field'|'field-array'|'checkbox'|'sub-form'|'radio'|'tabs'|'tab-item'|'date-picker'|'time-picker'|'wizard'|'switch'|'textarea'|'select'|'plain-text'|'button'|'input-addon-group'|'input-addon-button-group'|'dual-list-select'|'slider';
22

33
interface componentTypes {
4-
TEXT_FIELD: string;
5-
FIELD_ARRAY: string;
6-
CHECKBOX: string;
7-
SUB_FORM: string;
8-
RADIO: string;
9-
TABS: string;
10-
TAB_ITEM: string;
11-
DATE_PICKER: string;
12-
TIME_PICKER: string;
13-
WIZARD: string;
14-
SWITCH: string;
15-
TEXTAREA: string;
16-
SELECT: string;
17-
PLAIN_TEXT: string;
18-
BUTTON: string;
19-
INPUT_ADDON_GROUP: string;
20-
INPUT_ADDON_BUTTON_GROUP: string;
21-
DUAL_LIST_SELECT: string;
22-
SLIDER: string;
4+
TEXT_FIELD: 'text-field';
5+
FIELD_ARRAY: 'field-array';
6+
CHECKBOX: 'checkbox';
7+
SUB_FORM: 'sub-form';
8+
RADIO: 'radio';
9+
TABS: 'tabs';
10+
TAB_ITEM: 'tab-item';
11+
DATE_PICKER: 'date-picker';
12+
TIME_PICKER: 'time-picker';
13+
WIZARD: 'wizard';
14+
SWITCH: 'switch';
15+
TEXTAREA: 'textarea';
16+
SELECT: 'select';
17+
PLAIN_TEXT: 'plain-text';
18+
BUTTON: 'button';
19+
INPUT_ADDON_GROUP: 'input-addon-group';
20+
INPUT_ADDON_BUTTON_GROUP: 'input-addon-button-group';
21+
DUAL_LIST_SELECT: 'dual-list-select';
22+
SLIDER: 'slider';
2323
}
2424

25+
declare const componentTypes: componentTypes;
26+
2527
export default componentTypes;

packages/react-form-renderer/src/files/condition.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export interface ConditionProp {
1212
notMatch?: any;
1313
then?: ActionResolution;
1414
else?: ActionResolution;
15+
or?: ConditionProp | ConditionProp[];
16+
and?: ConditionProp | ConditionProp[];
17+
not?: ConditionProp | ConditionProp[];
1518
}
1619

1720
export interface ConditionDefinition extends ConditionProp {
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export type DataType = 'integer'|'float'|'number'|'boolean'|'string';
22

33
interface dataTypes {
4-
INTEGER: string;
5-
FLOAT: string;
6-
NUMBER: string;
7-
BOOLEAN: string;
8-
STRING: string;
4+
INTEGER: 'integer';
5+
FLOAT: 'float';
6+
NUMBER: 'number';
7+
BOOLEAN: 'boolean';
8+
STRING: 'string';
99
}
1010

11+
declare const dataTypes: dataTypes;
12+
1113
export default dataTypes;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import { FieldArrayProps } from 'react-final-form-arrays';
22

3-
export default FieldArrayProps;
3+
declare const FieldArray: React.ComponentType<FieldArrayProps<any, HTMLElement>>;
4+
5+
export default FieldArray;

packages/react-form-renderer/src/files/field.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ import { AnyObject } from "./common";
55

66
export type FieldAction = [string, ...any[]];
77

8+
export interface FieldActions {
9+
[key: string]: FieldAction;
10+
}
11+
812
interface Field extends AnyObject {
913
name: string;
1014
component: string;
1115
validate?: Validator[];
12-
condition?: ConditionDefinition[];
16+
condition?: ConditionDefinition | ConditionDefinition[];
1317
initializeOnMount?: boolean;
1418
dataType?: DataType;
1519
initialValue?: any;
1620
clearedValue?: any;
1721
clearOnUnmount?: boolean;
18-
actions?: FieldAction;
22+
actions?: FieldActions;
1923
}
2024

2125
export default Field;

packages/react-form-renderer/src/files/form-renderer.d.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import { ComponentType, FunctionComponent } from 'react';
2-
import { FormApi } from 'final-form';
2+
import { FormApi, SubmissionErrors } from 'final-form';
3+
import { FormProps } from 'react-final-form';
34
import Schema from './schema';
45
import ComponentMapper from './component-mapper';
56
import ValidatorMapper from './validator-mapper';
67
import ActionMapper from './action-mapper';
78
import SchemaValidatorMapper from './schema-validator-mapper';
89
import { FormTemplateRenderProps } from '../../dist/cjs';
10+
import { AnyObject } from './common';
911

10-
export interface FormSubscription {
11-
[key: string]: boolean;
12-
}
13-
14-
export interface FormRendererProps {
12+
export interface FormRendererProps extends FormProps {
1513
initialValues?: object;
16-
onSubmit: (values: object, formApi: FormApi, callback: () => void) => Promise<any>;
17-
onCancel?: () => void;
14+
onCancel?: (values: AnyObject, ...args: any[]) => void;
1815
onReset?: () => void;
1916
schema: Schema;
2017
clearOnUnmount?: boolean;
21-
subscription?: FormSubscription;
2218
clearedValue?: any;
2319
componentMapper: ComponentMapper;
2420
FormTemplate: ComponentType<FormTemplateRenderProps> | FunctionComponent<FormTemplateRenderProps>;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import { FormProps } from 'react-final-form';
22

3-
export default FormProps;
3+
declare const Form: React.ComponentType<FormProps<{}>>;
4+
5+
export default Form;

packages/react-form-renderer/src/files/schema-validator-mapper.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface PartialValidator {
2-
[key: string]: () => void;
2+
[key: string]: (...args: any[]) => void;
33
}
44

55
interface SchemaValidatorMapper {

packages/react-form-renderer/src/files/use-field-api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ T extends HTMLElement = HTMLElement> extends AnyObject {
2020
meta: FieldMetaState<FieldValue>;
2121
}
2222

23-
export default function(options: UseFieldApiConfig): UseFieldApiProps<string>;
23+
export default function(options: UseFieldApiConfig): UseFieldApiProps<any>;
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
interface validatorTypes {
2-
REQUIRED: string;
3-
MIN_LENGTH: string;
4-
MAX_LENGTH: string;
5-
EXACT_LENGTH: string;
6-
MIN_ITEMS: string;
7-
MIN_NUMBER_VALUE: string;
8-
MAX_NUMBER_VALUE: string;
9-
PATTERN: string;
10-
URL: string;
2+
REQUIRED: 'required';
3+
MIN_LENGTH: 'min-length';
4+
MAX_LENGTH: 'max-length';
5+
EXACT_LENGTH: 'exact-length';
6+
MIN_ITEMS: 'min-items';
7+
MIN_NUMBER_VALUE: 'min-number-value';
8+
MAX_NUMBER_VALUE: 'max-number-value';
9+
PATTERN: 'pattern';
10+
URL: 'url';
1111
}
1212

13+
declare const validatorTypes: validatorTypes;
14+
1315
export default validatorTypes;

0 commit comments

Comments
 (0)