|
| 1 | +import PropTypes from 'prop-types'; |
| 2 | +import React from 'react'; |
| 3 | +import ReactDOM from 'react-dom'; |
| 4 | +import Gallery from '../src/Gallery'; |
| 5 | + |
| 6 | +class ImageComponent extends React.Component { |
| 7 | + constructor(props) { |
| 8 | + super(props); |
| 9 | + this.state = { |
| 10 | + show: false |
| 11 | + }; |
| 12 | + } |
| 13 | + |
| 14 | + render () { |
| 15 | + if (this.state.show) { |
| 16 | + return <img {...this.props.imageProps} />; |
| 17 | + } else { |
| 18 | + return ( |
| 19 | + <div |
| 20 | + style={Object.assign({}, this.props.imageProps.style, { textAlign: 'center' })} |
| 21 | + onMouseOver={() => this.setState({ show: true })} |
| 22 | + > |
| 23 | + Hover to show |
| 24 | + </div> |
| 25 | + ); |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +class Demo7 extends React.Component { |
| 31 | + constructor(props){ |
| 32 | + super(props); |
| 33 | + |
| 34 | + this.state = { |
| 35 | + images: this.props.images |
| 36 | + }; |
| 37 | + } |
| 38 | + |
| 39 | + render () { |
| 40 | + return ( |
| 41 | + <div style={{ |
| 42 | + display: "block", |
| 43 | + minHeight: "1px", |
| 44 | + width: "100%", |
| 45 | + border: "1px solid #ddd", |
| 46 | + overflow: "auto"}}> |
| 47 | + <Gallery |
| 48 | + images={this.state.images} |
| 49 | + lightboxWidth={1536} |
| 50 | + thumbnailImageComponent={ImageComponent} |
| 51 | + enableLightbox={true} |
| 52 | + enableImageSelection={false} |
| 53 | + /> |
| 54 | + </div> |
| 55 | + ); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +Demo7.propTypes = { |
| 60 | + images: PropTypes.arrayOf( |
| 61 | + PropTypes.shape({ |
| 62 | + src: PropTypes.string.isRequired, |
| 63 | + thumbnail: PropTypes.string.isRequired, |
| 64 | + srcset: PropTypes.array, |
| 65 | + caption: PropTypes.string, |
| 66 | + thumbnailWidth: PropTypes.number.isRequired, |
| 67 | + thumbnailHeight: PropTypes.number.isRequired, |
| 68 | + isSelected: PropTypes.bool |
| 69 | + }) |
| 70 | + ).isRequired |
| 71 | +}; |
| 72 | + |
| 73 | +Demo7.defaultProps = { |
| 74 | + images: shuffleArray([ |
| 75 | + { |
| 76 | + src: "https://c5.staticflickr.com/9/8768/28941110956_b05ab588c1_b.jpg", |
| 77 | + thumbnail: "https://c5.staticflickr.com/9/8768/28941110956_b05ab588c1_n.jpg", |
| 78 | + thumbnailWidth: 240, |
| 79 | + thumbnailHeight: 320, |
| 80 | + caption: "8H (gratisography.com)" |
| 81 | + }, |
| 82 | + { |
| 83 | + src: "https://c3.staticflickr.com/9/8583/28354353794_9f2d08d8c0_b.jpg", |
| 84 | + thumbnail: "https://c3.staticflickr.com/9/8583/28354353794_9f2d08d8c0_n.jpg", |
| 85 | + thumbnailWidth: 320, |
| 86 | + thumbnailHeight: 190, |
| 87 | + caption: "286H (gratisography.com)" |
| 88 | + }, |
| 89 | + { |
| 90 | + src: "https://c7.staticflickr.com/9/8569/28941134686_d57273d933_b.jpg", |
| 91 | + thumbnail: "https://c7.staticflickr.com/9/8569/28941134686_d57273d933_n.jpg", |
| 92 | + thumbnailWidth: 320, |
| 93 | + thumbnailHeight: 148, |
| 94 | + caption: "315H (gratisography.com)" |
| 95 | + }, |
| 96 | + { |
| 97 | + src: "https://c6.staticflickr.com/9/8342/28897193381_800db6419e_b.jpg", |
| 98 | + thumbnail: "https://c6.staticflickr.com/9/8342/28897193381_800db6419e_n.jpg", |
| 99 | + thumbnailWidth: 320, |
| 100 | + thumbnailHeight: 213, |
| 101 | + caption: "201H (gratisography.com)" |
| 102 | + }, |
| 103 | + { |
| 104 | + src: "https://c2.staticflickr.com/9/8239/28897202241_1497bec71a_b.jpg", |
| 105 | + thumbnail: "https://c2.staticflickr.com/9/8239/28897202241_1497bec71a_n.jpg", |
| 106 | + thumbnailWidth: 248, |
| 107 | + thumbnailHeight: 320, |
| 108 | + caption: "Big Ben (Tom Eversley - isorepublic.com)" |
| 109 | + }, |
| 110 | + { |
| 111 | + src: "https://c1.staticflickr.com/9/8785/28687743710_870813dfde_h.jpg", |
| 112 | + thumbnail: "https://c1.staticflickr.com/9/8785/28687743710_3580fcb5f0_n.jpg", |
| 113 | + thumbnailWidth: 320, |
| 114 | + thumbnailHeight: 113, |
| 115 | + caption: "Red Zone - Paris (Tom Eversley - isorepublic.com)" |
| 116 | + }, |
| 117 | + { |
| 118 | + src: "https://c6.staticflickr.com/9/8520/28357073053_cafcb3da6f_b.jpg", |
| 119 | + thumbnail: "https://c6.staticflickr.com/9/8520/28357073053_cafcb3da6f_n.jpg", |
| 120 | + thumbnailWidth: 313, |
| 121 | + thumbnailHeight: 320, |
| 122 | + caption: "Wood Glass (Tom Eversley - isorepublic.com)" |
| 123 | + }, |
| 124 | + { |
| 125 | + src: "https://c8.staticflickr.com/9/8104/28973555735_ae7c208970_b.jpg", |
| 126 | + thumbnail: "https://c8.staticflickr.com/9/8104/28973555735_ae7c208970_n.jpg", |
| 127 | + thumbnailWidth: 320, |
| 128 | + thumbnailHeight: 213, |
| 129 | + caption: "Flower Interior Macro (Tom Eversley - isorepublic.com)" |
| 130 | + } |
| 131 | + ]) |
| 132 | +}; |
| 133 | + |
| 134 | +ReactDOM.render(<Demo7 />, document.getElementById('demo7')); |
0 commit comments