signal-desktop/ts/components/conversation/media-gallery/DocumentListItem.tsx

67 lines
1.6 KiB
TypeScript
Raw Normal View History

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';
import formatFileSize from 'filesize';
interface Props {
// 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;
shouldShowSeparator?: boolean;
2018-04-12 20:23:26 +00:00
}
export class DocumentListItem extends React.Component<Props> {
public static defaultProps: Partial<Props> = {
shouldShowSeparator: true,
};
2020-09-14 19:51:27 +00:00
public render(): JSX.Element {
const { shouldShowSeparator } = this.props;
return (
<div
2018-07-18 00:15:34 +00:00
className={classNames(
'module-document-list-item',
shouldShowSeparator
? 'module-document-list-item--with-separator'
: null
)}
>
{this.renderContent()}
</div>
);
}
private renderContent() {
2020-09-14 19:51:27 +00:00
const { fileName, fileSize, onClick, timestamp } = this.props;
2018-04-12 20:23:26 +00:00
return (
2019-11-07 21:36:16 +00:00
<button
2020-09-14 19:51:27 +00:00
type="button"
2018-07-18 00:15:34 +00:00
className="module-document-list-item__content"
2020-09-14 19:51:27 +00:00
onClick={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">
2020-10-21 23:54:53 +00:00
{typeof fileSize === 'number'
? formatFileSize(fileSize, { round: 0 })
: ''}
2018-04-12 20:23:26 +00:00
</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>
2019-11-07 21:36:16 +00:00
</button>
2018-04-12 20:23:26 +00:00
);
}
}