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.

75 lines
2.0 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. height: React.PropTypes.number.isRequired
  7. },
  8. mixins: [PureRenderMixin],
  9. render () {
  10. var children = this.props.media.take(4);
  11. var size = children.size;
  12. children = children.map((attachment, i) => {
  13. let width = 50;
  14. let height = 100;
  15. let top = 'auto';
  16. let left = 'auto';
  17. let bottom = 'auto';
  18. let right = 'auto';
  19. if (size === 4 || (size === 3 && i > 0)) {
  20. height = 50;
  21. }
  22. if (size === 2) {
  23. if (i === 0) {
  24. right = '2px';
  25. } else {
  26. left = '2px';
  27. }
  28. } else if (size === 3) {
  29. if (i === 0) {
  30. right = '2px';
  31. } else if (i > 0) {
  32. left = '2px';
  33. }
  34. if (i === 1) {
  35. bottom = '2px';
  36. } else if (i > 1) {
  37. top = '2px';
  38. }
  39. } else if (size === 4) {
  40. if (i === 0 || i === 2) {
  41. right = '2px';
  42. }
  43. if (i === 1 || i === 3) {
  44. left = '2px';
  45. }
  46. if (i < 2) {
  47. bottom = '2px';
  48. } else {
  49. top = '2px';
  50. }
  51. }
  52. 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' }} />;
  53. });
  54. return (
  55. <div style={{ marginTop: '8px', overflow: 'hidden', width: '100%', height: `${this.props.height}px`, boxSizing: 'border-box' }}>
  56. {children}
  57. </div>
  58. );
  59. }
  60. });
  61. export default MediaGallery;