11import { useFluent , useEventCallback } from '@fluentui/react-components' ;
2-
3- import type { EventHandler } from '@fluentui/react-utilities' ;
42import {
53 getEventClientCoords ,
6- NativeTouchOrMouseEvent ,
74 isMouseEvent ,
85 isTouchEvent ,
6+ type NativeTouchOrMouseEvent ,
7+ type EventHandler ,
98} from '@fluentui/react-utilities' ;
109import * as React from 'react' ;
10+
1111import { EVENTS , GrowDirection , ResizeHandleUpdateEventData } from '../types' ;
12+ import type { UnitHandle } from './useUnitHandle' ;
1213
1314export type UseMouseHandlerParams = {
1415 growDirection : GrowDirection ;
1516 onValueChange : EventHandler < ResizeHandleUpdateEventData > ;
1617 onDragEnd ?: EventHandler < Omit < ResizeHandleUpdateEventData , 'value' > > ;
1718 onDragStart ?: EventHandler < Omit < ResizeHandleUpdateEventData , 'value' > > ;
19+
1820 getCurrentValue : ( ) => number ;
21+ unitHandle : UnitHandle ;
1922} ;
2023
2124export function useMouseHandler ( params : UseMouseHandlerParams ) {
2225 const { targetDocument, dir } = useFluent ( ) ;
2326 const targetWindow = targetDocument ?. defaultView ;
2427
2528 const dragStartOriginCoords = React . useRef ( { clientX : 0 , clientY : 0 } ) ;
26- const { growDirection, onValueChange, getCurrentValue } = params ;
29+ const { growDirection, getCurrentValue , onValueChange, unitHandle } = params ;
2730
2831 const startValue = React . useRef ( 0 ) ;
2932
@@ -39,21 +42,26 @@ export function useMouseHandler(params: UseMouseHandlerParams) {
3942
4043 switch ( growDirection ) {
4144 case 'end' :
42- newValue += deltaCoords [ 0 ] * ( dir === 'rtl' ? - 1 : 1 ) ;
45+ newValue += unitHandle . fromPxToValue (
46+ deltaCoords [ 0 ] * ( dir === 'rtl' ? - 1 : 1 )
47+ ) ;
4348 break ;
4449 case 'start' :
45- newValue -= deltaCoords [ 0 ] * ( dir === 'rtl' ? - 1 : 1 ) ;
50+ newValue -= unitHandle . fromPxToValue (
51+ deltaCoords [ 0 ] * ( dir === 'rtl' ? - 1 : 1 )
52+ ) ;
4653 break ;
4754 case 'up' :
48- newValue -= deltaCoords [ 1 ] ;
55+ newValue -= unitHandle . fromPxToValue ( deltaCoords [ 1 ] ) ;
4956 break ;
5057 case 'down' :
51- newValue += deltaCoords [ 1 ] ;
58+ newValue += unitHandle . fromPxToValue ( deltaCoords [ 1 ] ) ;
5259 break ;
5360 }
5461
5562 onValueChange ( event , {
56- value : Math . round ( newValue ) ,
63+ value : unitHandle . roundValue ( newValue ) ,
64+ unit : unitHandle . name ,
5765 ...( isTouchEvent ( event )
5866 ? { event, type : EVENTS . touch }
5967 : { event, type : EVENTS . mouse } ) ,
@@ -95,8 +103,8 @@ export function useMouseHandler(params: UseMouseHandlerParams) {
95103 params . onDragEnd ?.(
96104 event ,
97105 isTouchEvent ( event )
98- ? { event, type : EVENTS . touch }
99- : { event, type : EVENTS . mouse }
106+ ? { event, type : EVENTS . touch , unit : unitHandle . name }
107+ : { event, type : EVENTS . mouse , unit : unitHandle . name }
100108 ) ;
101109 } ) ;
102110
@@ -127,8 +135,8 @@ export function useMouseHandler(params: UseMouseHandlerParams) {
127135 params . onDragStart ?.(
128136 event ,
129137 isTouchEvent ( event )
130- ? { event, type : EVENTS . touch }
131- : { event, type : EVENTS . mouse }
138+ ? { event, type : EVENTS . touch , unit : unitHandle . name }
139+ : { event, type : EVENTS . mouse , unit : unitHandle . name }
132140 ) ;
133141 } ) ;
134142
0 commit comments