@@ -2,11 +2,12 @@ import {
2
2
NumberInputActionContext ,
3
3
NumberInputReducerAction ,
4
4
NumberInputState ,
5
- StepDirection ,
6
5
} from './useNumberInput.types' ;
7
6
import { NumberInputActionTypes } from './numberInputAction.types' ;
8
7
import { clamp , isNumber } from './utils' ;
9
8
9
+ type Direction = '+' | '-' ;
10
+
10
11
// extracted from handleValueChange
11
12
function getClampedValues ( rawValue : number | undefined , context : NumberInputActionContext ) {
12
13
const { min, max, step } = context ;
@@ -24,22 +25,22 @@ function getClampedValues(rawValue: number | undefined, context: NumberInputActi
24
25
function stepValue (
25
26
state : NumberInputState ,
26
27
context : NumberInputActionContext ,
27
- direction : StepDirection ,
28
+ direction : Direction ,
28
29
multiplier : number ,
29
30
) {
30
31
const { value } = state ;
31
32
const { step = 1 , min, max } = context ;
32
33
33
34
if ( isNumber ( value ) ) {
34
35
return {
35
- up : value + ( step ?? 1 ) * multiplier ,
36
- down : value - ( step ?? 1 ) * multiplier ,
36
+ '+' : value + ( step ?? 1 ) * multiplier ,
37
+ '-' : value - ( step ?? 1 ) * multiplier ,
37
38
} [ direction ] ;
38
39
}
39
40
40
41
return {
41
- up : min ?? 0 ,
42
- down : max ?? 0 ,
42
+ '+' : min ?? 0 ,
43
+ '-' : max ?? 0 ,
43
44
} [ direction ] ;
44
45
}
45
46
@@ -98,8 +99,8 @@ function handleInputChange<State extends NumberInputState>(
98
99
function handleStep < State extends NumberInputState > (
99
100
state : State ,
100
101
context : NumberInputActionContext ,
102
+ direction : Direction ,
101
103
applyMultiplier : boolean ,
102
- direction : StepDirection ,
103
104
) {
104
105
const multiplier = applyMultiplier ? context . shiftMultiplier : 1 ;
105
106
@@ -143,9 +144,9 @@ export function numberInputReducer(
143
144
case NumberInputActionTypes . inputChange :
144
145
return handleInputChange ( state , context , action . inputValue ) ;
145
146
case NumberInputActionTypes . increment :
146
- return handleStep ( state , context , action . applyMultiplier , 'up' ) ;
147
+ return handleStep ( state , context , '+' , action . applyMultiplier ) ;
147
148
case NumberInputActionTypes . decrement :
148
- return handleStep ( state , context , action . applyMultiplier , 'down' ) ;
149
+ return handleStep ( state , context , '-' , action . applyMultiplier ) ;
149
150
case NumberInputActionTypes . incrementToMax :
150
151
return handleToMinOrMax ( state , context , 'max' ) ;
151
152
case NumberInputActionTypes . decrementToMin :
0 commit comments