2016-09-05 18:38:31 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
|
|
|
|
|
|
const MediaGallery = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
2016-09-18 11:03:37 +00:00
|
|
|
media: ImmutablePropTypes.list.isRequired,
|
|
|
|
height: React.PropTypes.number.isRequired
|
2016-09-05 18:38:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
|
|
|
render () {
|
2016-09-05 18:59:56 +00:00
|
|
|
var children = this.props.media.take(4);
|
|
|
|
var size = children.size;
|
|
|
|
|
|
|
|
children = children.map((attachment, i) => {
|
2016-09-05 22:23:27 +00:00
|
|
|
let width = 50;
|
|
|
|
let height = 100;
|
2016-09-05 23:26:35 +00:00
|
|
|
let top = 'auto';
|
|
|
|
let left = 'auto';
|
|
|
|
let bottom = 'auto';
|
|
|
|
let right = 'auto';
|
2016-09-05 18:59:56 +00:00
|
|
|
|
2016-09-25 13:26:56 +00:00
|
|
|
if (size === 1) {
|
|
|
|
width = 100;
|
|
|
|
}
|
|
|
|
|
2016-09-05 23:26:35 +00:00
|
|
|
if (size === 4 || (size === 3 && i > 0)) {
|
2016-09-05 22:23:27 +00:00
|
|
|
height = 50;
|
2016-09-05 18:59:56 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 23:26:35 +00:00
|
|
|
if (size === 2) {
|
|
|
|
if (i === 0) {
|
|
|
|
right = '2px';
|
|
|
|
} else {
|
|
|
|
left = '2px';
|
|
|
|
}
|
|
|
|
} else if (size === 3) {
|
|
|
|
if (i === 0) {
|
|
|
|
right = '2px';
|
|
|
|
} else if (i > 0) {
|
|
|
|
left = '2px';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i === 1) {
|
|
|
|
bottom = '2px';
|
|
|
|
} else if (i > 1) {
|
|
|
|
top = '2px';
|
|
|
|
}
|
|
|
|
} else if (size === 4) {
|
|
|
|
if (i === 0 || i === 2) {
|
|
|
|
right = '2px';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i === 1 || i === 3) {
|
|
|
|
left = '2px';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < 2) {
|
|
|
|
bottom = '2px';
|
|
|
|
} else {
|
|
|
|
top = '2px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-07 23:24:26 +00:00
|
|
|
return <a key={attachment.get('id')} href={attachment.get('url')} target='_blank' style={{ boxSizing: 'border-box', position: 'relative', left: left, top: top, right: right, bottom: bottom, float: 'left', textDecoration: 'none', border: 'none', display: 'block', width: `${width}%`, height: `${height}%`, background: `url(${attachment.get('preview_url')}) no-repeat center`, backgroundSize: 'cover', cursor: 'zoom-in' }} />;
|
2016-09-05 18:38:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2016-09-18 11:03:37 +00:00
|
|
|
<div style={{ marginTop: '8px', overflow: 'hidden', width: '100%', height: `${this.props.height}px`, boxSizing: 'border-box' }}>
|
2016-09-05 18:38:31 +00:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default MediaGallery;
|