2018-04-12 20:23:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import moment from 'moment';
|
|
|
|
import formatFileSize from 'filesize';
|
|
|
|
|
|
|
|
interface Props {
|
2018-04-13 00:56:05 +00:00
|
|
|
fileName?: string;
|
2018-04-12 20:23:26 +00:00
|
|
|
fileSize?: number;
|
|
|
|
i18n: (key: string, values?: Array<string>) => string;
|
2018-04-15 06:16:39 +00:00
|
|
|
onClick?: () => void;
|
2018-04-12 20:23:26 +00:00
|
|
|
timestamp: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = {
|
|
|
|
container: {
|
|
|
|
width: '100%',
|
|
|
|
height: 72,
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderBottomColor: '#ccc',
|
|
|
|
borderBottomStyle: 'solid',
|
|
|
|
},
|
|
|
|
itemContainer: {
|
2018-04-25 20:33:54 +00:00
|
|
|
cursor: 'pointer',
|
2018-04-12 20:23:26 +00:00
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
flexWrap: 'nowrap',
|
|
|
|
alignItems: 'center',
|
|
|
|
height: '100%',
|
|
|
|
} as React.CSSProperties,
|
|
|
|
itemMetadata: {
|
|
|
|
display: 'inline-flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
flexGrow: 1,
|
|
|
|
flexShrink: 0,
|
|
|
|
marginLeft: 8,
|
|
|
|
marginRight: 8,
|
|
|
|
} as React.CSSProperties,
|
|
|
|
itemDate: {
|
|
|
|
display: 'inline-block',
|
|
|
|
flexShrink: 0,
|
|
|
|
},
|
|
|
|
itemIcon: {
|
|
|
|
flexShrink: 0,
|
|
|
|
},
|
2018-04-24 16:41:32 +00:00
|
|
|
itemFileName: {
|
|
|
|
fontWeight: 'bold',
|
|
|
|
} as React.CSSProperties,
|
2018-04-12 20:23:26 +00:00
|
|
|
itemFileSize: {
|
|
|
|
display: 'inline-block',
|
|
|
|
marginTop: 8,
|
|
|
|
fontSize: '80%',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-04-15 01:11:40 +00:00
|
|
|
export class DocumentListItem extends React.Component<Props, {}> {
|
2018-04-12 20:23:26 +00:00
|
|
|
public renderContent() {
|
|
|
|
const { fileName, fileSize, timestamp } = this.props;
|
|
|
|
|
|
|
|
return (
|
2018-04-15 06:16:39 +00:00
|
|
|
<div style={styles.itemContainer} onClick={this.props.onClick}>
|
2018-04-12 20:23:26 +00:00
|
|
|
<img
|
|
|
|
src="images/file.svg"
|
|
|
|
width="48"
|
|
|
|
height="48"
|
|
|
|
style={styles.itemIcon}
|
|
|
|
/>
|
2018-04-13 20:25:52 +00:00
|
|
|
<div style={styles.itemMetadata}>
|
2018-04-24 16:41:32 +00:00
|
|
|
<span style={styles.itemFileName}>{fileName}</span>
|
2018-04-13 20:25:52 +00:00
|
|
|
<span style={styles.itemFileSize}>
|
2018-04-12 20:23:26 +00:00
|
|
|
{typeof fileSize === 'number' ? formatFileSize(fileSize) : ''}
|
|
|
|
</span>
|
|
|
|
</div>
|
2018-04-13 20:25:52 +00:00
|
|
|
<div style={styles.itemDate}>
|
2018-04-12 21:22:26 +00:00
|
|
|
{moment(timestamp).format('ddd, MMM D, Y')}
|
2018-04-12 20:23:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
2018-04-13 20:25:52 +00:00
|
|
|
return <div style={styles.container}>{this.renderContent()}</div>;
|
2018-04-12 20:23:26 +00:00
|
|
|
}
|
|
|
|
}
|