1
- import React , { createRef , useContext } from 'react'
1
+ import React , { useContext } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
4
- import { Control } from 'react-redux-form '
4
+ import { Field } from 'formik '
5
5
import {
6
- Row , Col , Collapse , Input , Button ,
6
+ Row , Col , Collapse ,
7
7
InputGroup , InputGroupAddon , InputGroupText
8
8
} from 'reactstrap'
9
9
10
10
import Icon from '../../../../../../../Icon'
11
- import FileSelector from '../../../../../../../FileSelector'
11
+ import FileSelectorField from '../../../../../../../FileSelector/field '
12
12
13
13
import { ItemContext } from '../../../index'
14
14
15
- export const ImageOptions = ( { rowIndex , ... props } ) => {
15
+ export const ImageOptions = ( { name , index } ) => {
16
16
const { openItem } = useContext ( ItemContext )
17
17
18
18
return (
19
19
< Row form >
20
20
< Col >
21
- < Collapse isOpen = { openItem === rowIndex } >
21
+ < Collapse isOpen = { openItem === index } >
22
22
< InputGroup className = "mt-2" >
23
23
< InputGroupAddon addonType = "prepend" >
24
24
< InputGroupText >
25
25
< Icon icon = "arrows-h" fixedWidth />
26
26
</ InputGroupText >
27
27
</ InputGroupAddon >
28
- < Control
29
- model = " .width"
28
+ < Field
29
+ name = { ` ${ name } .width` }
30
30
defaultValue = ""
31
31
placeholder = "width"
32
- debounce = { 300 }
33
- className = "form-control"
34
- style = { { fontFamily : 'Fira Mono' } }
32
+ className = "form-control text-monospace"
35
33
/>
36
34
< InputGroupAddon addonType = "prepend" >
37
35
< InputGroupText >
38
36
< Icon icon = "arrows-v" fixedWidth />
39
37
</ InputGroupText >
40
38
</ InputGroupAddon >
41
- < Control
42
- model = " .height"
39
+ < Field
40
+ name = { ` ${ name } .height` }
43
41
defaultValue = ""
44
42
placeholder = "height"
45
- debounce = { 300 }
46
- className = "form-control"
47
- style = { { fontFamily : 'Fira Mono' } }
43
+ className = "form-control text-monospace"
48
44
/>
49
45
</ InputGroup >
50
46
</ Collapse >
@@ -53,60 +49,27 @@ export const ImageOptions = ({ rowIndex, ...props }) => {
53
49
)
54
50
}
55
51
56
- const ImageSelector = ( { rowIndex } , { id, gridDispatch } ) => {
57
- const fileSelector = createRef ( )
58
-
59
- return (
60
- < Row form >
61
- < Col >
62
- < FileSelector
63
- accept = "image/*"
64
- component = { id }
65
- ref = { fileSelector }
66
- />
67
- < InputGroup >
68
- < Control
69
- model = ".src"
70
- placeholder = "source"
71
- component = { Input }
72
- style = { { fontFamily : 'Fira Mono' } }
73
- debounce = { 300 }
74
- />
75
- < InputGroupAddon addonType = "append" >
76
- < Button
77
- outline color = "secondary"
78
- style = { { minWidth : '3rem' } }
79
- onClick = { async ( ) => {
80
- try {
81
- const files = await fileSelector . current . select ( )
82
- gridDispatch ( 'change' , {
83
- model : `local.items.rows[${ rowIndex } ][0].src` ,
84
- value : `\${ this.files["${ files [ 0 ] . localPath } "] }`
85
- } )
86
- } catch ( error ) {
87
- console . log ( 'Error while selecting image' , error )
88
- }
89
- } }
90
- >
91
- < Icon fixedWidth icon = "folder" />
92
- </ Button >
93
- </ InputGroupAddon >
94
- </ InputGroup >
95
- </ Col >
96
- </ Row >
97
- )
98
- }
52
+ const ImageSelector = ( { name } , { id } ) =>
53
+ < Row form >
54
+ < Col >
55
+ < FileSelectorField
56
+ name = { `${ name } .src` }
57
+ accept = "image/*"
58
+ placeholder = "source"
59
+ component = { id }
60
+ />
61
+ </ Col >
62
+ </ Row >
99
63
100
64
ImageSelector . contextTypes = {
101
65
id : PropTypes . oneOfType ( [
102
66
PropTypes . string ,
103
67
PropTypes . number ,
104
68
] ) ,
105
- gridDispatch : PropTypes . func ,
106
69
}
107
70
108
- export default ( { rowIndex } ) =>
71
+ export default ( { name , index } ) =>
109
72
< >
110
- < ImageSelector rowIndex = { rowIndex } />
111
- < ImageOptions rowIndex = { rowIndex } />
73
+ < ImageSelector name = { name } />
74
+ < ImageOptions name = { name } index = { index } />
112
75
</ >
0 commit comments