diff --git a/.eslintrc.js b/.eslintrc.js
index 1616404a6f..5c1012e501 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -28,6 +28,12 @@ module.exports = {
onNonMatchingHeader: 'replace',
},
],
+ 'no-restricted-imports': [
+ 'error',
+ {
+ patterns: ['@mui/*/*/*'],
+ },
+ ],
'no-restricted-syntax': [
'error',
{
diff --git a/packages/test-utils/src/testUtils/appWrappers.tsx b/packages/test-utils/src/testUtils/appWrappers.tsx
index 012cbe0b98..6545cc312a 100644
--- a/packages/test-utils/src/testUtils/appWrappers.tsx
+++ b/packages/test-utils/src/testUtils/appWrappers.tsx
@@ -18,7 +18,6 @@ import React, { ComponentType, ReactNode, ReactElement } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { Route } from 'react-router-dom';
import { UnifiedThemeProvider, themes } from '@backstage/theme';
-import { CssBaseline } from '@material-ui/core';
import MockIcon from '@material-ui/icons/AcUnit';
import { createSpecializedApp } from '@backstage/core-app-api';
import {
@@ -142,7 +141,7 @@ export function createTestAppWrapper(
variant: 'light',
Provider: ({ children }) => (
- {children}
+ {children}
),
},
diff --git a/packages/theme/src/unified/MuiClassNameSetup.ts b/packages/theme/src/unified/MuiClassNameSetup.ts
new file mode 100644
index 0000000000..42b948af32
--- /dev/null
+++ b/packages/theme/src/unified/MuiClassNameSetup.ts
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2022 The Backstage Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';
+
+/**
+ * This API is introduced in @mui/material (v5.0.5) as a replacement of deprecated createGenerateClassName & only affects v5 MUI components from `@mui/*`
+ */
+ClassNameGenerator.configure(componentName => {
+ return `v5-${componentName}`;
+});
diff --git a/packages/theme/src/unified/UnifiedThemeProvider.tsx b/packages/theme/src/unified/UnifiedThemeProvider.tsx
index 10277136e5..88cc1d9457 100644
--- a/packages/theme/src/unified/UnifiedThemeProvider.tsx
+++ b/packages/theme/src/unified/UnifiedThemeProvider.tsx
@@ -15,31 +15,16 @@
*/
import React, { ReactNode } from 'react';
-import {
- Theme as Mui4Theme,
- StylesProvider,
- ThemeProvider,
-} from '@material-ui/core/styles';
+import './MuiClassNameSetup';
+import { ThemeProvider } from '@material-ui/core/styles';
import {
StyledEngineProvider,
- Theme as Mui5Theme,
ThemeProvider as Mui5Provider,
} from '@mui/material/styles';
-import {
- StylesProvider as Mui5StylesProvider,
- createGenerateClassName,
-} from '@mui/styles';
import Mui5CssBaseline from '@mui/material/CssBaseline';
import { UnifiedTheme } from './types';
import { CssBaseline } from '@material-ui/core';
-const generateV4ClassName = createGenerateClassName({
- seed: 'm4',
-});
-const generateV5ClassName = createGenerateClassName({
- seed: 'm5',
-});
-
/**
* Props for {@link UnifiedThemeProvider}.
*
@@ -85,25 +70,14 @@ export function UnifiedThemeProvider(
);
if (v4Theme) {
- /* const styles = maybeLoadMui4Styles();
- if (!styles) {
- throw new Error('Failed to load MUI 4 styles package');
- }
- const { StylesProvider, ThemeProvider } = styles; */
- result = (
-
- {result}
-
- );
+ result = {result};
}
if (v5Theme) {
result = (
-
-
- {result}
-
-
+
+ {result}
+
);
}