From 3f2aff4e8d0249a2936b2130828c3db254aab7fd Mon Sep 17 00:00:00 2001 From: Siriwat K Date: Fri, 5 Jul 2024 17:58:58 +0700 Subject: [PATCH] [material-ui][joy-ui] Remove warning from `getInitColorSchemeScript` (#42838) --- .github/workflows/ci.yml | 2 +- .../mui-joy/src/styles/CssVarsProvider.tsx | 33 +++++++--------- .../src/styles/CssVarsProvider.tsx | 39 +++++++------------ 3 files changed, 29 insertions(+), 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24255495324d9b..4d885bf990425b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/packages/mui-joy/src/styles/CssVarsProvider.tsx b/packages/mui-joy/src/styles/CssVarsProvider.tsx index 2daeaa8dc1fece..6a607165d1e068 100644 --- a/packages/mui-joy/src/styles/CssVarsProvider.tsx +++ b/packages/mui-joy/src/styles/CssVarsProvider.tsx @@ -12,7 +12,7 @@ import { defaultConfig } from '../InitColorSchemeScript/InitColorSchemeScript'; const { CssVarsProvider, useColorScheme, - getInitColorSchemeScript: deprecatedGetInitColorSchemeScript, + getInitColorSchemeScript: getInitColorSchemeScriptSystem, } = createCssVarsProvider({ themeId: THEME_ID, theme: defaultTheme, @@ -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(); + * + ; + * ``` + */ +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 `` instead.', - ].join('\n'), - ); - - warnedInitScriptOnce = true; - } - return deprecatedGetInitColorSchemeScript(params); -}; - -export { CssVarsProvider, useColorScheme, getInitColorSchemeScript }; +export { CssVarsProvider, useColorScheme }; diff --git a/packages/mui-material/src/styles/CssVarsProvider.tsx b/packages/mui-material/src/styles/CssVarsProvider.tsx index 9824ae6e225d81..5378f7aa4a69cb 100644 --- a/packages/mui-material/src/styles/CssVarsProvider.tsx +++ b/packages/mui-material/src/styles/CssVarsProvider.tsx @@ -19,7 +19,7 @@ const defaultTheme = experimental_extendTheme(); const { CssVarsProvider, useColorScheme, - getInitColorSchemeScript: deprecatedGetInitColorSchemeScript, + getInitColorSchemeScript: getInitColorSchemeScriptSystem, } = createCssVarsProvider({ themeId: THEME_ID, theme: defaultTheme, @@ -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 `` 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(); + * + ; + * ``` + */ +export const getInitColorSchemeScript = getInitColorSchemeScriptSystem; + +export { useColorScheme, CssVarsProvider as Experimental_CssVarsProvider };