Skip to content

Commit

Permalink
✏️ fix: cache 设为可选项
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Mar 17, 2023
1 parent 71becf8 commit 495cd78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
23 changes: 14 additions & 9 deletions src/factories/createStyleProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { StylisPlugin } from '@emotion/cache';
import { Context, FC, memo, ReactNode, useEffect, useMemo } from 'react';

export interface StyleProviderProps
extends Pick<
StyleContextProps,
'container' | 'autoClear' | 'cache' | 'hashPriority' | 'ssrInline' | 'transformers'
extends Partial<
Pick<
StyleContextProps,
'container' | 'autoClear' | 'cache' | 'hashPriority' | 'ssrInline' | 'transformers'
>
> {
prefix?: string;

Expand Down Expand Up @@ -69,11 +71,14 @@ export const createStyleProvider = (
getStyleManager?.(emotion);
}, [emotion]);

return (
// @ts-ignore
<AntdStyleProvider {...antdStyleProviderProps}>
<EmotionContext.Provider value={emotion}>{children}</EmotionContext.Provider>
</AntdStyleProvider>
);
const content = <EmotionContext.Provider value={emotion}>{children}</EmotionContext.Provider>;

if (antdStyleProviderProps.cache) {
return (
// @ts-ignore
<AntdStyleProvider {...antdStyleProviderProps}>{content}</AntdStyleProvider>
);
}
return content;
},
);
20 changes: 18 additions & 2 deletions src/factories/createThemeProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,29 @@ import TokenContainer from './TokenContainer';
import { ThemeProviderProps } from './type';

export * from './type';

/**
* @title CreateThemeProviderOptions
* @category Interfaces
* @description 用于创建主题提供者的选项接口
*/
interface CreateThemeProviderOptions {
/**
* @title styledConfig
* @description 配置 styled-components 的选项
* @default undefined
*/
styledConfig?: StyledConfig;
/**
* @title StyleEngineContext
* @description StyleEngine 上下文
*/
StyleEngineContext: Context<StyleEngine>;
/**
* @title useTheme
* @description 获取当前主题的钩子函数
*/
useTheme: UseTheme;
}

export const createThemeProvider = (
option: CreateThemeProviderOptions,
): (<T = any, S = any>(props: ThemeProviderProps<T, S>) => ReactElement | null) => {
Expand Down

0 comments on commit 495cd78

Please sign in to comment.