|
| 1 | +import CSSModules from 'react-css-modules'; |
| 2 | +import clickOutsideWrapper from 'react-click-outside'; |
| 3 | +import styles from './Tips.scss'; |
| 4 | +import images from '../images'; |
| 5 | + |
| 6 | +export default |
| 7 | +@clickOutsideWrapper |
| 8 | +@CSSModules(styles, {allowMultiple: true}) |
| 9 | + |
| 10 | +class Tips extends React.Component { |
| 11 | + static propTypes = { |
| 12 | + currentTipId: React.PropTypes.number.isRequired, |
| 13 | + tips: React.PropTypes.number.isRequired, |
| 14 | + open: React.PropTypes.bool.isRequired, |
| 15 | + onCloseTips: React.PropTypes.func.isRequired, |
| 16 | + setCurrentTip: React.PropTypes.func.isRequired, |
| 17 | + }; |
| 18 | + |
| 19 | + handleClickOutside(event) { |
| 20 | + if (this.props.open) { |
| 21 | + this.props.onCloseTips(); |
| 22 | + event.stopPropagation(); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + renderDot(i) { |
| 27 | + const active = i === this.props.currentTipId ? "active" : "" |
| 28 | + return <span styleName={`dot ${active}`} onClick={() => this.props.setCurrentTip(i)}></span> |
| 29 | + } |
| 30 | + |
| 31 | + renderNextButton = () => { |
| 32 | + return <button styleName="next-btn" onClick={()=>this.props.setCurrentTip(this.props.currentTipId + 1)}>next</button> |
| 33 | + } |
| 34 | + |
| 35 | + renderLastButton = () => { |
| 36 | + return <button styleName="last-btn" onClick={this.props.onCloseTips}>{"ok,let's go!"}</button> |
| 37 | + } |
| 38 | + |
| 39 | + render() { |
| 40 | + const tip = this.props.tips[this.props.currentTipId]; |
| 41 | + const isLast = this.props.currentTipId === (this.props.tips.length - 1); |
| 42 | + return ( |
| 43 | + <div styleName="body"> |
| 44 | + <div styleName="close-btn" onClick={this.props.onCloseTips}>SKIP</div> |
| 45 | + <div styleName="header">{tip.header}</div> |
| 46 | + <div styleName="title">{tip.title}</div> |
| 47 | + <img styleName="image"src={images[this.props.currentTipId + 1]}/> |
| 48 | + <div styleName="dots-wrap"> |
| 49 | + { |
| 50 | + this.props.tips.map((t,i) => this.renderDot(i)) |
| 51 | + } |
| 52 | + </div> |
| 53 | + {isLast ? this.renderLastButton() : this.renderNextButton()} |
| 54 | + </div> |
| 55 | + ); |
| 56 | + } |
| 57 | +} |
0 commit comments