Skip to content

Commit

Permalink
Revert "feat: createGlobal"
Browse files Browse the repository at this point in the history
This reverts commit da4b2e0.
  • Loading branch information
MadCcc committed Jul 20, 2023
1 parent d240bda commit bb45c9b
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 16,915 deletions.
6 changes: 0 additions & 6 deletions docs/api/global-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,3 @@ group: 创建样式
利用 antd v5 的 token 系统,我们可以自行组织实现一个在 Ant Design 中并不存在的 Button 样式。

<code src="../demos/globalStyles/AntdToken.tsx"></code>

## `createStyles` 相似的使用方法

`createGlobal` 同样可以用于插入全局样式,但拥有与 `createStyles` 相似的 api。

<code src="../demos/globalStyles/createGlobal.tsx"></code>
35 changes: 0 additions & 35 deletions docs/demos/globalStyles/createGlobal.tsx

This file was deleted.

21 changes: 2 additions & 19 deletions src/factories/createGlobalStyle.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Global, css as emotionCss } from '@emotion/react';
import { Global } from '@emotion/react';
import { serializeStyles } from '@emotion/serialize';
import { memo } from 'react';

import { CSSStyle, FullToken, Theme } from '@/types';
import { CSSStyle, Theme } from '@/types';

export interface GlobalTheme {
theme: Theme;
Expand All @@ -18,20 +18,3 @@ export const createGlobalStyleFactory =
const theme = useTheme();
return <Global styles={serializeStyles(styles, undefined, { ...props, theme })} />;
});

export const createGlobalFactory =
(useTheme: () => Theme) =>
(
styleFn: ({
token,
css,
}: {
token: FullToken;
css: typeof emotionCss;
}) => ReturnType<typeof emotionCss>,
) => {
return memo(() => {
const token = useTheme();
return <Global styles={styleFn({ token, css: emotionCss })} />;
});
};
5 changes: 1 addition & 4 deletions src/functions/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createContext } from 'react';
import { CacheManager, createCSS, createEmotion, serializeCSS } from '@/core';

import { createEmotionContext } from '@/factories/createEmotionContext';
import { createGlobalFactory, createGlobalStyleFactory } from '@/factories/createGlobalStyle';
import { createGlobalStyleFactory } from '@/factories/createGlobalStyle';
import { createStylishFactory } from '@/factories/createStyish';
import { createStyleProvider } from '@/factories/createStyleProvider';
import { createStylesFactory } from '@/factories/createStyles';
Expand Down Expand Up @@ -99,8 +99,6 @@ export const createInstance = <T = any>(options: CreateOptions<T>) => {

const createGlobalStyle = createGlobalStyleFactory(useTheme);

const createGlobal = createGlobalFactory(useTheme);

const createStylish = createStylishFactory(createStyles);

const ThemeProvider = createThemeProvider({
Expand All @@ -119,7 +117,6 @@ export const createInstance = <T = any>(options: CreateOptions<T>) => {
// ******************** //
createStyles,
createGlobalStyle,
createGlobal,
createStylish,
// ******************** //
// **** 基础样式方法 **** //
Expand Down
1 change: 0 additions & 1 deletion src/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const {
createStyles,
createGlobalStyle,
createStylish,
createGlobal,
// **** 基础样式方法 **** //
css,
cx,
Expand Down
Loading

0 comments on commit bb45c9b

Please sign in to comment.