2018-04-12 20:23:26 +00:00
|
|
|
import React from 'react';
|
2018-07-18 00:15:34 +00:00
|
|
|
import classNames from 'classnames';
|
2018-04-12 20:23:26 +00:00
|
|
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
interface Props {
|
2018-05-08 19:56:10 +00:00
|
|
|
// Required
|
|
|
|
timestamp: number;
|
|
|
|
|
|
|
|
// Optional
|
2019-01-14 21:49:58 +00:00
|
|
|
fileName?: string;
|
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
|
|
|
}
|
|
|
|
|
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
|
2018-07-18 00:15:34 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-document-list-item',
|
|
|
|
shouldShowSeparator
|
|
|
|
? 'module-document-list-item--with-separator'
|
|
|
|
: null
|
|
|
|
)}
|
2018-05-08 19:56:10 +00:00
|
|
|
>
|
|
|
|
{this.renderContent()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private renderContent() {
|
2018-07-18 00:15:34 +00:00
|
|
|
const { fileName, fileSize, timestamp } = this.props;
|
2018-04-12 20:23:26 +00:00
|
|
|
|
|
|
|
return (
|
2018-05-22 19:31:43 +00:00
|
|
|
<div
|
2018-07-18 00:15:34 +00:00
|
|
|
className="module-document-list-item__content"
|
2018-05-22 19:31:43 +00:00
|
|
|
role="button"
|
|
|
|
onClick={this.props.onClick}
|
|
|
|
>
|
2018-07-18 00:15:34 +00:00
|
|
|
<div className="module-document-list-item__icon" />
|
|
|
|
<div className="module-document-list-item__metadata">
|
|
|
|
<span className="module-document-list-item__file-name">
|
|
|
|
{fileName}
|
|
|
|
</span>
|
|
|
|
<span className="module-document-list-item__file-size">
|
2018-04-12 20:23:26 +00:00
|
|
|
{typeof fileSize === 'number' ? formatFileSize(fileSize) : ''}
|
|
|
|
</span>
|
|
|
|
</div>
|
2018-07-18 00:15:34 +00:00
|
|
|
<div className="module-document-list-item__date">
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|