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-ui][joy-ui] Remove warning from getInitColorSchemeScript #42838

Merged
merged 7 commits into from
Jul 5, 2024
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
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;
Copy link
Member

Choose a reason for hiding this comment

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

I've added redeclaration to improve the jsdoc, because it doesn't work well when added to reexport:

Before After
Screenshot 2024-07-05 at 11 53 58 Screenshot 2024-07-05 at 11 53 26


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 };
Loading