File tree 3 files changed +21
-1
lines changed
examples/react-chayns-amountcontrol
src/react-chayns-amountcontrol
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,13 @@ export default class Example extends React.Component {
139
139
shopStyle
140
140
/>
141
141
</ div >
142
+
143
+ < AmountControl
144
+ amount = { amount }
145
+ onInput = { this . onChange }
146
+ buttonText = "0,10"
147
+ showInput = { amount > 0 }
148
+ />
142
149
</ ExampleContainer >
143
150
) ;
144
151
}
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ You can set the following props on a AmountControl element:
39
39
| amount | The current amount (behaves like value, not like defaultValue) | number | 0 |
40
40
| className | The css class of the AmountControl-wrapper | string | |
41
41
| 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 | |
42
43
| onAdd | Function that is called when the user click on the add button | function | |
43
44
| onRemove | Function that is called when the user click on the remove button | function | |
44
45
| equalize | Equalizes a set of AmountControls (see examples) | string | |
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export default class AmountControl extends React.Component {
10
10
buttonText : PropTypes . string . isRequired ,
11
11
amount : PropTypes . number ,
12
12
onChange : PropTypes . func ,
13
+ onInput : PropTypes . func ,
13
14
onAdd : PropTypes . func ,
14
15
onRemove : PropTypes . func ,
15
16
equalize : PropTypes . string ,
@@ -27,6 +28,7 @@ export default class AmountControl extends React.Component {
27
28
static defaultProps = {
28
29
amount : 0 ,
29
30
onChange : null ,
31
+ onInput : null ,
30
32
onAdd : null ,
31
33
onRemove : null ,
32
34
equalize : null ,
@@ -59,6 +61,12 @@ export default class AmountControl extends React.Component {
59
61
this . setState ( {
60
62
tempValue : value
61
63
} ) ;
64
+
65
+ const { onInput } = this . props ;
66
+
67
+ if ( onInput && ( value || value === 0 ) ) {
68
+ onInput ( value ) ;
69
+ }
62
70
} ;
63
71
64
72
getRemoveIcon ( ) {
@@ -99,11 +107,15 @@ export default class AmountControl extends React.Component {
99
107
} ;
100
108
101
109
changeAmount = ( amount ) => {
102
- const { onChange } = this . props ;
110
+ const { onChange, onInput } = this . props ;
103
111
104
112
if ( onChange ) {
105
113
onChange ( amount ) ;
106
114
}
115
+
116
+ if ( onInput ) {
117
+ onInput ( amount ) ;
118
+ }
107
119
} ;
108
120
109
121
render ( ) {
You can’t perform that action at this time.
0 commit comments