Skip to content

Commit

Permalink
Added logic to disable <ButtonForCounter>s when they're at either the…
Browse files Browse the repository at this point in the history
… bottom or upper limit of their range.
  • Loading branch information
maratbn committed Aug 5, 2018
1 parent a02cce3 commit 0a28072
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions webpack_in/entry.jsx
Expand Up @@ -240,7 +240,7 @@ class ButtonForCounter extends React.Component {
this._flagCount = true; this._flagCount = true;


const doCount = () => { const doCount = () => {
if (!this._flagCount) { if (!this._flagCount || this.props.isDisabled) {
return; return;
} }


Expand All @@ -258,7 +258,8 @@ class ButtonForCounter extends React.Component {
} }


render() { render() {
return (<button onMouseDown={ this._onCountStart } return (<button disabled={ this.props.isDisabled }
onMouseDown={ this._onCountStart }
onMouseUp={ this._onCountStop } onMouseUp={ this._onCountStop }
onMouseLeave={ this._onCountStop } onMouseLeave={ this._onCountStop }
onTouchStart={ this._onCountStart } onTouchStart={ this._onCountStart }
Expand All @@ -269,6 +270,7 @@ class ButtonForCounter extends React.Component {


ButtonForCounter.propTypes = { ButtonForCounter.propTypes = {
caption: PropTypes.string.isRequired, caption: PropTypes.string.isRequired,
isDisabled: PropTypes.bool,
onCount: PropTypes.func.isRequired onCount: PropTypes.func.isRequired
}; };


Expand Down Expand Up @@ -317,6 +319,7 @@ class ColorComponentEntry extends React.Component {
this.props.onChangeValue(convertValue(strValueEntered)); this.props.onChangeValue(convertValue(strValueEntered));
}} /> }} />
<ButtonForCounter caption="&#9650;" <ButtonForCounter caption="&#9650;"
isDisabled={ this.props.value === 255 }
onCount={ () => { onCount={ () => {
const valueNew = this.props.value + 1; const valueNew = this.props.value + 1;


Expand All @@ -327,6 +330,7 @@ class ColorComponentEntry extends React.Component {
this.props.onChangeValue(valueNew); this.props.onChangeValue(valueNew);
}} /> }} />
<ButtonForCounter caption="&#9660;" <ButtonForCounter caption="&#9660;"
isDisabled={ this.props.value === 0 }
onCount={ () => { onCount={ () => {
const valueNew = this.props.value - 1; const valueNew = this.props.value - 1;


Expand Down

0 comments on commit 0a28072

Please sign in to comment.