diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-10-14 23:32:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 03:02:05 +0530 |
commit | 137555821f172e4eadc7cf099d4270ae8fc1374e (patch) | |
tree | 693882bbf7a6b2a24b5a727091d09586d0371007 /src/components/ui/ImageUpload.js | |
parent | New translations en-US.json (Spanish) (#2072) (diff) | |
download | ferdium-app-137555821f172e4eadc7cf099d4270ae8fc1374e.tar.gz ferdium-app-137555821f172e4eadc7cf099d4270ae8fc1374e.tar.zst ferdium-app-137555821f172e4eadc7cf099d4270ae8fc1374e.zip |
chore: convert components to tsx (#2071)
Diffstat (limited to 'src/components/ui/ImageUpload.js')
-rw-r--r-- | src/components/ui/ImageUpload.js | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/src/components/ui/ImageUpload.js b/src/components/ui/ImageUpload.js deleted file mode 100644 index c51d39a9b..000000000 --- a/src/components/ui/ImageUpload.js +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | import { Component, Fragment } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import { Field } from 'mobx-react-form'; | ||
5 | import classnames from 'classnames'; | ||
6 | import Dropzone from 'react-dropzone'; | ||
7 | import { isWindows } from '../../environment'; | ||
8 | |||
9 | @observer | ||
10 | class ImageUpload extends Component { | ||
11 | static propTypes = { | ||
12 | field: PropTypes.instanceOf(Field).isRequired, | ||
13 | className: PropTypes.string, | ||
14 | multiple: PropTypes.bool, | ||
15 | textDelete: PropTypes.string.isRequired, | ||
16 | textUpload: PropTypes.string.isRequired, | ||
17 | }; | ||
18 | |||
19 | static defaultProps = { | ||
20 | className: null, | ||
21 | multiple: false, | ||
22 | }; | ||
23 | |||
24 | state = { | ||
25 | path: null, | ||
26 | }; | ||
27 | |||
28 | dropzoneRef = null; | ||
29 | |||
30 | onDrop(acceptedFiles) { | ||
31 | const { field } = this.props; | ||
32 | |||
33 | for (const file of acceptedFiles) { | ||
34 | const imgPath = isWindows ? file.path.replace(/\\/g, '/') : file.path; | ||
35 | this.setState({ | ||
36 | path: imgPath, | ||
37 | }); | ||
38 | |||
39 | this.props.field.onDrop(file); | ||
40 | } | ||
41 | |||
42 | field.set(''); | ||
43 | } | ||
44 | |||
45 | render() { | ||
46 | const { field, className, multiple, textDelete, textUpload } = this.props; | ||
47 | |||
48 | const cssClasses = classnames({ | ||
49 | 'image-upload__dropzone': true, | ||
50 | [`${className}`]: className, | ||
51 | }); | ||
52 | |||
53 | return ( | ||
54 | <div className="image-upload-wrapper"> | ||
55 | <label className="franz-form__label" htmlFor="iconUpload"> | ||
56 | {field.label} | ||
57 | </label> | ||
58 | <div className="image-upload"> | ||
59 | {(field.value && field.value !== 'delete') || this.state.path ? ( | ||
60 | <> | ||
61 | <div | ||
62 | className="image-upload__preview" | ||
63 | style={{ | ||
64 | backgroundImage: `url("${this.state.path || field.value}")`, | ||
65 | }} | ||
66 | /> | ||
67 | <div className="image-upload__action"> | ||
68 | <button | ||
69 | type="button" | ||
70 | onClick={() => { | ||
71 | if (field.value) { | ||
72 | field.set('delete'); | ||
73 | } else { | ||
74 | this.setState({ | ||
75 | path: null, | ||
76 | }); | ||
77 | } | ||
78 | }} | ||
79 | > | ||
80 | <i className="mdi mdi-delete" /> | ||
81 | <p>{textDelete}</p> | ||
82 | </button> | ||
83 | <div className="image-upload__action-background" /> | ||
84 | </div> | ||
85 | </> | ||
86 | ) : ( | ||
87 | <Dropzone | ||
88 | ref={node => { | ||
89 | this.dropzoneRef = node; | ||
90 | }} | ||
91 | onDrop={this.onDrop.bind(this)} | ||
92 | multiple={multiple} | ||
93 | accept="image/jpeg, image/png, image/svg+xml" | ||
94 | > | ||
95 | {({ getRootProps, getInputProps }) => ( | ||
96 | <div {...getRootProps()} className={cssClasses}> | ||
97 | <i className="mdi mdi-file-image" /> | ||
98 | <p>{textUpload}</p> | ||
99 | <input {...getInputProps()} /> | ||
100 | </div> | ||
101 | )} | ||
102 | </Dropzone> | ||
103 | )} | ||
104 | </div> | ||
105 | </div> | ||
106 | ); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | export default ImageUpload; | ||