export default class Number extends Component { static propTypes = { onChange: PropTypes.func.isRequired } constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.doneChange = this.doneChange.bind(this); this.state = { i: 0, pressed: false }; } handleChange(i) { this.doneChange(true); let I = this.state.i; while (this.state.pressed) { I += i; if (I > 150) { I = 150; } if (I < 0) { I = 0; } } this.setState({ i: I }, () => { this.props.onChange(this.state.i); }); } doneChange(isPressed) { this.setState({ pressed: isPressed }); }
render() { const styles = require('./Number.scss'); return ( <div className={styles.number}> <button ><span>-</span></button> <div className={styles.numeral}>{this.state.i}</div> <button ><span>+</span></button> </div>); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)