Skip to content

Commit fa29249

Browse files
committed
feat: added new props for disable buttons
Added buttonLeftDisabled Added buttonRightEnabled
1 parent 243a806 commit fa29249

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

PROPS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
| `background` | Background color of number button | String | `transparent` | |
1111
| `buttonFontFamily` | Custom fontFamily of buttons of the Spinner | String | `System Default` | |
1212
| `buttonFontSize` | Custom fontSize of buttons of the Spinner | Number | `14` | |
13+
| `buttonLeftDisabled` | Disable left button | Boolean | `false` | |
1314
| `buttonLeftImage` | Custom element on the button left of the spinner | Component | | |
1415
| `buttonLeftText` | Custom text on the button left of the spinner | String | | |
1516
| `buttonPressLeftImage` | Custom element on the button left of the spinner on pressed state | Component | | |
1617
| `buttonPressRightImage` | Custom element on the button right of the spinner on pressed state | Component | | |
1718
| `buttonPressStyle` | Button Style on Pressed state (Plus and Minus buttons) | Object | | Could overwrite other props |
1819
| `buttonPressTextColor` | Custom color of the button of the Spinner on Pressed state | String | `#FFFFFF` | |
20+
| `buttonRightDisabled` | Disable right button | Boolean | `false` | |
1921
| `buttonRightImage` | Custom element on the button right of the spinner | Component | | |
2022
| `buttonRightText` | Custom text on the button right of the spinner | String | | |
2123
| `buttonStyle` | Button Style (Plus and Minus buttons) | Object | | Could overwrite other props |

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Check the "[Props List](PROPS.md)" file to have the complete list of component p
167167
| `arrows` | Labels on button will be (< and >) instead of (+ and -) | Boolean | `false` |
168168
| `rounded` | Use circular button | Boolean | `true` |
169169
| `activeOpacity` | Opacity of underlay on pressed button | Number | `0.85` |
170+
| `buttonLeftDisabled` | Disable left button | Boolean | `false` | |
171+
| `buttonRightDisabled` | Disable right button | Boolean | `false` | |
170172
| `buttonLeftText` | Custom text on the button left of the spinner | String | |
171173
| `buttonRightText` | Custom text on the button right of the spinner | String | |
172174
| `buttonLeftImage` | Custom element on the button left of the spinner | Component | | Could overwrite other props |

index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class InputSpinner extends Component {
191191
* Increase
192192
*/
193193
increase() {
194-
if (this.props.disabled) return;
194+
if (this._isDisabledButtonRight()) return;
195195
let num =
196196
this.parseNum(this.state.value) + this.parseNum(this.state.step);
197197
if (this.props.onIncrease) {
@@ -208,7 +208,7 @@ class InputSpinner extends Component {
208208
* Decrease
209209
*/
210210
decrease() {
211-
if (this.props.disabled) return;
211+
if (this._isDisabledButtonLeft()) return;
212212
let num =
213213
this.parseNum(this.state.value) - this.parseNum(this.state.step);
214214
if (this.props.onDecrease) {
@@ -262,6 +262,24 @@ class InputSpinner extends Component {
262262
return !this.props.disabled && this.props.editable;
263263
}
264264

265+
/**
266+
* Is left button disabled
267+
* @returns {Boolean}
268+
* @private
269+
*/
270+
_isDisabledButtonLeft(){
271+
return (this.props.disabled || this.props.buttonRightDisabled);
272+
}
273+
274+
/**
275+
* Is right button disabled
276+
* @returns {Boolean}
277+
* @private
278+
*/
279+
_isDisabledButtonRight(){
280+
return (this.props.disabled || this.props.buttonRightDisabled);
281+
}
282+
265283
/**
266284
* Is right button pressed
267285
* @returns {boolean}
@@ -572,6 +590,7 @@ class InputSpinner extends Component {
572590
underlayColor={this._getColorPress()}
573591
onHideUnderlay={this.onHideUnderlay.bind(this)}
574592
onShowUnderlay={this.onShowUnderlay.bind(this, "left")}
593+
disabled={this._isDisabledButtonLeft()}
575594
style={buttonStyle}
576595
onPress={() => this.decrease()}>
577596
{this._renderLeftButtonElement()}
@@ -605,6 +624,7 @@ class InputSpinner extends Component {
605624
underlayColor={this._getColorPress()}
606625
onHideUnderlay={this.onHideUnderlay.bind(this)}
607626
onShowUnderlay={this.onShowUnderlay.bind(this, "right")}
627+
disabled={this._isDisabledButtonLeft()}
608628
style={buttonStyle}
609629
onPress={() => this.increase()}>
610630
{this._renderRightButtonElement()}
@@ -673,6 +693,8 @@ InputSpinner.propTypes = {
673693
onMax: PropTypes.func,
674694
onIncrease: PropTypes.func,
675695
onDecrease: PropTypes.func,
696+
buttonLeftDisabled: PropTypes.bool,
697+
buttonRightDisabled: PropTypes.bool,
676698
buttonLeftText: PropTypes.string,
677699
buttonRightText: PropTypes.string,
678700
buttonLeftImage: PropTypes.element,
@@ -714,6 +736,8 @@ InputSpinner.defaultProps = {
714736
editable: true,
715737
width: 150,
716738
height: 50,
739+
buttonLeftDisabled: false,
740+
buttonRightDisabled: false,
717741
buttonLeftText: null,
718742
buttonRightText: null,
719743
buttonStyle: {},

0 commit comments

Comments
 (0)