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

55 lines
929 B
TypeScript
Raw Normal View History

2018-04-12 20:23:26 +00:00
import React from 'react';
import { Message } from './types/Message';
2018-04-12 20:23:26 +00:00
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-25 22:20:47 +00:00
cursor: 'pointer',
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
},
};
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} role="button" onClick={this.props.onClick}>
2018-04-15 06:16:39 +00:00
{this.renderContent()}
</div>
);
2018-04-12 20:23:26 +00:00
}
}