Skip to content

Commit 88a6f7d

Browse files
author
jonisaa
committed
#2 Refactor to es6 class
1 parent 634df54 commit 88a6f7d

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/components/common/FileInfo.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,34 @@ import React, { Component, PropTypes } from 'react';
22
import { Col } from 'react-bootstrap';
33
import filesize from 'filesize';
44

5-
const FileUploadItem = ({ file, height, width }) => {
6-
let image = null;
5+
export default class FileUploadItem extends Component {
6+
static propTypes = {
7+
onClick: PropTypes.func,
8+
file: PropTypes.object.isRequired,
9+
height: PropTypes.string,
10+
width: PropTypes.string
11+
};
712

8-
if (file.type.match(/image/)) {
9-
image = <img height={height} width={width} src={file.preview}/>;
10-
}
13+
static defaultProps = {
14+
height: "150px",
15+
width: "150px"
16+
};
1117

12-
return (
13-
<Col xs={4} md={4}>
14-
{image}
15-
<p>{file.name}</p>
16-
<p>{filesize(file.size)}</p>
17-
</Col>
18-
);
19-
};
18+
render() {
19+
let { file, height, width } = this.props;
2020

21-
FileUploadItem.propTypes = {
22-
file: PropTypes.object.isRequired,
23-
height: PropTypes.string,
24-
width: PropTypes.string
25-
};
21+
let image = null;
2622

27-
FileUploadItem.defaultProps = {
28-
height: "150px",
29-
width: "150px"
30-
};
23+
if (file.type.match(/image/)) {
24+
image = <img height={height} width={width} src={file.preview}/>;
25+
}
3126

32-
export default FileUploadItem;
27+
return (
28+
<Col xs={4} md={4}>
29+
{image}
30+
<p>{file.name}</p>
31+
<p>{filesize(file.size)}</p>
32+
</Col>
33+
);
34+
}
35+
};

0 commit comments

Comments
 (0)