Skip to content

Commit

Permalink
[material-ui][joy-ui] Remove warning from getInitColorSchemeScript (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Jul 5, 2024
1 parent a2972e8 commit 3f2aff4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
# fetch all tags which are required for `pnpm release:changelog`
fetch-depth: 0
- name: Set up pnpm
uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # v2.4.0
uses: pnpm/action-setup@v4
- name: Use Node.js 18.x
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
Expand Down
33 changes: 14 additions & 19 deletions packages/mui-joy/src/styles/CssVarsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { defaultConfig } from '../InitColorSchemeScript/InitColorSchemeScript';
const {
CssVarsProvider,
useColorScheme,
getInitColorSchemeScript: deprecatedGetInitColorSchemeScript,
getInitColorSchemeScript: getInitColorSchemeScriptSystem,
} = createCssVarsProvider<SupportedColorScheme, typeof THEME_ID>({
themeId: THEME_ID,
theme: defaultTheme,
Expand All @@ -25,22 +25,17 @@ const {
},
});

let warnedInitScriptOnce = false;
/**
* @deprecated use `InitColorSchemeScript` instead
*
* ```diff
* - import { getInitColorSchemeScript } from '@mui/joy/styles';
* + import InitColorSchemeScript from '@mui/joy/InitColorSchemeScript';
*
* - getInitColorSchemeScript();
* + <InitColorSchemeScript />;
* ```
*/
export const getInitColorSchemeScript = getInitColorSchemeScriptSystem;

const getInitColorSchemeScript: typeof deprecatedGetInitColorSchemeScript = (params) => {
if (!warnedInitScriptOnce) {
console.warn(
[
'MUI: The getInitColorSchemeScript function has been deprecated.',
'',
"You should use `import InitColorSchemeScript from '@mui/joy/InitColorSchemeScript'`",
'and replace the function call with `<InitColorSchemeScript />` instead.',
].join('\n'),
);

warnedInitScriptOnce = true;
}
return deprecatedGetInitColorSchemeScript(params);
};

export { CssVarsProvider, useColorScheme, getInitColorSchemeScript };
export { CssVarsProvider, useColorScheme };
39 changes: 14 additions & 25 deletions packages/mui-material/src/styles/CssVarsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultTheme = experimental_extendTheme();
const {
CssVarsProvider,
useColorScheme,
getInitColorSchemeScript: deprecatedGetInitColorSchemeScript,
getInitColorSchemeScript: getInitColorSchemeScriptSystem,
} = createCssVarsProvider<SupportedColorScheme, typeof THEME_ID>({
themeId: THEME_ID,
theme: defaultTheme,
Expand All @@ -45,27 +45,16 @@ const {
excludeVariablesFromRoot,
});

let warnedInitScriptOnce = false;

// TODO: remove in v7
const getInitColorSchemeScript: typeof deprecatedGetInitColorSchemeScript = (params) => {
if (!warnedInitScriptOnce) {
console.warn(
[
'MUI: The getInitColorSchemeScript function has been deprecated.',
'',
"You should use `import InitColorSchemeScript from '@mui/material/InitColorSchemeScript'`",
'and replace the function call with `<InitColorSchemeScript />` instead.',
].join('\n'),
);

warnedInitScriptOnce = true;
}
return deprecatedGetInitColorSchemeScript(params);
};

export {
useColorScheme,
getInitColorSchemeScript,
CssVarsProvider as Experimental_CssVarsProvider,
};
/**
* @deprecated Use `InitColorSchemeScript` instead
* ```diff
* - import { getInitColorSchemeScript } from '@mui/material/styles';
* + import InitColorSchemeScript from '@mui/material/InitColorSchemeScript';
*
* - getInitColorSchemeScript();
* + <InitColorSchemeScript />;
* ```
*/
export const getInitColorSchemeScript = getInitColorSchemeScriptSystem;

export { useColorScheme, CssVarsProvider as Experimental_CssVarsProvider };

0 comments on commit 3f2aff4

Please sign in to comment.