From 721b285db4662de5c33e139c4b4cc4d63ae90019 Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:13:41 +0100 Subject: [PATCH] [charts] Flatten imports from `@mui/utils` and `@mui/system` (#15603) Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Co-authored-by: Lukas Tyla --- .eslintrc.js | 23 ++++++++++--------- .../src/BarChartPro/BarChartPro.tsx | 3 +-- .../ChartContainerPro/ChartContainerPro.tsx | 2 +- .../src/Heatmap/heatmapClasses.ts | 6 ++--- .../src/LineChartPro/LineChartPro.tsx | 2 +- .../createAxisFilterMapper.ts | 3 ++- .../src/internals/utils/releaseInfo.ts | 2 +- .../x-charts/src/ChartsAxis/axisClasses.ts | 6 ++--- .../src/ChartsLegend/chartsLegendClasses.ts | 6 ++--- .../src/ChartsTooltip/ChartsTooltipTable.ts | 2 +- packages/x-charts/src/models/axis.ts | 2 +- 11 files changed, 26 insertions(+), 31 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index cc528a710906..fac05b6d0e35 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -59,21 +59,22 @@ const RESTRICTED_TOP_LEVEL_IMPORTS = [ const buildPackageRestrictedImports = (packageName, root, allowRootImports = true) => [ { files: [`packages/${root}/src/**/*{.ts,.tsx,.js}`], - excludedFiles: ['*.d.ts', '*.spec.ts', '*.spec.tsx', '**.test.tx', '**.test.tsx'], + excludedFiles: [ + '*.d.ts', + '*.spec.ts', + '*.spec.tsx', + '**.test.tx', + '**.test.tsx', + `packages/${root}/src/index{.ts,.tsx,.js}`, + ], rules: { 'no-restricted-imports': [ 'error', { - paths: [ - { - name: packageName, - message: 'Use relative import instead', - }, - { - name: '@mui/material', - message: 'Use @mui/utils or a more specific import instead', - }, - ], + paths: RESTRICTED_TOP_LEVEL_IMPORTS.map((pkName) => ({ + name: pkName, + message: 'Use relative import instead', + })), patterns: [ // TODO move rule into main repo to allow deep @mui/monorepo imports { diff --git a/packages/x-charts-pro/src/BarChartPro/BarChartPro.tsx b/packages/x-charts-pro/src/BarChartPro/BarChartPro.tsx index 5508b75db439..2c08c454d575 100644 --- a/packages/x-charts-pro/src/BarChartPro/BarChartPro.tsx +++ b/packages/x-charts-pro/src/BarChartPro/BarChartPro.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import { useThemeProps } from '@mui/material/styles'; -import { BarChartProps, BarPlot } from '@mui/x-charts/BarChart'; +import { BarPlotProps, BarChartProps, BarPlot } from '@mui/x-charts/BarChart'; import { ChartsOnAxisClickHandler } from '@mui/x-charts/ChartsOnAxisClickHandler'; import { ChartsGrid } from '@mui/x-charts/ChartsGrid'; import { ChartsOverlay } from '@mui/x-charts/ChartsOverlay'; @@ -12,7 +12,6 @@ import { ChartsAxisHighlight } from '@mui/x-charts/ChartsAxisHighlight'; import { ChartsTooltip } from '@mui/x-charts/ChartsTooltip'; import { ChartsClipPath } from '@mui/x-charts/ChartsClipPath'; import { useBarChartProps } from '@mui/x-charts/internals'; -import { BarPlotProps } from '@mui/x-charts'; import { ChartContainerPro } from '../ChartContainerPro'; import { ZoomSetup } from '../context/ZoomProvider/ZoomSetup'; import { useZoom } from '../context/ZoomProvider/useZoom'; diff --git a/packages/x-charts-pro/src/ChartContainerPro/ChartContainerPro.tsx b/packages/x-charts-pro/src/ChartContainerPro/ChartContainerPro.tsx index 4b77a752926a..4c0d9f6dcaa0 100644 --- a/packages/x-charts-pro/src/ChartContainerPro/ChartContainerPro.tsx +++ b/packages/x-charts-pro/src/ChartContainerPro/ChartContainerPro.tsx @@ -5,7 +5,7 @@ import type {} from '../typeOverloads'; import { Watermark } from '@mui/x-license/Watermark'; import { ChartContainerProps } from '@mui/x-charts/ChartContainer'; import { ResizableContainer } from '@mui/x-charts/internals'; -import { ChartsSurface } from '@mui/x-charts'; +import { ChartsSurface } from '@mui/x-charts/ChartsSurface'; import { getReleaseInfo } from '../internals/utils/releaseInfo'; import { ChartDataProviderPro } from '../context/ChartDataProviderPro'; import { ZoomProps } from '../context/ZoomProvider'; diff --git a/packages/x-charts-pro/src/Heatmap/heatmapClasses.ts b/packages/x-charts-pro/src/Heatmap/heatmapClasses.ts index 2f50b4bdfa59..7e6c7898c722 100644 --- a/packages/x-charts-pro/src/Heatmap/heatmapClasses.ts +++ b/packages/x-charts-pro/src/Heatmap/heatmapClasses.ts @@ -1,7 +1,5 @@ -import { - unstable_generateUtilityClass as generateUtilityClass, - unstable_generateUtilityClasses as generateUtilityClasses, -} from '@mui/utils'; +import generateUtilityClass from '@mui/utils/generateUtilityClass'; +import generateUtilityClasses from '@mui/utils/generateUtilityClasses'; export interface HeatmapClasses { /** Styles applied to the heatmap cells. */ diff --git a/packages/x-charts-pro/src/LineChartPro/LineChartPro.tsx b/packages/x-charts-pro/src/LineChartPro/LineChartPro.tsx index e9dec5d30cca..82b9a6d5c5bc 100644 --- a/packages/x-charts-pro/src/LineChartPro/LineChartPro.tsx +++ b/packages/x-charts-pro/src/LineChartPro/LineChartPro.tsx @@ -10,6 +10,7 @@ import { LinePlot, LinePlotProps, MarkPlot, + MarkPlotProps, } from '@mui/x-charts/LineChart'; import { ChartsOnAxisClickHandler } from '@mui/x-charts/ChartsOnAxisClickHandler'; import { ChartsGrid } from '@mui/x-charts/ChartsGrid'; @@ -20,7 +21,6 @@ import { ChartsLegend } from '@mui/x-charts/ChartsLegend'; import { ChartsTooltip } from '@mui/x-charts/ChartsTooltip'; import { ChartsClipPath } from '@mui/x-charts/ChartsClipPath'; import { useLineChartProps } from '@mui/x-charts/internals'; -import { MarkPlotProps } from '@mui/x-charts'; import { ChartContainerPro } from '../ChartContainerPro'; import { ZoomSetup } from '../context/ZoomProvider/ZoomSetup'; import { useZoom } from '../context/ZoomProvider/useZoom'; diff --git a/packages/x-charts-pro/src/context/CartesianProviderPro/createAxisFilterMapper.ts b/packages/x-charts-pro/src/context/CartesianProviderPro/createAxisFilterMapper.ts index cbb0638bed59..43a65e76688b 100644 --- a/packages/x-charts-pro/src/context/CartesianProviderPro/createAxisFilterMapper.ts +++ b/packages/x-charts-pro/src/context/CartesianProviderPro/createAxisFilterMapper.ts @@ -8,7 +8,8 @@ import { isDefined, getScale, } from '@mui/x-charts/internals'; -import { ChartsAxisProps, ScaleName, AxisConfig } from '@mui/x-charts'; +import { ScaleName, AxisConfig } from '@mui/x-charts/models'; +import { ChartsAxisProps } from '@mui/x-charts/ChartsAxis'; import { ZoomData } from '../ZoomProvider'; type CreateAxisFilterMapperParams = { diff --git a/packages/x-charts-pro/src/internals/utils/releaseInfo.ts b/packages/x-charts-pro/src/internals/utils/releaseInfo.ts index 2830a4fd656a..7c6e262f74e2 100644 --- a/packages/x-charts-pro/src/internals/utils/releaseInfo.ts +++ b/packages/x-charts-pro/src/internals/utils/releaseInfo.ts @@ -1,4 +1,4 @@ -import { ponyfillGlobal } from '@mui/utils'; +import ponyfillGlobal from '@mui/utils/ponyfillGlobal'; export const getReleaseInfo = () => { const releaseInfo = '__RELEASE_INFO__'; diff --git a/packages/x-charts/src/ChartsAxis/axisClasses.ts b/packages/x-charts/src/ChartsAxis/axisClasses.ts index 5f04fafe0583..a99e8dbd2aef 100644 --- a/packages/x-charts/src/ChartsAxis/axisClasses.ts +++ b/packages/x-charts/src/ChartsAxis/axisClasses.ts @@ -1,7 +1,5 @@ -import { - unstable_generateUtilityClass as generateUtilityClass, - unstable_generateUtilityClasses as generateUtilityClasses, -} from '@mui/utils'; +import generateUtilityClass from '@mui/utils/generateUtilityClass'; +import generateUtilityClasses from '@mui/utils/generateUtilityClasses'; export interface ChartsAxisClasses { /** Styles applied to the root element. */ diff --git a/packages/x-charts/src/ChartsLegend/chartsLegendClasses.ts b/packages/x-charts/src/ChartsLegend/chartsLegendClasses.ts index 3ec9664ff4a5..7539c5caf6ac 100644 --- a/packages/x-charts/src/ChartsLegend/chartsLegendClasses.ts +++ b/packages/x-charts/src/ChartsLegend/chartsLegendClasses.ts @@ -1,7 +1,5 @@ -import { - unstable_generateUtilityClass as generateUtilityClass, - unstable_generateUtilityClasses as generateUtilityClasses, -} from '@mui/utils'; +import generateUtilityClass from '@mui/utils/generateUtilityClass'; +import generateUtilityClasses from '@mui/utils/generateUtilityClasses'; export interface ChartsLegendClasses { /** Styles applied to the root element. */ diff --git a/packages/x-charts/src/ChartsTooltip/ChartsTooltipTable.ts b/packages/x-charts/src/ChartsTooltip/ChartsTooltipTable.ts index a50e1c462c51..6512e1bf6753 100644 --- a/packages/x-charts/src/ChartsTooltip/ChartsTooltipTable.ts +++ b/packages/x-charts/src/ChartsTooltip/ChartsTooltipTable.ts @@ -1,5 +1,5 @@ import { styled } from '@mui/material/styles'; -import { shouldForwardProp } from '@mui/system'; +import { shouldForwardProp } from '@mui/system/createStyled'; import { chartsTooltipClasses } from './chartsTooltipClasses'; /** diff --git a/packages/x-charts/src/models/axis.ts b/packages/x-charts/src/models/axis.ts index c4114b0c7822..b8394900048e 100644 --- a/packages/x-charts/src/models/axis.ts +++ b/packages/x-charts/src/models/axis.ts @@ -9,7 +9,7 @@ import type { ScaleSequential, ScaleThreshold, } from '@mui/x-charts-vendor/d3-scale'; -import { SxProps } from '@mui/system'; +import { SxProps } from '@mui/system/styleFunctionSx'; import { ChartsAxisClasses } from '../ChartsAxis/axisClasses'; import type { TickParams } from '../hooks/useTicks'; import { ChartsTextProps } from '../ChartsText';