Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Material You] Use md as a CSS var prefix #36177

Merged
merged 3 commits into from
Feb 14, 2023
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
10 changes: 5 additions & 5 deletions docs/src/modules/components/MaterialYouUsageDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export const prependLinesSpace = (code: string, size: number = 2) => {
return newCode.join('\n');
};

function ModeSwitcher({ md2Mode }: { md2Mode: Mode | undefined }) {
const { mode, setMode } = useColorScheme();
if (md2Mode && mode !== md2Mode) {
setMode(md2Mode ?? mode);
Copy link
Member Author

Choose a reason for hiding this comment

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

I found that this line setState at the render phase which is not allowed in React.

}
function ModeSwitcher({ md2Mode }: { md2Mode: Mode }) {
const { setMode } = useColorScheme();
React.useEffect(() => {
setMode(md2Mode);
}, [md2Mode, setMode]);
return null;
}

Expand Down
14 changes: 14 additions & 0 deletions packages/mui-material-next/src/styles/extendTheme.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect } from 'chai';
import { extendTheme } from '@mui/material-next/styles';

describe('Material You — extendTheme', () => {
it('should have default cssVarPrefix', () => {
expect(extendTheme().cssVarPrefix).to.equal('md');
});

it('`getCssVar` return default prefix', () => {
expect(extendTheme().getCssVar('palette-primary-main')).to.equal(
'var(--md-palette-primary-main)',
);
});
});
4 changes: 2 additions & 2 deletions packages/mui-material-next/src/styles/extendTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ function setColor(obj: any, key: string, defaultValue: any) {
obj[key] = obj[key] || defaultValue;
}

export const createGetCssVar = (cssVarPrefix = 'mui') => systemCreateGetCssVar(cssVarPrefix);
export const createGetCssVar = (cssVarPrefix = 'md') => systemCreateGetCssVar(cssVarPrefix);

export default function extendTheme(options: CssVarsThemeOptions = {}, ...args: any[]) {
const { colorSchemes: colorSchemesInput = {}, cssVarPrefix = 'mui', ...input } = options;
const { colorSchemes: colorSchemesInput = {}, cssVarPrefix = 'md', ...input } = options;
const getCssVar = createGetCssVar(cssVarPrefix);

const md3LightColors = createMd3LightColorScheme(getCssVar, md3CommonPalette);
Expand Down