Skip to content

Commit 2696d03

Browse files
authored
Stepper - Add step prop to control the increase and decrease level (#1330)
1 parent 24f16cc commit 2696d03

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

demo/src/screens/componentScreens/StepperScreen.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ export default class StepperScreen extends Component {
4242
onValueChange={count => this.setState({itemsCount: count})}
4343
initialValue={1}
4444
/>
45+
46+
<View row center>
47+
<Text text60 primary>Count: </Text>
48+
<Stepper
49+
step={0.5}
50+
min={1}
51+
max={50}
52+
onValueChange={count => this.setState({itemsCount: count})}
53+
initialValue={1}
54+
/>
55+
</View>
4556
</View>
4657
</ScrollView>
4758
);

src/components/stepper/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import {PureBaseComponent} from '../../commons';
1414
export default class Stepper extends PureBaseComponent {
1515
static displayName = 'Stepper';
1616
static propTypes = {
17+
/**
18+
* The step to increase and decrease by (default is 1)
19+
*/
20+
step: PropTypes.number,
1721
/**
1822
* Text to show next to the current number
1923
*/
@@ -89,7 +93,7 @@ export default class Stepper extends PureBaseComponent {
8993
break;
9094
}
9195
};
92-
96+
9397
generateStyles() {
9498
this.styles = createStyles(this.props.size);
9599
}
@@ -119,6 +123,18 @@ export default class Stepper extends PureBaseComponent {
119123
}
120124
}
121125

126+
get step() {
127+
return this.props.step || 1;
128+
}
129+
130+
decrease = () => {
131+
this.updateValue(this.state.value - this.step);
132+
}
133+
134+
increase = () => {
135+
this.updateValue(this.state.value + this.step);
136+
}
137+
122138
render() {
123139
const {minusDisabled, plusDisabled, testID} = this.getDisabledState();
124140
return (
@@ -134,15 +150,15 @@ export default class Stepper extends PureBaseComponent {
134150
testID={`${testID}.decrease`}
135151
styles={this.styles}
136152
disabled={minusDisabled}
137-
onPress={() => this.updateValue(this.state.value - 1)}
153+
onPress={this.decrease}
138154
/>
139155
<View style={this.styles.separator}/>
140156
<StepperButton
141157
label="+"
142158
testID={`${testID}.increase`}
143159
styles={this.styles}
144160
disabled={plusDisabled}
145-
onPress={() => this.updateValue(this.state.value + 1)}
161+
onPress={this.increase}
146162
/>
147163
</View>
148164
</View>

0 commit comments

Comments
 (0)