pcm-shared-components 2.1.108 → 2.1.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
2
|
import { createTheme, useTheme, ThemeProvider } from "@mui/material/styles";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Used to bridge the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Used to bridge the gap between MUI4 currently used in the app and MUI5 used in this library.
|
|
6
|
+
* Wrapping the app with this component makes the MUI5 ThemeProvider inherit the existing theme.
|
|
8
7
|
*/
|
|
9
8
|
export const PcSharedComponentThemeInheritor = props => {
|
|
10
9
|
const {
|
|
11
10
|
theme,
|
|
12
|
-
children
|
|
11
|
+
children
|
|
13
12
|
} = props;
|
|
14
|
-
|
|
13
|
+
|
|
14
|
+
// MUI5 theme from the parent (MUI4 theme adapter or MUI5 provider)
|
|
15
|
+
const outerTheme = useTheme();
|
|
16
|
+
|
|
17
|
+
// Build final theme once per change
|
|
18
|
+
const mergedTheme = useMemo(() => createTheme(theme || outerTheme), [theme, outerTheme]);
|
|
15
19
|
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
16
|
-
theme:
|
|
20
|
+
theme: mergedTheme
|
|
17
21
|
}, children);
|
|
18
22
|
};
|
|
19
23
|
export default PcSharedComponentThemeInheritor;
|