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

113 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-04-12 20:23:26 +00:00
import React from 'react';
import moment from 'moment';
// tslint:disable-next-line:match-default-export-name
2018-04-12 20:23:26 +00:00
import formatFileSize from 'filesize';
import { Localizer } from '../../../types/Util';
2018-04-12 20:23:26 +00:00
interface Props {
// Required
i18n: Localizer;
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;
shouldShowSeparator?: boolean;
2018-04-12 20:23:26 +00:00
}
const styles = {
container: {
width: '100%',
height: 72,
},
containerSeparator: {
2018-04-12 20:23:26 +00:00
borderBottomWidth: 1,
borderBottomColor: '#ccc',
borderBottomStyle: 'solid',
},
itemContainer: {
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%',
},
};
export class DocumentListItem extends React.Component<Props> {
public static defaultProps: Partial<Props> = {
shouldShowSeparator: true,
};
public render() {
const { shouldShowSeparator } = this.props;
return (
<div
style={{
...styles.container,
...(shouldShowSeparator ? styles.containerSeparator : {}),
}}
>
{this.renderContent()}
</div>
);
}
private renderContent() {
const { fileName, fileSize, timestamp, i18n } = this.props;
2018-04-12 20:23:26 +00:00
return (
<div
style={styles.itemContainer}
role="button"
onClick={this.props.onClick}
>
2018-04-12 20:23:26 +00:00
<img
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>
);
}
}