generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: 将 antd-style 中导出的 css 都替换为 `@emotion/react` 的 css,建立起 css`` -> styleObject 的心智。 原因:由于 emotion/css 的 css`` 只产出 className,因此无法做一些复杂操作,例如样式片段复用,需要替换为 react 的版本
- Loading branch information
Showing
5 changed files
with
35 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import { ClassNamesUtil } from '@/types'; | ||
import { createCX } from '@/utils'; | ||
import createEmotion from '@emotion/css/create-instance'; | ||
|
||
export const emotion = createEmotion({ | ||
key: 'ant-css', | ||
speedy: false, | ||
}); | ||
|
||
export const { | ||
css, | ||
cx, | ||
injectGlobal, | ||
keyframes, | ||
sheet, | ||
flush, | ||
merge, | ||
hydrate, | ||
getRegisteredStyles, | ||
cache, | ||
} = emotion; | ||
export const { injectGlobal, keyframes, sheet, flush, merge, hydrate, getRegisteredStyles, cache } = | ||
emotion; | ||
|
||
export type { Emotion } from '@emotion/css/create-instance'; | ||
export { css } from '@emotion/react'; | ||
export { createEmotion }; | ||
|
||
/** | ||
* 用于将 css 生成的 styles 创建为 className | ||
* @param classNames | ||
*/ | ||
export const cx: ClassNamesUtil = createCX(emotion.css, emotion.cx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import { ClassNamesUtil } from '@/types'; | ||
import { Emotion } from '@emotion/css/create-instance'; | ||
|
||
/** | ||
* 判断是否是 ReactCss 的编译产物 | ||
* @param params | ||
*/ | ||
export const isReactCssResult = (params: any) => | ||
typeof params === 'object' && 'styles' in params && 'name' in params && 'toString' in params; | ||
|
||
export const createCX = | ||
(css: Emotion['css'], cx: Emotion['cx']): ClassNamesUtil => | ||
(...classNames) => { | ||
return cx( | ||
...(classNames.map((c) => | ||
// 由于使用了 reactCss 作为基础样式工具,因此在使用 cx 级联 className 时需要使用特殊处理的 cx | ||
// 要将 reactCss 的产出转为 css 产物 | ||
isReactCssResult(c) ? css(c) : c, | ||
) as any[]), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters