Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 2213203

Browse files
Replace image selector with FileSelectorField
1 parent b65aa79 commit 2213203

File tree

1 file changed

+55
-86
lines changed
  • packages/builder/src/components/ComponentOptions/components/Content/Canvas/components/form/Details

1 file changed

+55
-86
lines changed

packages/builder/src/components/ComponentOptions/components/Content/Canvas/components/form/Details/ImageOptions.js

Lines changed: 55 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,69 @@
1-
import React, { createRef } from 'react'
1+
import React from 'react'
22
import PropTypes from 'prop-types'
33

44
import { DropdownMenu, DropdownItem,
55
InputGroup, InputGroupAddon, InputGroupText, Button } from 'reactstrap'
6-
import { Field } from 'formik'
76

8-
import FileSelector from '../../../../../../../FileSelector'
7+
import FileSelectorField from '../../../../../../../FileSelector/field'
98
import Icon from '../../../../../../../Icon'
109

11-
const ImageOptions = ({ selection, changeHandler }, { id }) => {
12-
const fileSelector = createRef()
13-
14-
return (
15-
<DropdownMenu right
16-
style={{
17-
width: '500px',
18-
}}
19-
>
20-
<FileSelector
21-
tab="pool"
10+
const ImageOptions = ({ selection, changeHandler }, { id }) =>
11+
<DropdownMenu right
12+
style={{
13+
width: '500px',
14+
}}
15+
>
16+
<DropdownItem tag="div" toggle={ false } className="mute">
17+
<FileSelectorField
18+
name="src"
2219
accept="image/*"
20+
tab="pool"
21+
icon="file-audio"
2322
component={ id }
24-
ref={ fileSelector }
2523
/>
26-
<DropdownItem tag="div" toggle={ false } className="mute">
27-
<InputGroup>
28-
<Field
29-
name="src"
30-
placeholder="Source"
31-
className="form-control"
32-
style={{ fontFamily: 'Fira Mono' }}
33-
/>
34-
<InputGroupAddon addonType="append">
35-
<Button
36-
outline color="secondary"
37-
style={{ padding: '0 1rem' }}
38-
onClick={ async () => {
39-
try {
40-
const files = await fileSelector.current.select()
41-
changeHandler(
42-
'src', `\${ this.files["${ files[0].localPath }"] }`
43-
)
44-
} catch (error) {
45-
console.log('Error while inserting image', error)
46-
}
47-
} }
48-
>
49-
<Icon icon="folder" />
50-
</Button>
51-
</InputGroupAddon>
52-
</InputGroup>
53-
</DropdownItem>
54-
<DropdownItem tag="div" toggle={ false } className="mute">
55-
<InputGroup className="d-flex flex-row image-autoscale" size="sm">
56-
<InputGroupAddon addonType="prepend" style={{ width: '25%' }}>
57-
<InputGroupText className="w-100 text-center">
58-
Auto resize
59-
</InputGroupText>
60-
</InputGroupAddon>
61-
<InputGroupAddon
62-
className="flex-fill"
63-
addonType="append"
24+
</DropdownItem>
25+
<DropdownItem tag="div" toggle={ false } className="mute">
26+
<InputGroup className="d-flex flex-row image-autoscale" size="sm">
27+
<InputGroupAddon addonType="prepend" style={{ width: '25%' }}>
28+
<InputGroupText className="w-100 text-center">
29+
Auto resize
30+
</InputGroupText>
31+
</InputGroupAddon>
32+
<InputGroupAddon
33+
className="flex-fill"
34+
addonType="append"
35+
>
36+
<Button outline
37+
color={
38+
!['width', 'height'].includes(selection.autoScale)
39+
? 'primary'
40+
: 'secondary'
41+
}
42+
style={{ width: '35%' }}
43+
onClick={ () => changeHandler('autoScale', false) }
6444
>
65-
<Button outline
66-
color={
67-
!['width', 'height'].includes(selection.autoScale)
68-
? 'primary'
69-
: 'secondary'
70-
}
71-
style={{ width: '35%' }}
72-
onClick={ () => changeHandler('autoScale', false) }
73-
>
74-
<Icon icon="power-off" />
75-
</Button>
76-
<Button outline
77-
color={ selection.autoScale === 'width'
78-
? 'primary' : 'secondary' }
79-
style={{ width: '32.5%' }}
80-
onClick={ () => changeHandler('autoScale', 'width') }
81-
>
82-
<Icon icon="arrows-alt-h" />
83-
</Button>
84-
<Button outline
85-
color={ selection.autoScale === 'height'
86-
? 'primary' : 'secondary' }
87-
style={{ width: '32.5%' }}
88-
onClick={ () => changeHandler('autoScale', 'height') }
89-
>
90-
<Icon icon="arrows-alt-v" />
91-
</Button>
92-
</InputGroupAddon>
93-
</InputGroup>
94-
</DropdownItem>
95-
</DropdownMenu>
96-
)
97-
}
45+
<Icon icon="power-off" />
46+
</Button>
47+
<Button outline
48+
color={ selection.autoScale === 'width'
49+
? 'primary' : 'secondary' }
50+
style={{ width: '32.5%' }}
51+
onClick={ () => changeHandler('autoScale', 'width') }
52+
>
53+
<Icon icon="arrows-alt-h" />
54+
</Button>
55+
<Button outline
56+
color={ selection.autoScale === 'height'
57+
? 'primary' : 'secondary' }
58+
style={{ width: '32.5%' }}
59+
onClick={ () => changeHandler('autoScale', 'height') }
60+
>
61+
<Icon icon="arrows-alt-v" />
62+
</Button>
63+
</InputGroupAddon>
64+
</InputGroup>
65+
</DropdownItem>
66+
</DropdownMenu>
9867

9968
ImageOptions.contextTypes = {
10069
id: PropTypes.oneOfType([

0 commit comments

Comments
 (0)