@@ -34,6 +34,8 @@ export default class AmountControl extends PureComponent {
34
34
equalize : PropTypes . string ,
35
35
focusOnClick : PropTypes . bool ,
36
36
contentWidth : PropTypes . number ,
37
+ min : PropTypes . number ,
38
+ max : PropTypes . number ,
37
39
stopPropagation : PropTypes . bool ,
38
40
} ;
39
41
@@ -59,6 +61,8 @@ export default class AmountControl extends PureComponent {
59
61
focusOnClick : true ,
60
62
contentWidth : null ,
61
63
stopPropagation : false ,
64
+ min : null ,
65
+ max : null ,
62
66
plusIcon : faPlus ,
63
67
minusIcon : faMinus ,
64
68
removeIcon : faMinus ,
@@ -119,15 +123,23 @@ export default class AmountControl extends PureComponent {
119
123
}
120
124
121
125
addItem = ( ) => {
122
- const { amount, onAdd } = this . props ;
126
+ const { amount, onAdd, max } = this . props ;
127
+
128
+ if ( max && amount + 1 > max ) {
129
+ return ;
130
+ }
123
131
124
132
if ( onAdd ) onAdd ( ) ;
125
133
126
134
this . changeAmount ( amount + 1 ) ;
127
135
} ;
128
136
129
137
removeItem = ( ) => {
130
- const { amount, onRemove } = this . props ;
138
+ const { amount, onRemove, min } = this . props ;
139
+
140
+ if ( min && amount - 1 < min ) {
141
+ return ;
142
+ }
131
143
132
144
if ( onRemove ) onRemove ( ) ;
133
145
@@ -145,6 +157,8 @@ export default class AmountControl extends PureComponent {
145
157
amount : oldAmount ,
146
158
disableAdd,
147
159
disableRemove,
160
+ min,
161
+ max,
148
162
} = this . props ;
149
163
150
164
if ( onInput ) {
@@ -153,7 +167,9 @@ export default class AmountControl extends PureComponent {
153
167
154
168
if ( onChange ) {
155
169
if ( ( disableAdd && amount > oldAmount )
156
- || ( disableRemove && amount < oldAmount ) ) {
170
+ || ( disableRemove && amount < oldAmount )
171
+ || ( min && amount < min )
172
+ || ( max && amount > max ) ) {
157
173
this . setState ( {
158
174
tempValue : oldAmount ,
159
175
} ) ;
@@ -191,6 +207,8 @@ export default class AmountControl extends PureComponent {
191
207
contentWidth,
192
208
stopPropagation,
193
209
plusIcon,
210
+ max,
211
+ min,
194
212
} = this . props ;
195
213
const { tempAmount, tempValue, showInput } = this . state ;
196
214
@@ -204,7 +222,7 @@ export default class AmountControl extends PureComponent {
204
222
stopPropagation = { stopPropagation }
205
223
icon = { this . getRemoveIcon ( ) }
206
224
onClick = { this . removeItem }
207
- disabled = { disabled || disableRemove }
225
+ disabled = { disabled || disableRemove || ( min && ( amount <= min ) ) }
208
226
className = { classNames ( 'cc__amount-control__remove' , { 'cc__amount-control--icon' : amount > 0 || icon } ) }
209
227
color = { ( icon && ! tempAmount ) ? iconColor : removeColor }
210
228
/>
@@ -231,7 +249,7 @@ export default class AmountControl extends PureComponent {
231
249
stopPropagation = { stopPropagation }
232
250
icon = { plusIcon }
233
251
onClick = { this . addItem }
234
- disabled = { disabled || disableAdd }
252
+ disabled = { disabled || disableAdd || ( max && ( amount >= max ) ) }
235
253
className = { classNames ( 'cc__amount-control__add' , { 'cc__amount-control--icon' : amount > 0 } ) }
236
254
color = { addColor }
237
255
/>
0 commit comments