@@ -18,21 +18,37 @@ import {
18
18
import { styled } from '@mui/material/styles' ;
19
19
import { useXAxes , useYAxes } from '@mui/x-charts/hooks' ;
20
20
import { rafThrottle } from '@mui/x-internals/rafThrottle' ;
21
+ import { shouldForwardProp } from '@mui/system' ;
21
22
import { ChartsTooltipZoomSliderValue } from './ChartsTooltipZoomSliderValue' ;
22
23
import {
23
24
selectorChartAxisZoomData ,
24
25
UseChartProZoomSignature ,
25
26
} from '../../internals/plugins/useChartProZoom' ;
26
27
import { ChartAxisZoomSliderThumb } from './ChartAxisZoomSliderThumb' ;
27
28
28
- const ZoomSliderTrack = styled ( 'rect' ) ( ( { theme } ) => ( {
29
- '&' : {
30
- fill :
31
- theme . palette . mode === 'dark'
32
- ? ( theme . vars || theme ) . palette . grey [ 800 ]
33
- : ( theme . vars || theme ) . palette . grey [ 300 ] ,
34
- cursor : 'crosshair' ,
35
- } ,
29
+ const ZoomSliderTrack = styled ( 'rect' , {
30
+ shouldForwardProp : ( prop ) =>
31
+ shouldForwardProp ( prop ) && prop !== 'axisDirection' && prop !== 'isSelecting' ,
32
+ } ) < { axisDirection : 'x' | 'y' ; isSelecting : boolean } > ( ( { theme } ) => ( {
33
+ fill :
34
+ theme . palette . mode === 'dark'
35
+ ? ( theme . vars || theme ) . palette . grey [ 800 ]
36
+ : ( theme . vars || theme ) . palette . grey [ 300 ] ,
37
+ cursor : 'pointer' ,
38
+ variants : [
39
+ {
40
+ props : { axisDirection : 'x' , isSelecting : true } ,
41
+ style : {
42
+ cursor : 'ew-resize' ,
43
+ } ,
44
+ } ,
45
+ {
46
+ props : { axisDirection : 'y' , isSelecting : true } ,
47
+ style : {
48
+ cursor : 'ns-resize' ,
49
+ } ,
50
+ } ,
51
+ ] ,
36
52
} ) ) ;
37
53
38
54
const ZoomSliderActiveTrackRect = styled ( 'rect' ) ( ( { theme } ) => ( {
@@ -162,6 +178,7 @@ function ChartAxisZoomSliderTrack({
162
178
const ref = React . useRef < SVGRectElement > ( null ) ;
163
179
const { instance, svgRef } = useChartContext < [ UseChartProZoomSignature ] > ( ) ;
164
180
const store = useStore < [ UseChartProZoomSignature ] > ( ) ;
181
+ const [ isSelecting , setIsSelecting ] = React . useState ( false ) ;
165
182
166
183
const onPointerDown = function onPointerDown ( event : React . PointerEvent < SVGRectElement > ) {
167
184
const rect = ref . current ;
@@ -241,6 +258,7 @@ function ChartAxisZoomSliderTrack({
241
258
rect . releasePointerCapture ( pointerUpEvent . pointerId ) ;
242
259
rect . removeEventListener ( 'pointermove' , onPointerMove ) ;
243
260
document . removeEventListener ( 'pointerup' , onPointerUp ) ;
261
+ setIsSelecting ( false ) ;
244
262
245
263
if ( pointerMoved ) {
246
264
return ;
@@ -271,14 +289,23 @@ function ChartAxisZoomSliderTrack({
271
289
document . addEventListener ( 'pointerup' , onPointerUp ) ;
272
290
rect . addEventListener ( 'pointermove' , onPointerMove ) ;
273
291
292
+ setIsSelecting ( true ) ;
274
293
instance . setAxisZoomData ( axisId , ( prev ) => ( {
275
294
...prev ,
276
295
start : zoomFromPointerDown ,
277
296
end : zoomFromPointerDown ,
278
297
} ) ) ;
279
298
} ;
280
299
281
- return < ZoomSliderTrack ref = { ref } onPointerDown = { onPointerDown } { ...other } /> ;
300
+ return (
301
+ < ZoomSliderTrack
302
+ ref = { ref }
303
+ onPointerDown = { onPointerDown }
304
+ axisDirection = { axisDirection }
305
+ isSelecting = { isSelecting }
306
+ { ...other }
307
+ />
308
+ ) ;
282
309
}
283
310
284
311
const formatter = Intl . NumberFormat ( undefined , { maximumFractionDigits : 0 } ) ;
0 commit comments