-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.ts
58 lines (53 loc) · 1.48 KB
/
state.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
import { ActionType, InputType, IForm } from '../types/form';
import { IFormGeneratorState } from './types';
const today = new Date().toISOString().slice(0, 10);
export const defaultIndent = 2;
export const defaultSchema: IForm = {
title: 'Register',
items: [
{
type: InputType.textfield,
name: 'name',
label: 'Full Name',
placeholder: 'Jane Doe',
},
{ type: InputType.numberfield, name: 'compensation', label: 'Annual Compensation' },
{
type: InputType.radiogroup,
name: 'laptop',
label: 'Preferred Laptop',
options: [
{ value: 'mac', caption: 'MacBook Pro 13”', checked: true },
{ value: 'windows', caption: 'Dell XPS 13” with Windows' },
{ value: 'linux', caption: 'Dell XPS 13” with Ubuntu' },
],
},
{
type: InputType.datefield,
name: 'onboarding',
value: today,
label: 'Onboarding Date',
},
{ type: InputType.textarea, name: 'bio', label: 'Bio' },
{
type: InputType.checkbox,
name: 'terms',
checked: true,
label: 'I agree to defined terms and policies',
},
],
actions: [
{ type: ActionType.reset, text: 'Cancel' },
{ type: ActionType.submit, text: 'Sign up' },
],
};
export const stateFromSchema = (schema: IForm): IFormGeneratorState => {
const text = JSON.stringify(schema, null, defaultIndent);
return {
schema,
text,
lastValidText: text,
error: '',
};
};
export const init = stateFromSchema;