@@ -23,12 +23,12 @@ export interface MotionThumbInterface {
23
23
onMotionStart : VoidFunction ;
24
24
onMotionEnd : VoidFunction ;
25
25
direction ?: 'ltr' | 'rtl' ;
26
- position ?: 'horizontal' | 'vertical' ;
26
+ mode ?: 'horizontal' | 'vertical' ;
27
27
}
28
28
29
29
const calcThumbStyle = (
30
30
targetElement : HTMLElement | null | undefined ,
31
- position : 'horizontal' | 'vertical' ,
31
+ mode : 'horizontal' | 'vertical' ,
32
32
) : ThumbReact => {
33
33
if ( ! targetElement ) return null ;
34
34
@@ -47,7 +47,7 @@ const calcThumbStyle = (
47
47
height : targetElement . clientHeight ,
48
48
} ;
49
49
50
- if ( position === 'vertical' ) {
50
+ if ( mode === 'vertical' ) {
51
51
return {
52
52
left : 0 ,
53
53
right : 0 ,
@@ -81,7 +81,7 @@ export default function MotionThumb(props: MotionThumbInterface) {
81
81
onMotionStart,
82
82
onMotionEnd,
83
83
direction,
84
- position = 'horizontal' ,
84
+ mode = 'horizontal' ,
85
85
} = props ;
86
86
87
87
const thumbRef = React . useRef < HTMLDivElement > ( null ) ;
@@ -103,8 +103,8 @@ export default function MotionThumb(props: MotionThumbInterface) {
103
103
const prev = findValueElement ( prevValue ) ;
104
104
const next = findValueElement ( value ) ;
105
105
106
- const calcPrevStyle = calcThumbStyle ( prev , position ) ;
107
- const calcNextStyle = calcThumbStyle ( next , position ) ;
106
+ const calcPrevStyle = calcThumbStyle ( prev , mode ) ;
107
+ const calcNextStyle = calcThumbStyle ( next , mode ) ;
108
108
109
109
setPrevValue ( value ) ;
110
110
setPrevStyle ( calcPrevStyle ) ;
@@ -120,37 +120,45 @@ export default function MotionThumb(props: MotionThumbInterface) {
120
120
121
121
const thumbStart = React . useMemo (
122
122
( ) =>
123
- position === 'vertical'
123
+ mode === 'vertical'
124
124
? toPX ( prevStyle ?. top ?? 0 )
125
- : toPX ( prevStyle ?. left ?? 0 ) ,
126
- [ position , prevStyle ] ,
125
+ : direction === 'rtl'
126
+ ? toPX ( - ( prevStyle ?. right as number ) )
127
+ : toPX ( prevStyle ?. left as number ) ,
128
+ [ mode , direction , prevStyle ] ,
127
129
) ;
128
130
129
131
const thumbActive = React . useMemo (
130
132
( ) =>
131
- position === 'vertical'
133
+ mode === 'vertical'
132
134
? toPX ( nextStyle ?. top ?? 0 )
133
- : toPX ( nextStyle ?. left ?? 0 ) ,
134
- [ position , nextStyle ] ,
135
+ : direction === 'rtl'
136
+ ? toPX ( - ( nextStyle ?. right as number ) )
137
+ : toPX ( nextStyle ?. left as number ) ,
138
+ [ mode , direction , nextStyle ] ,
135
139
) ;
136
140
137
- const onAppearStart = ( ) => ( {
138
- transform : `translate${
139
- position === 'vertical' ? 'Y' : 'X'
140
- } (var(--thumb-start-${ position === 'vertical' ? 'top' : 'left' } ))`,
141
- [ position === 'vertical' ? 'height' : 'width' ] : `var(--thumb-start-${
142
- position === 'vertical' ? 'height' : 'width'
143
- } )`,
144
- } ) ;
145
-
146
- const onAppearActive = ( ) => ( {
147
- transform : `translate${
148
- position === 'vertical' ? 'Y' : 'X'
149
- } (var(--thumb-active-${ position === 'vertical' ? 'top' : 'left' } ))`,
150
- [ position === 'vertical' ? 'height' : 'width' ] : `var(--thumb-active-${
151
- position === 'vertical' ? 'height' : 'width'
152
- } )`,
153
- } ) ;
141
+ const onAppearStart = ( ) =>
142
+ mode === 'vertical'
143
+ ? {
144
+ transform : 'translateY(var(--thumb-start-top))' ,
145
+ height : 'var(--thumb-start-height)' ,
146
+ }
147
+ : {
148
+ transform : 'translateX(var(--thumb-start-left))' ,
149
+ width : 'var(--thumb-start-width)' ,
150
+ } ;
151
+
152
+ const onAppearActive = ( ) =>
153
+ mode === 'vertical'
154
+ ? {
155
+ transform : 'translateY(var(--thumb-active-top))' ,
156
+ height : 'var(--thumb-active-height)' ,
157
+ }
158
+ : {
159
+ transform : 'translateX(var(--thumb-active-left))' ,
160
+ width : 'var(--thumb-active-width)' ,
161
+ } ;
154
162
155
163
const onVisibleChanged = ( ) => {
156
164
setPrevStyle ( null ) ;
@@ -187,11 +195,7 @@ export default function MotionThumb(props: MotionThumbInterface) {
187
195
const motionProps = {
188
196
ref : composeRef ( thumbRef , ref ) ,
189
197
style : mergedStyle ,
190
- className : classNames (
191
- `${ prefixCls } -thumb` ,
192
- `${ prefixCls } -${ position } -thumb` ,
193
- motionClassName ,
194
- ) ,
198
+ className : classNames ( `${ prefixCls } -thumb` , motionClassName ) ,
195
199
} ;
196
200
197
201
if ( process . env . NODE_ENV === 'test' ) {
0 commit comments