Skip to content

Commit

Permalink
Update markdownDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidphamntq committed Sep 20, 2023
1 parent 69c035e commit f7913d9
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions docs/src/modules/components/MarkdownDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import PropTypes from 'prop-types';
import { useRouter } from 'next/router';
import { useTheme } from '@mui/system';
import { exactProp } from '@mui/utils';
import { CssVarsProvider as JoyCssVarsProvider, useColorScheme } from '@mui/joy/styles';
import {
CssVarsProvider as JoyCssVarsProvider,
useColorScheme as useJoyColorScheme,
} from '@mui/joy/styles';
import {
Experimental_CssVarsProvider as MuiCssVarsProvider,
useColorScheme as useMuiColorScheme,
} from '@mui/material/styles';
import RichMarkdownElement from 'docs/src/modules/components/RichMarkdownElement';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import AppLayoutDocs from 'docs/src/modules/components/AppLayoutDocs';
Expand All @@ -12,16 +19,17 @@ import BrandingProvider from 'docs/src/BrandingProvider';
import Ad from 'docs/src/modules/components/Ad';
import AdGuest from 'docs/src/modules/components/AdGuest';

function JoyModeObserver({ mode }) {
function ModeObserver({ mode, useColorScheme }) {
const { setMode } = useColorScheme();
React.useEffect(() => {
setMode(mode);
}, [mode, setMode]);
return null;
}

JoyModeObserver.propTypes = {
ModeObserver.propTypes = {
mode: PropTypes.oneOf(['light', 'dark']),
useColorScheme: PropTypes.func,
};

export default function MarkdownDocs(props) {
Expand All @@ -46,10 +54,22 @@ export default function MarkdownDocs(props) {
const localizedDoc = docs[userLanguage] || docs.en;

const isJoy = canonicalAs.startsWith('/joy-ui/') && !disableCssVarsProvider;
const CssVarsProvider = isJoy ? JoyCssVarsProvider : React.Fragment;
const Wrapper = isJoy ? BrandingProvider : React.Fragment;
const isMui = canonicalAs.startsWith('/material-ui/') && !disableCssVarsProvider;
let CssVarsProvider = React.Fragment;
let useColorScheme;
if (isJoy) {
CssVarsProvider = JoyCssVarsProvider;
useColorScheme = useJoyColorScheme;
}

if (isMui) {
CssVarsProvider = MuiCssVarsProvider;
useColorScheme = useMuiColorScheme;
}

const Wrapper = isJoy || isMui ? BrandingProvider : React.Fragment;
const wrapperProps = {
...(isJoy && { mode: theme.palette.mode }),
...((isJoy || isMui) && { mode: theme.palette.mode }),
};

return (
Expand All @@ -69,7 +89,9 @@ export default function MarkdownDocs(props) {
</BrandingProvider>
)}
<CssVarsProvider>
{isJoy && <JoyModeObserver mode={theme.palette.mode} />}
{(isJoy || isMui) && (
<ModeObserver mode={theme.palette.mode} useColorScheme={useColorScheme} />
)}
{localizedDoc.rendered.map((renderedMarkdownOrDemo, index) => (
<RichMarkdownElement
key={`demos-section-${index}`}
Expand Down

0 comments on commit f7913d9

Please sign in to comment.