@@ -8,7 +8,7 @@ import { UpIcon } from './UpIcon';
88const StyledUpIcon = tasty ( UpIcon , {
99 styles : {
1010 transformOrigin : 'center' ,
11- transition : 'rotate linear 120ms, scale linear 120ms ' ,
11+ transition : 'rotate linear $transition, transform linear $transition ' ,
1212 } ,
1313} ) ;
1414
@@ -46,34 +46,25 @@ export const DirectionIcon = memo(function DirectionIcon(
4646 return ;
4747 }
4848
49- let appliedRotate = 0 ;
50- let nextFlipScale = flipScale ;
51-
5249 const lastRotate = rotationByDirection [ lastDirection ] ;
5350 const nextRotate = rotationByDirection [ direction ] ;
54- const diffRotate = nextRotate - lastRotate ;
55-
56- if ( Math . abs ( diffRotate ) % 360 !== 180 ) {
57- if ( nextRotate < lastRotate ) {
58- appliedRotate = 90 ;
59- } else {
60- appliedRotate = - 90 ;
61- }
62-
63- if ( Math . abs ( diffRotate ) !== 90 ) {
64- appliedRotate = - appliedRotate ;
65- }
51+ const diffRotate = lastRotate - nextRotate ;
52+ const angle = Math . abs ( diffRotate ) % 360 ;
6653
67- if ( flipScale ) {
68- appliedRotate = - appliedRotate ;
69- }
54+ if ( angle === 180 ) {
55+ // For 180° changes, flip instead of rotating
56+ setFlipScale ( ( prev ) => - prev ) ;
7057 } else {
71- nextFlipScale = - flipScale ;
58+ // Find shortest rotation path
59+ let shortestDiff = diffRotate ;
60+ if ( angle > 180 ) {
61+ // Wrap around: use the shorter path
62+ shortestDiff = diffRotate > 0 ? diffRotate - 360 : diffRotate + 360 ;
63+ }
64+ // Apply the shortest rotation path
65+ setRotate ( ( prev ) => prev - shortestDiff ) ;
7266 }
7367
74- setRotate ( rotate + appliedRotate ) ;
75- setFlipScale ( nextFlipScale ) ;
76-
7768 lastDirectionRef . current = direction ;
7869 } , [ direction ] ) ;
7970
@@ -83,7 +74,7 @@ export const DirectionIcon = memo(function DirectionIcon(
8374 { ...iconProps }
8475 style = { {
8576 rotate : `${ rotate } deg` ,
86- scale : `1 ${ flipScale } ` ,
77+ transform : `scaleY( ${ flipScale } ) ` ,
8778 } }
8879 />
8980 ) ;
0 commit comments