Skip to content

Commit ab8104b

Browse files
Refactor
1 parent 1054b1d commit ab8104b

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed

packages/x-charts-pro/src/ChartZoomSlider/internals/ChartAxisZoomSlider.tsx

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { styled } from '@mui/material/styles';
1717
import { useXAxes, useYAxes } from '@mui/x-charts/hooks';
1818
import { rafThrottle } from '@mui/x-internals/rafThrottle';
19-
import { ChartsZoomValueTooltip } from './ChartsZoomValueTooltip';
19+
import { ChartsTooltipZoomSliderValue } from './ChartsTooltipZoomSliderValue';
2020
import {
2121
selectorChartAxisZoomData,
2222
UseChartProZoomSignature,
@@ -82,7 +82,7 @@ export function ChartAxisZoomSlider({ axisDirection, axisId }: ChartZoomSliderPr
8282
let x: number;
8383
let y: number;
8484
let reverse: boolean;
85-
let position: 'top' | 'bottom' | 'left' | 'right';
85+
let axisPosition: 'top' | 'bottom' | 'left' | 'right';
8686

8787
if (axisDirection === 'x') {
8888
const axis = xAxis[axisId];
@@ -99,7 +99,7 @@ export function ChartAxisZoomSlider({ axisDirection, axisId }: ChartZoomSliderPr
9999
? drawingArea.top + drawingArea.height + axis.offset + axisSize + ZOOM_SLIDER_MARGIN
100100
: drawingArea.top - axis.offset - axisSize - ZOOM_SLIDER_SIZE - ZOOM_SLIDER_MARGIN;
101101
reverse = axis.reverse ?? false;
102-
position = axis.position ?? 'bottom';
102+
axisPosition = axis.position ?? 'bottom';
103103
} else {
104104
const axis = yAxis[axisId];
105105

@@ -115,7 +115,7 @@ export function ChartAxisZoomSlider({ axisDirection, axisId }: ChartZoomSliderPr
115115
: drawingArea.left - axis.offset - axisSize - ZOOM_SLIDER_SIZE - ZOOM_SLIDER_MARGIN;
116116
y = drawingArea.top;
117117
reverse = axis.reverse ?? false;
118-
position = axis.position ?? 'left';
118+
axisPosition = axis.position ?? 'left';
119119
}
120120

121121
const backgroundRectOffset = (ZOOM_SLIDER_SIZE - ZOOM_SLIDER_BACKGROUND_SIZE) / 2;
@@ -133,7 +133,7 @@ export function ChartAxisZoomSlider({ axisDirection, axisId }: ChartZoomSliderPr
133133
<ChartAxisZoomSliderSpan
134134
zoomData={zoomData}
135135
axisId={axisId}
136-
position={position}
136+
axisPosition={axisPosition}
137137
axisDirection={axisDirection}
138138
reverse={reverse}
139139
/>
@@ -147,14 +147,14 @@ const zoomValueFormatter = (value: number) => formatter.format(value);
147147
function ChartAxisZoomSliderSpan({
148148
axisId,
149149
axisDirection,
150-
position,
150+
axisPosition,
151151
zoomData,
152152
reverse,
153153
valueFormatter = zoomValueFormatter,
154154
}: {
155155
axisId: AxisId;
156156
axisDirection: 'x' | 'y';
157-
position: 'top' | 'bottom' | 'left' | 'right';
157+
axisPosition: 'top' | 'bottom' | 'left' | 'right';
158158
zoomData: ZoomData;
159159
reverse: boolean;
160160
valueFormatter?: (value: number) => string;
@@ -429,20 +429,20 @@ function ChartAxisZoomSliderSpan({
429429
onPointerLeave={() => setShowTooltip(null)}
430430
placement="end"
431431
/>
432-
<ChartsZoomValueTooltip
432+
<ChartsTooltipZoomSliderValue
433433
anchorEl={startHandleEl}
434434
open={showTooltip === 'start' || showTooltip === 'both'}
435-
placement={position}
435+
placement={axisPosition}
436436
>
437437
{valueFormatter(zoomData.start)}
438-
</ChartsZoomValueTooltip>
439-
<ChartsZoomValueTooltip
438+
</ChartsTooltipZoomSliderValue>
439+
<ChartsTooltipZoomSliderValue
440440
anchorEl={endHandleEl}
441441
open={showTooltip === 'end' || showTooltip === 'both'}
442-
placement={position}
442+
placement={axisPosition}
443443
>
444444
{valueFormatter(zoomData.end)}
445-
</ChartsZoomValueTooltip>
445+
</ChartsTooltipZoomSliderValue>
446446
</React.Fragment>
447447
);
448448
}

packages/x-charts-pro/src/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { styled } from '@mui/material/styles';
55
import useForkRef from '@mui/utils/useForkRef';
66
import useEventCallback from '@mui/utils/useEventCallback';
77
import { rafThrottle } from '@mui/x-internals/rafThrottle';
8+
import clsx from 'clsx';
89
import {
910
chartAxisZoomSliderHandleClasses,
1011
useUtilityClasses,
@@ -47,7 +48,7 @@ export const ChartAxisZoomSliderHandle = React.forwardRef<
4748
SVGRectElement,
4849
ChartZoomSliderHandleProps
4950
>(function ChartPreviewHandle(
50-
{ onMove, orientation, placement, rx = 4, ry = 4, ...rest },
51+
{ className, onMove, orientation, placement, rx = 4, ry = 4, ...rest },
5152
forwardedRef,
5253
) {
5354
const classes = useUtilityClasses({ onMove, orientation, placement });
@@ -91,5 +92,5 @@ export const ChartAxisZoomSliderHandle = React.forwardRef<
9192
};
9293
}, [onMoveEvent, orientation]);
9394

94-
return <Rect className={classes.root} ref={ref} rx={rx} ry={ry} {...rest} />;
95+
return <Rect className={clsx(classes.root, className)} ref={ref} rx={rx} ry={ry} {...rest} />;
9596
});

packages/x-charts-pro/src/ChartZoomSlider/internals/ChartsZoomValueTooltip.tsx renamed to packages/x-charts-pro/src/ChartZoomSlider/internals/ChartsTooltipZoomSliderValue.tsx

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
11
import * as React from 'react';
22
import NoSsr from '@mui/material/NoSsr';
3-
import { styled } from '@mui/material/styles';
4-
import Popper, { PopperProps } from '@mui/material/Popper';
5-
import { ChartsTooltipPaper } from '@mui/x-charts/ChartsTooltip';
3+
import { PopperProps } from '@mui/material/Popper';
4+
import { ChartsTooltipPaper, ChartsTooltipRoot } from '@mui/x-charts/ChartsTooltip';
65
import Typography from '@mui/material/Typography';
76

8-
const ChartsTooltipRoot = styled(Popper, {
9-
name: 'MuiChartsTooltip',
10-
slot: 'Root',
11-
})(({ theme }) => ({
12-
pointerEvents: 'none',
13-
zIndex: theme.zIndex.modal,
14-
}));
15-
167
const MODIFIERS = [
178
{
189
name: 'offset',
19-
options: {
20-
offset: [0, 4],
21-
},
10+
options: { offset: [0, 4] },
2211
},
2312
];
2413

25-
interface ChartsZoomValueTooltipProps
14+
interface ChartsTooltipZoomSliderValueProps
2615
extends Pick<PopperProps, 'anchorEl' | 'open' | 'modifiers' | 'placement'>,
2716
React.PropsWithChildren {}
2817

29-
export function ChartsZoomValueTooltip({
18+
export function ChartsTooltipZoomSliderValue({
3019
anchorEl,
3120
open,
3221
placement,
3322
modifiers = MODIFIERS,
3423
children,
35-
}: ChartsZoomValueTooltipProps) {
24+
}: ChartsTooltipZoomSliderValueProps) {
3625
return (
3726
<NoSsr>
3827
{open ? (

packages/x-charts/src/ChartsTooltip/ChartsTooltipContainer.tsx

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import HTMLElementType from '@mui/utils/HTMLElementType';
55
import useLazyRef from '@mui/utils/useLazyRef';
6-
import { styled, useThemeProps } from '@mui/material/styles';
7-
import Popper, { PopperProps } from '@mui/material/Popper';
6+
import { useThemeProps } from '@mui/material/styles';
7+
import { PopperProps } from '@mui/material/Popper';
88
import NoSsr from '@mui/material/NoSsr';
9+
import { ChartsTooltipRoot } from './ChartsTooltipRoot';
910
import { useSvgRef } from '../hooks/useSvgRef';
1011
import { TriggerOptions, usePointerType } from './utils';
1112
import { ChartsTooltipClasses } from './chartsTooltipClasses';
@@ -37,14 +38,6 @@ export interface ChartsTooltipContainerProps extends Partial<PopperProps> {
3738
children?: React.ReactNode;
3839
}
3940

40-
const ChartsTooltipRoot = styled(Popper, {
41-
name: 'MuiChartsTooltip',
42-
slot: 'Root',
43-
})(({ theme }) => ({
44-
pointerEvents: 'none',
45-
zIndex: theme.zIndex.modal,
46-
}));
47-
4841
/**
4942
* Demos:
5043
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { styled } from '@mui/material/styles';
2+
import Popper from '@mui/material/Popper';
3+
4+
export const ChartsTooltipRoot = styled(Popper, {
5+
name: 'MuiChartsTooltip',
6+
slot: 'Root',
7+
})(({ theme }) => ({
8+
pointerEvents: 'none',
9+
zIndex: theme.zIndex.modal,
10+
}));

packages/x-charts/src/ChartsTooltip/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './ChartsTooltipContainer';
33
export type { ChartsTooltipClasses, ChartsTooltipClassKey } from './chartsTooltipClasses';
44
export { getChartsTooltipUtilityClass, chartsTooltipClasses } from './chartsTooltipClasses';
55

6+
export * from './ChartsTooltipRoot';
67
export * from './ChartsAxisTooltipContent';
78
export * from './ChartsItemTooltipContent';
89

0 commit comments

Comments
 (0)