@@ -8,8 +8,24 @@ import type { ISliderThumbProps } from './types';
8
8
import Box from '../Box' ;
9
9
import { SliderContext } from './Context' ;
10
10
import { useHasResponsiveProps } from '../../../hooks/useHasResponsiveProps' ;
11
+ import { useHover } from '@react-native-aria/interactions' ;
12
+ import { mergeRefs } from '../../../utils' ;
13
+ import { extractInObject , stylingProps } from '../../../theme/tools/utils' ;
14
+ import { Stack } from '../Stack' ;
15
+ import { Center } from '../../composites/Center' ;
11
16
12
17
function SliderThumb ( props : ISliderThumbProps , ref : any ) {
18
+ const [ isPressed , setIsPressed ] = React . useState ( false ) ;
19
+
20
+ const [ isFocused , setIsFocused ] = React . useState ( false ) ;
21
+ const handleFocus = ( focusState : boolean , callback : any ) => {
22
+ setIsFocused ( focusState ) ;
23
+ callback ( ) ;
24
+ } ;
25
+
26
+ const _ref = React . useRef ( null ) ;
27
+ const { isHovered } = useHover ( { } , _ref ) ;
28
+
13
29
const {
14
30
state,
15
31
trackLayout,
@@ -18,16 +34,31 @@ function SliderThumb(props: ISliderThumbProps, ref: any) {
18
34
thumbSize,
19
35
isReadOnly,
20
36
isDisabled,
37
+ _interactionBox : interactionBoxContext ,
21
38
} = React . useContext ( SliderContext ) ;
22
- const resolvedProps = usePropsResolution (
39
+ const {
40
+ onFocus,
41
+ onBlur,
42
+ _stack,
43
+ _interactionBox,
44
+ ...resolvedProps
45
+ } = usePropsResolution (
23
46
'SliderThumb' ,
24
47
{
25
48
size : thumbSize ,
49
+ _interactionBox : interactionBoxContext ,
26
50
colorScheme,
27
51
...props ,
28
52
} ,
29
- { isDisabled, isReadOnly }
53
+ {
54
+ isDisabled,
55
+ isReadOnly,
56
+ isPressed,
57
+ isFocused,
58
+ isHovered,
59
+ }
30
60
) ;
61
+
31
62
const inputRef = React . useRef ( null ) ;
32
63
const { thumbProps, inputProps } = useSliderThumb (
33
64
{
@@ -39,6 +70,10 @@ function SliderThumb(props: ISliderThumbProps, ref: any) {
39
70
state
40
71
) ;
41
72
73
+ React . useEffect ( ( ) => {
74
+ setIsPressed ( state . isThumbDragging ( 0 ) ) ;
75
+ } , [ state ] ) ;
76
+
42
77
const thumbAbsoluteSize = useToken ( 'sizes' , resolvedProps . size ) ;
43
78
44
79
const thumbStyles : any = {
@@ -59,6 +94,23 @@ function SliderThumb(props: ISliderThumbProps, ref: any) {
59
94
thumbStyles . transform . push ( {
60
95
scale : state . isThumbDragging ( 0 ) ? resolvedProps . scaleOnPressed : 1 ,
61
96
} ) ;
97
+
98
+ const [ layoutProps , nonLayoutProps ] = extractInObject ( resolvedProps , [
99
+ ...stylingProps . margin ,
100
+ ...stylingProps . layout ,
101
+ ...stylingProps . flexbox ,
102
+ ...stylingProps . position ,
103
+ ...stylingProps . outline ,
104
+ ] ) ;
105
+
106
+ const [
107
+ accessibilityProps ,
108
+ nonAccessibilityProps ,
109
+ ] = extractInObject ( nonLayoutProps , [
110
+ 'accessibilityRole' ,
111
+ 'accessibilityState' ,
112
+ ] ) ;
113
+
62
114
//TODO: refactor for responsive prop
63
115
if ( useHasResponsiveProps ( props ) ) {
64
116
return null ;
@@ -69,17 +121,30 @@ function SliderThumb(props: ISliderThumbProps, ref: any) {
69
121
position = "absolute"
70
122
{ ...thumbProps }
71
123
{ ...resolvedProps }
72
- ref = { ref }
73
- style = { [ thumbStyles , props . style ] }
124
+ { ...accessibilityProps }
125
+ { ...layoutProps }
126
+ style = { [ thumbStyles , resolvedProps . style ] }
127
+ onFocus = { ( e : any ) => {
128
+ handleFocus ( true , onFocus ? ( ) => onFocus ( e ) : ( ) => { } ) ;
129
+ } }
130
+ onBlur = { ( e : any ) => {
131
+ handleFocus ( false , onBlur ? ( ) => onBlur ( e ) : ( ) => { } ) ;
132
+ } }
74
133
// {...(isReadOnly && _readOnly)}
75
134
// {...(isDisabled && _disabled)}
135
+ ref = { mergeRefs ( [ _ref , ref ] ) }
76
136
>
77
- { props . children }
78
- { Platform . OS === 'web' && (
79
- < VisuallyHidden >
80
- < input ref = { inputRef } { ...inputProps } />
81
- </ VisuallyHidden >
82
- ) }
137
+ < Stack { ..._stack } >
138
+ < Box { ..._interactionBox } />
139
+ < Center { ...nonAccessibilityProps } >
140
+ { props . children }
141
+ { Platform . OS === 'web' && (
142
+ < VisuallyHidden >
143
+ < input ref = { inputRef } { ...inputProps } />
144
+ </ VisuallyHidden >
145
+ ) }
146
+ </ Center >
147
+ </ Stack >
83
148
</ Box >
84
149
) ;
85
150
}
0 commit comments