aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/ImageUpload.js
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-10-14 23:32:05 +0200
committerLibravatar GitHub <noreply@github.com>2021-10-15 03:02:05 +0530
commit137555821f172e4eadc7cf099d4270ae8fc1374e (patch)
tree693882bbf7a6b2a24b5a727091d09586d0371007 /src/components/ui/ImageUpload.js
parentNew translations en-US.json (Spanish) (#2072) (diff)
downloadferdium-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.js110
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 @@
1import { Component, Fragment } from 'react';
2import PropTypes from 'prop-types';
3import { observer } from 'mobx-react';
4import { Field } from 'mobx-react-form';
5import classnames from 'classnames';
6import Dropzone from 'react-dropzone';
7import { isWindows } from '../../environment';
8
9@observer
10class 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
110export default ImageUpload;