|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import MoreImages from './MoreImages'; |
| 4 | +import ImageContainer from './ImageContainer'; |
| 5 | + |
| 6 | +export default class Gallery extends React.Component { |
| 7 | + static propTypes = { |
| 8 | + urls: PropTypes.array.isRequired, |
| 9 | + onlyIcon: PropTypes.bool, |
| 10 | + onClick: PropTypes.func |
| 11 | + |
| 12 | + }; |
| 13 | + static defaultProps = { |
| 14 | + onlyIcon: false, |
| 15 | + onClick: chayns.openImage |
| 16 | + }; |
| 17 | + |
| 18 | + constructor() { |
| 19 | + super(); |
| 20 | + this.openFirstImage = this.openGallery.bind(this, 0); |
| 21 | + this.openSecondImage = this.openGallery.bind(this, 1); |
| 22 | + this.openThirdImage = this.openGallery.bind(this, 2); |
| 23 | + } |
| 24 | + |
| 25 | + openGallery(start) { |
| 26 | + this.props.onClick(this.props.urls, start); |
| 27 | + } |
| 28 | + |
| 29 | + render() { |
| 30 | + const { urls, onlyIcon } = this.props; |
| 31 | + const count = urls.length; |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className="chayns-gallery" > |
| 35 | + <div className="gallery-grid"> |
| 36 | + <ImageContainer |
| 37 | + className="gallery_item" |
| 38 | + url={urls[0]} |
| 39 | + onClick={this.openFirstImage} |
| 40 | + /> |
| 41 | + {(count > 1) && ( |
| 42 | + <ImageContainer |
| 43 | + className="gallery_item" |
| 44 | + url={urls[1]} |
| 45 | + onClick={this.openSecondImage} |
| 46 | + /> |
| 47 | + )} |
| 48 | + {(count > 2) && ( |
| 49 | + <ImageContainer |
| 50 | + className="gallery_item" |
| 51 | + url={urls[2]} |
| 52 | + onClick={this.openThirdImage} |
| 53 | + > |
| 54 | + {(count > 3) && ( |
| 55 | + <MoreImages |
| 56 | + count={count - 3} |
| 57 | + onlyIcon={onlyIcon} |
| 58 | + /> |
| 59 | + )} |
| 60 | + </ImageContainer> |
| 61 | + )} |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
0 commit comments