From aac5ed807c4eb944ae717323a0652a3d5a1bd756 Mon Sep 17 00:00:00 2001 From: money Date: Tue, 7 Nov 2023 06:18:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugins):=20=E8=BF=90=E8=A1=8C=E6=97=B6=20?= =?UTF-8?q?styled=20components=20=E6=94=AF=E6=8C=81=20function=20(#11304)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(plugins): 运行时 styled components 支持 function * docs: 修改文档 * docs(SC): use object config --------- Co-authored-by: fz6m <59400654+fz6m@users.noreply.github.com> --- docs/docs/docs/max/styled-components.md | 2 +- packages/plugins/src/styled-components.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/docs/docs/max/styled-components.md b/docs/docs/docs/max/styled-components.md index 0bb77889390c..a37cb5dda7af 100644 --- a/docs/docs/docs/max/styled-components.md +++ b/docs/docs/docs/max/styled-components.md @@ -64,7 +64,7 @@ export default { 比如: ```ts -import {createGlobalStyle} from "umi"; +import { createGlobalStyle } from "umi"; export const styledComponents = { GlobalStyle: createGlobalStyle` diff --git a/packages/plugins/src/styled-components.ts b/packages/plugins/src/styled-components.ts index fbcacfe3a046..f9b7d96d07b9 100644 --- a/packages/plugins/src/styled-components.ts +++ b/packages/plugins/src/styled-components.ts @@ -55,7 +55,11 @@ export { styled, ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetMan content: ` ${styledComponentsRuntimeCode} export function rootContainer(container) { - const globalStyle = styledComponentsConfig.GlobalStyle ? : null; + const scConfig = + typeof styledComponentsConfig === 'function' + ? styledComponentsConfig() + : styledComponentsConfig; + const globalStyle = scConfig.GlobalStyle ? : null; return ( <> {globalStyle}