1
1
import React from 'react'
2
2
3
- import { Control } from 'react-redux-form '
3
+ import { Field , useFormikContext , getIn } from 'formik '
4
4
import { Row , Col ,
5
- Input , InputGroup , InputGroupAddon , InputGroupText ,
5
+ InputGroup , InputGroupAddon , InputGroupText ,
6
6
FormGroup , Label , FormText } from 'reactstrap'
7
7
8
8
import { CollapsingOptions } from './BaseOptions'
9
9
import Icon from '../../../../../../../Icon'
10
+ import { Input } from '../../../../../../../Form'
10
11
11
- export const ExtraOptions = ( { type } ) => {
12
+ export const ExtraOptions = ( { name , type } ) => {
12
13
switch ( type ) {
13
14
case 'number' :
14
15
return < >
@@ -19,33 +20,33 @@ export const ExtraOptions = ({ type }) => {
19
20
< Icon icon = "arrow-to-bottom" fallback = "arrow-down" />
20
21
</ InputGroupText >
21
22
</ InputGroupAddon >
22
- < Control
23
- model = " .attributes.min"
23
+ < Field
24
+ name = { ` ${ name } .attributes.min` }
24
25
placeholder = "No lower limit"
25
26
component = { Input }
26
- style = { { fontFamily : 'Fira Mono' } }
27
+ className = "text-monospace"
27
28
/>
28
29
< InputGroupAddon addonType = "prepend" >
29
30
< InputGroupText >
30
31
< Icon icon = "arrow-to-top" fallback = "arrow-up" />
31
32
</ InputGroupText >
32
33
</ InputGroupAddon >
33
- < Control
34
- model = " .attributes.max"
34
+ < Field
35
+ name = { ` ${ name } .attributes.max` }
35
36
placeholder = "No upper limit"
36
37
component = { Input }
37
- style = { { fontFamily : 'Fira Mono' } }
38
+ className = "text-monospace"
38
39
/>
39
40
< InputGroupAddon addonType = "prepend" >
40
41
< InputGroupText >
41
42
< Icon icon = "shoe-prints" />
42
43
</ InputGroupText >
43
44
</ InputGroupAddon >
44
- < Control
45
- model = " .attributes.step"
45
+ < Field
46
+ name = { ` ${ name } .attributes.step` }
46
47
placeholder = "Default step (1)"
47
48
component = { Input }
48
- style = { { fontFamily : 'Fira Mono' } }
49
+ className = "text-monospace"
49
50
/>
50
51
</ InputGroup >
51
52
</ FormGroup >
@@ -59,22 +60,22 @@ export const ExtraOptions = ({ type }) => {
59
60
< Icon icon = "arrow-to-bottom" fallback = "arrow-down" />
60
61
</ InputGroupText >
61
62
</ InputGroupAddon >
62
- < Control
63
- model = " .attributes.min"
63
+ < Field
64
+ name = { ` ${ name } .attributes.min` }
64
65
placeholder = "No earliest date (yyyy-mm-dd)"
65
66
component = { Input }
66
- style = { { fontFamily : 'Fira Mono' } }
67
+ className = "text-monospace"
67
68
/>
68
69
< InputGroupAddon addonType = "prepend" >
69
70
< InputGroupText >
70
71
< Icon icon = "arrow-to-top" fallback = "arrow-up" />
71
72
</ InputGroupText >
72
73
</ InputGroupAddon >
73
- < Control
74
- model = " .attributes.max"
74
+ < Field
75
+ name = { ` ${ name } .attributes.max` }
75
76
placeholder = "No latest date (yyyy-mm-dd)"
76
77
component = { Input }
77
- style = { { fontFamily : 'Fira Mono' } }
78
+ className = "text-monospace"
78
79
/>
79
80
</ InputGroup >
80
81
</ FormGroup >
@@ -84,46 +85,51 @@ export const ExtraOptions = ({ type }) => {
84
85
}
85
86
}
86
87
87
- export default ( { rowIndex, type, data } ) =>
88
- < >
88
+ export default ( { name, index, type } ) => {
89
+ const { values } = useFormikContext ( )
90
+ const attributes = getIn ( values , `${ name } .attributes` )
91
+
92
+ return < >
89
93
< Row form >
90
94
< Col >
91
- < Control
92
- model = " .label"
95
+ < Field
96
+ name = { ` ${ name } .label` }
93
97
placeholder = "Question"
94
98
component = { Input }
95
- debounce = { 300 }
96
99
/>
97
100
</ Col >
98
101
</ Row >
99
102
< CollapsingOptions
100
- rowIndex = { rowIndex }
103
+ name = { name }
104
+ index = { index }
101
105
>
102
106
{
103
107
type === 'input' && < >
104
108
< FormGroup className = "my-2" >
105
- < Label for = { `page-item-${ rowIndex } -attrs-type` } className = "mb-1" >
109
+ < Label for = { `page-item-${ index } -attrs-type` } className = "mb-1" >
106
110
Data type
107
111
</ Label >
108
112
< FormText color = "muted" className = "mb-2" >
109
113
Check input format, and restrict input
110
114
</ FormText >
111
- < Control . select
112
- model = ".attributes.type"
113
- className = "form-control custom-select"
114
- style = { { fontFamily : 'Fira Mono' } }
115
- controlProps = { {
116
- id : `page-item-${ rowIndex } -attrs-type` ,
117
- } }
115
+ < Field
116
+ name = { `${ name } .attributes.type` }
117
+ index = { `page-item-${ index } -attrs-type` }
118
+ as = "select"
119
+ className = "form-control custom-select text-monospace"
118
120
>
119
121
< option value = "text" > Text</ option >
120
122
< option value = "number" > Number</ option >
121
123
< option value = "email" > Email</ option >
122
124
< option value = "date" > Date</ option >
123
- </ Control . select >
125
+ </ Field >
124
126
</ FormGroup >
125
- < ExtraOptions type = { data . attributes && data . attributes . type } />
127
+ < ExtraOptions
128
+ name = { name }
129
+ type = { attributes && attributes . type }
130
+ />
126
131
</ >
127
132
}
128
133
</ CollapsingOptions >
129
134
</ >
135
+ }
0 commit comments