Skip to content

Commit 3ad89ef

Browse files
committed
Merge branch 'feature/amount-control_on-input'
2 parents 7cb5cb7 + 0e8e67f commit 3ad89ef

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

examples/react-chayns-amountcontrol/Example.jsx

+7
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ export default class Example extends React.Component {
139139
shopStyle
140140
/>
141141
</div>
142+
143+
<AmountControl
144+
amount={amount}
145+
onInput={this.onChange}
146+
buttonText="0,10"
147+
showInput={amount > 0}
148+
/>
142149
</ExampleContainer>
143150
);
144151
}

src/react-chayns-amountcontrol/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ You can set the following props on a AmountControl element:
3939
| amount | The current amount (behaves like value, not like defaultValue) | number | 0 |
4040
| className | The css class of the AmountControl-wrapper | string | |
4141
| onChange | Function that is called when the user changes the amount | function | |
42+
| onInput | Function that is called directly when the user changes the amount | function | |
4243
| onAdd | Function that is called when the user click on the add button | function | |
4344
| onRemove | Function that is called when the user click on the remove button | function | |
4445
| equalize | Equalizes a set of AmountControls (see examples) | string | |

src/react-chayns-amountcontrol/component/AmountControl.jsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class AmountControl extends React.Component {
1010
buttonText: PropTypes.string.isRequired,
1111
amount: PropTypes.number,
1212
onChange: PropTypes.func,
13+
onInput: PropTypes.func,
1314
onAdd: PropTypes.func,
1415
onRemove: PropTypes.func,
1516
equalize: PropTypes.string,
@@ -27,6 +28,7 @@ export default class AmountControl extends React.Component {
2728
static defaultProps = {
2829
amount: 0,
2930
onChange: null,
31+
onInput: null,
3032
onAdd: null,
3133
onRemove: null,
3234
equalize: null,
@@ -59,6 +61,12 @@ export default class AmountControl extends React.Component {
5961
this.setState({
6062
tempValue: value
6163
});
64+
65+
const { onInput } = this.props;
66+
67+
if(onInput && (value || value === 0)) {
68+
onInput(value);
69+
}
6270
};
6371

6472
getRemoveIcon() {
@@ -99,11 +107,15 @@ export default class AmountControl extends React.Component {
99107
};
100108

101109
changeAmount = (amount) => {
102-
const { onChange } = this.props;
110+
const { onChange, onInput } = this.props;
103111

104112
if(onChange) {
105113
onChange(amount);
106114
}
115+
116+
if(onInput) {
117+
onInput(amount);
118+
}
107119
};
108120

109121
render() {

0 commit comments

Comments
 (0)