From c0b00c32d641d97243eca613eab011347078d253 Mon Sep 17 00:00:00 2001 From: arvinxx Date: Sun, 23 Apr 2023 20:48:12 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20fix:=20=E4=BF=AE=E6=AD=A3=20createInsta?= =?UTF-8?q?nce=20=E7=9A=84=20container=20=E6=8F=92=E5=85=A5=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E5=88=B6=E5=AE=9A=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #47 --- src/factories/createStyleProvider/index.tsx | 3 ++- src/functions/createInstance.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/factories/createStyleProvider/index.tsx b/src/factories/createStyleProvider/index.tsx index 5b7fa6d5..94fbcb36 100644 --- a/src/factories/createStyleProvider/index.tsx +++ b/src/factories/createStyleProvider/index.tsx @@ -36,6 +36,7 @@ export interface StyleProviderProps interface DefaultProps { prefix: string; speedy?: boolean; + container?: Node; } export const createStyleProvider = ( @@ -48,7 +49,7 @@ export const createStyleProvider = ( prefix = defaultProps?.prefix || DEFAULT_CSS_PREFIX_KEY, speedy = defaultProps?.speedy, getStyleManager, - container, + container = defaultProps?.container, nonce, insertionPoint, stylisPlugins, diff --git a/src/functions/createInstance.ts b/src/functions/createInstance.ts index 1c88b96e..b42b54da 100644 --- a/src/functions/createInstance.ts +++ b/src/functions/createInstance.ts @@ -40,6 +40,8 @@ export interface CreateOptions { * @default false */ speedy?: boolean; + + container?: Node; /** * 默认的自定义 Token */ @@ -57,7 +59,12 @@ export interface CreateOptions { export const createInstance = (options: CreateOptions) => { const defaultKey = options.key || 'css'; - const emotion = createEmotion({ key: defaultKey, speedy: options.speedy }); + // TODO: 此处的 emotion 应该是 emotion context 中的 emotion,需要允许外部通过 Provider 进行修改 + const emotion = createEmotion({ + key: defaultKey, + speedy: options.speedy, + container: options.container, + }); // 将 cache 存到一个全局 cacheManager.add(emotion.cache); @@ -105,6 +112,7 @@ export const createInstance = (options: CreateOptions) => { const StyleProvider = createStyleProvider(EmotionContext, { speedy: options.speedy, prefix: defaultKey, + container: options.container, }); return {