-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathApp.js
190 lines (178 loc) · 4.55 KB
/
App.js
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import React, { useEffect, useState } from 'react'
/** @jsx jsx */
import { jsx, Link } from 'theme-ui'
import ReactMarkdown from 'react-markdown'
import {
Button,
Input,
Label,
Checkbox,
Radio,
Phone,
Date,
Modal,
ErrorMessage,
FormBuilder
} from 'react-form-builder'
import forms from './forms.json'
import { useForm } from 'react-hook-form'
import 'react-datepicker/dist/react-datepicker.css'
import 'react-phone-number-input/style.css'
const App = () => {
const styles = {
fullWidth: {
gridColumnStart: '1',
gridColumnEnd: '3'
},
selectOption: {
background: 'bg',
color: 'black'
},
markDown: {
fontFamily: 'regular',
width: ['90%', '95%', '95%'],
p: {
margin: 0
}
}
}
const [privacyAllow, setPrivacyAllow] = useState(false)
const [modalText, setModalText] = useState('')
const [show, setShow] = useState(false)
const [isLoading, setLoading] = useState(false)
function onLinkOpen(name) {
setModalText(forms.contact.textToShow[name])
setShow(true)
}
const CustomCheckbox = (question, useForm) => {
return (
<div sx={{ ...(question.isFullWidth && styles.fullWidth) }}>
<Modal
title={question.name}
onClose={() => setShow(false)}
show={show}
modalText='this a modal example *markdown* **text** '
/>
<div sx={{}}>
<div sx={styles.centerStyle} key={question.name}>
<Label sx={styles.centerStyle}>
<Checkbox
sx={styles.checkboxMinWidth}
name={question.name}
test='test'
ref={useForm.register(question.name, question.registerConfig)}
/>
<ReactMarkdown
sx={styles.markDown}
source={question.label}
renderers={{
link: ({ href, children }) => {
return (
<Link
href={
children[0].props.children.includes('privacy')
? '#'
: '#'
}
>
{children} esto es el children: {children[0]}
</Link>
)
}
}}
/>
</Label>
{useForm?.errors[question.name] &&
useForm?.errors[question.name]?.type === 'required' && (
<ErrorMessage
message={
question?.errorMessages && question?.errorMessages?.required
}
/>
)}
</div>
</div>
</div>
)
}
const ModalCheckbox = () => {
const [show, setShow] = useState(false)
return (
<React.Fragment>
<Checkbox
question={forms.question}
useForm={{ errors: {}, register: () => {} }}
/>
</React.Fragment>
)
}
const onSubmitForm = (data) => {
!isLoading &&
alert(
`You have submitted your form correctly Data: ${'\n'} ${JSON.stringify(
data,
null,
2
)}`
)
setLoading(true)
setTimeout(() => {
setLoading(false)
}, 1000)
}
return (
<>
{/* <Button caption='Button example' />
<Input />
<Phone
defaultCountry='GB'
style={{}}
register={register}
setValue={setValue}
setError={setError}
clearErrors={clearErrors}
placeholder='Phone'
/>
<Date
register={register}
setValue={setValue}
name='Date'
registerConfig={{}}
placeholder=''
dateFormat='dd-MM-yyyy'
isMobile={false}
isBirthDate={false}
/>
<Label>An important title field here *</Label>
<Label>
<Checkbox />
Select an option
</Label>
<Label>
<Radio name='dark-mode' value='true' defaultChecked />
Dark Mode
</Label>
<Label>
<Radio name='dark-mode' value='false' />
Light Mode
</Label> */}
<Label>Example of form builder</Label>
<Modal
title='test'
onClose={() => setShow(false)}
show={show}
modalText={modalText}
/>
<FormBuilder
idForm={forms.contact.id}
form={forms.contact}
onSubmit={onSubmitForm}
isoCode='ES'
onLinkOpen={onLinkOpen}
isLoading={isLoading}
validateJSON
/>
</>
)
}
export default App