-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.ts
117 lines (109 loc) · 3.38 KB
/
input.ts
1
2
3
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
import { JSONSchemaType } from 'ajv';
import {
InputType,
IFormInput,
IInputOption,
IDateFieldInput,
ICheckBoxInput,
INumberFieldInput,
IRadioGroupInput,
ITextAreaInput,
ITextFieldInput,
} from '../types/form';
const inputOptionSchema: JSONSchemaType<IInputOption> = {
type: 'object',
properties: {
value: { type: 'string' },
caption: { type: 'string' },
checked: { type: 'boolean', nullable: true },
},
required: ['value', 'caption'],
additionalProperties: false,
};
const checkBoxInputSchema: JSONSchemaType<ICheckBoxInput> = {
type: 'object',
properties: {
type: { type: 'string', const: InputType.checkbox },
name: { type: 'string', nullable: true },
value: { type: 'string', nullable: true },
label: { type: 'string' },
disabled: { type: 'boolean', nullable: true },
checked: { type: 'boolean', nullable: true },
},
required: ['type', 'label'],
additionalProperties: false,
};
const dateFieldInputSchema: JSONSchemaType<IDateFieldInput> = {
type: 'object',
properties: {
type: { type: 'string', const: InputType.datefield },
name: { type: 'string', nullable: true },
value: { type: 'string', nullable: true },
label: { type: 'string', nullable: true },
disabled: { type: 'boolean', nullable: true },
},
required: ['type'],
additionalProperties: false,
};
const numberFieldInputSchema: JSONSchemaType<INumberFieldInput> = {
type: 'object',
properties: {
type: { type: 'string', const: InputType.numberfield },
name: { type: 'string', nullable: true },
value: { type: 'number', nullable: true },
label: { type: 'string', nullable: true },
disabled: { type: 'boolean', nullable: true },
placeholder: { type: 'string', nullable: true },
},
required: ['type'],
additionalProperties: false,
};
const radioGroupInputSchema: JSONSchemaType<IRadioGroupInput> = {
type: 'object',
properties: {
type: { type: 'string', const: InputType.radiogroup },
name: { type: 'string', nullable: true },
label: { type: 'string', nullable: true },
options: { type: 'array', items: inputOptionSchema, minItems: 2 },
disabled: { type: 'boolean', nullable: true },
},
required: ['type', 'options'],
additionalProperties: false,
};
const textAreaInputSchema: JSONSchemaType<ITextAreaInput> = {
type: 'object',
properties: {
type: { type: 'string', const: InputType.textarea },
name: { type: 'string', nullable: true },
value: { type: 'string', nullable: true },
label: { type: 'string', nullable: true },
disabled: { type: 'boolean', nullable: true },
placeholder: { type: 'string', nullable: true },
},
required: ['type'],
additionalProperties: false,
};
const textFieldInputSchema: JSONSchemaType<ITextFieldInput> = {
type: 'object',
properties: {
type: { type: 'string', const: InputType.textfield },
name: { type: 'string', nullable: true },
value: { type: 'string', nullable: true },
label: { type: 'string', nullable: true },
disabled: { type: 'boolean', nullable: true },
placeholder: { type: 'string', nullable: true },
},
required: ['type'],
additionalProperties: false,
};
export const formInputSchema: JSONSchemaType<IFormInput> = {
type: 'object',
oneOf: [
checkBoxInputSchema,
dateFieldInputSchema,
numberFieldInputSchema,
radioGroupInputSchema,
textAreaInputSchema,
textFieldInputSchema,
],
};