Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import createEmotionCache from '@mui/docs/createEmotionCache';
import findActivePage from '@mui/docs/findActivePage';
import getProductInfoFromUrl from '@mui/docs/getProductInfoFromUrl';
import { mapTranslations } from '@mui/docs/i18n';
import { getTheme } from '@mui/docs/branding';
import materialPkgJson from '@mui/material/package.json';
import systemPkgJson from '@mui/system/package.json';
import { LicenseInfo } from '@mui/x-license';
Expand All @@ -29,7 +30,6 @@ import NextHead from 'next/head';
import { useRouter } from 'next/router';
import PropTypes from 'prop-types';
import * as React from 'react';

import * as config from '../config';
import '../public/static/components-gallery/base-theme.css';
import './global.css';
Expand Down Expand Up @@ -124,10 +124,12 @@ function loadDependencies() {
);
}

if (typeof window !== 'undefined' && process.env.NODE_ENV === 'production') {
// eslint-disable-next-line no-console
console.log(
`%c
if (typeof window !== 'undefined') {
window.theme = getTheme();
if (process.env.NODE_ENV === 'production') {
// eslint-disable-next-line no-console
console.log(
`%c

███╗ ███╗ ██╗ ██╗ ██████╗
████╗ ████║ ██║ ██║ ██╔═╝
Expand All @@ -138,8 +140,9 @@ if (typeof window !== 'undefined' && process.env.NODE_ENV === 'production') {

Tip: you can access the documentation \`theme\` object directly in the console.
`,
'font-family:monospace;color:#1976d2;font-size:12px;',
);
'font-family:monospace;color:#1976d2;font-size:12px;',
);
}
}

/**
Expand Down
10 changes: 8 additions & 2 deletions packages/mui-docs/src/branding/BrandingCssVarsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function resetDocsSpacing() {
}

const themeCache: Map<string, ReturnType<typeof createTheme>> = new Map();
function getTheme(direction: 'ltr' | 'rtl') {
export function getTheme(direction: 'ltr' | 'rtl') {
let cachedTheme = themeCache.get(direction);
if (!cachedTheme) {
cachedTheme = createTheme({
Expand All @@ -131,11 +131,17 @@ function getTheme(direction: 'ltr' | 'rtl') {
return cachedTheme!;
}

interface BrandingCssThemeProviderProps {
children: React.ReactNode;
direction?: 'ltr' | 'rtl';
forceThemeRerender?: boolean;
}

export function BrandingCssThemeProvider({
children,
direction = 'ltr',
forceThemeRerender = false,
}: React.PropsWithChildren<{ direction?: 'ltr' | 'rtl'; forceThemeRerender?: boolean }>) {
}: BrandingCssThemeProviderProps) {
const theme = React.useMemo(() => getTheme(direction), [direction]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal but while resolving the conflicts, I realised that the window.theme will not update when the value of direction changes. Should not be an issue since only the value of theme.direction changes, not the palette colors.

return (
<ThemeProvider
Expand Down
Loading