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.

74 lines
1.9 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 = 50;
  13. let height = 100;
  14. let top = 'auto';
  15. let left = 'auto';
  16. let bottom = 'auto';
  17. let right = 'auto';
  18. if (size === 4 || (size === 3 && i > 0)) {
  19. height = 50;
  20. }
  21. if (size === 2) {
  22. if (i === 0) {
  23. right = '2px';
  24. } else {
  25. left = '2px';
  26. }
  27. } else if (size === 3) {
  28. if (i === 0) {
  29. right = '2px';
  30. } else if (i > 0) {
  31. left = '2px';
  32. }
  33. if (i === 1) {
  34. bottom = '2px';
  35. } else if (i > 1) {
  36. top = '2px';
  37. }
  38. } else if (size === 4) {
  39. if (i === 0 || i === 2) {
  40. right = '2px';
  41. }
  42. if (i === 1 || i === 3) {
  43. left = '2px';
  44. }
  45. if (i < 2) {
  46. bottom = '2px';
  47. } else {
  48. top = '2px';
  49. }
  50. }
  51. 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' }} />;
  52. });
  53. return (
  54. <div style={{ marginTop: '8px', overflow: 'hidden', width: '100%', height: '110px', boxSizing: 'border-box' }}>
  55. {children}
  56. </div>
  57. );
  58. }
  59. });
  60. export default MediaGallery;