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

57 lines
921 B
TypeScript
Raw Normal View History

2018-04-13 20:25:52 +00:00
/**
* @prettier
*/
2018-04-12 20:23:26 +00:00
import React from 'react';
import { Message } from './propTypes/Message';
interface Props {
message: Message;
2018-04-15 06:16:39 +00:00
onClick?: () => void;
2018-04-12 20:23:26 +00:00
}
2018-04-13 00:56:05 +00:00
const size = {
width: 94,
height: 94,
};
2018-04-12 20:23:26 +00:00
const styles = {
container: {
2018-04-13 00:56:05 +00:00
...size,
2018-04-12 20:23:26 +00:00
backgroundColor: '#f3f3f3',
marginRight: 4,
marginBottom: 4,
2018-04-13 00:56:05 +00:00
},
image: {
...size,
backgroundSize: 'cover',
2018-04-12 20:23:26 +00:00
},
};
2018-04-15 01:11:40 +00:00
export class MediaGridItem extends React.Component<Props, {}> {
2018-04-12 20:23:26 +00:00
public renderContent() {
2018-04-15 01:03:21 +00:00
const { message } = this.props;
2018-04-12 20:23:26 +00:00
2018-04-13 00:56:05 +00:00
if (!message.objectURL) {
2018-04-15 06:53:34 +00:00
return null;
2018-04-12 20:23:26 +00:00
}
return (
2018-04-13 00:56:05 +00:00
<div
style={{
...styles.container,
...styles.image,
backgroundImage: `url("${message.objectURL}")`,
}}
2018-04-12 20:23:26 +00:00
/>
);
}
public render() {
2018-04-15 06:16:39 +00:00
return (
<div style={styles.container} onClick={this.props.onClick}>
{this.renderContent()}
</div>
);
2018-04-12 20:23:26 +00:00
}
}