2018-04-12 20:23:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import moment from 'moment';
|
2018-05-22 19:31:43 +00:00
|
|
|
// tslint:disable-next-line:match-default-export-name
|
2018-04-12 20:23:26 +00:00
|
|
|
import formatFileSize from 'filesize';
|
|
|
|
|
2018-05-22 19:31:43 +00:00
|
|
|
import { Localizer } from '../../../types/Util';
|
|
|
|
|
2018-04-12 20:23:26 +00:00
|
|
|
interface Props {
|
2018-05-08 19:56:10 +00:00
|
|
|
// Required
|
2018-05-22 19:31:43 +00:00
|
|
|
i18n: Localizer;
|
2018-05-08 19:56:10 +00:00
|
|
|
timestamp: number;
|
|
|
|
|
|
|
|
// Optional
|
2018-05-07 16:40:59 +00:00
|
|
|
fileName?: string | null;
|
2018-04-12 20:23:26 +00:00
|
|
|
fileSize?: number;
|
2018-04-15 06:16:39 +00:00
|
|
|
onClick?: () => void;
|
2018-05-08 19:56:10 +00:00
|
|
|
shouldShowSeparator?: boolean;
|
2018-04-12 20:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = {
|
|
|
|
container: {
|
|
|
|
width: '100%',
|
|
|
|
height: 72,
|
2018-05-08 01:43:55 +00:00
|
|
|
},
|
|
|
|
containerSeparator: {
|
2018-04-12 20:23:26 +00:00
|
|
|
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-05-22 19:31:43 +00:00
|
|
|
export class DocumentListItem extends React.Component<Props> {
|
2018-05-08 19:56:10 +00:00
|
|
|
public static defaultProps: Partial<Props> = {
|
|
|
|
shouldShowSeparator: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
const { shouldShowSeparator } = this.props;
|
2018-05-22 19:31:43 +00:00
|
|
|
|
2018-05-08 19:56:10 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
...styles.container,
|
|
|
|
...(shouldShowSeparator ? styles.containerSeparator : {}),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{this.renderContent()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private renderContent() {
|
2018-05-22 19:31:43 +00:00
|
|
|
const { fileName, fileSize, timestamp, i18n } = this.props;
|
2018-04-12 20:23:26 +00:00
|
|
|
|
|
|
|
return (
|
2018-05-22 19:31:43 +00:00
|
|
|
<div
|
|
|
|
style={styles.itemContainer}
|
|
|
|
role="button"
|
|
|
|
onClick={this.props.onClick}
|
|
|
|
>
|
2018-04-12 20:23:26 +00:00
|
|
|
<img
|
2018-05-22 19:31:43 +00:00
|
|
|
alt={i18n('fileIconAlt')}
|
2018-04-12 20:23:26 +00:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|