You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. const MediaGallery = React.createClass({
  4. propTypes: {
  5. media: ImmutablePropTypes.list.isRequired
  6. },
  7. mixins: [PureRenderMixin],
  8. render () {
  9. var children = this.props.media.take(4);
  10. var size = children.size;
  11. children = children.map((attachment, i) => {
  12. let width = 142;
  13. let height = 110;
  14. let marginRight = 0;
  15. if (size == 4 || (size === 3 && i > 0)) {
  16. height = 52.5;
  17. }
  18. if ((size === 3 && i === 0) || (size === 4 && i % 2 === 0)) {
  19. marginRight = 5;
  20. }
  21. return <a key={attachment.get('id')} href={attachment.get('url')} style={{ position: 'relative', float: 'left', marginRight: `${marginRight}px`, marginBottom: '5px', textDecoration: 'none', border: 'none', display: 'block', width: `${width}px`, height: `${height}px`, background: `url(${attachment.get('preview_url')}) no-repeat`, backgroundSize: 'cover', cursor: 'zoom-in' }} />;
  22. });
  23. return (
  24. <div style={{ marginTop: '8px', overflow: 'hidden', marginBottom: '-5px' }}>
  25. {children}
  26. </div>
  27. );
  28. }
  29. });
  30. export default MediaGallery;