generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
222 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: 更新日志 | ||
nav: | ||
title: 更新日志 | ||
order: 999 | ||
--- | ||
|
||
<embed src="../CHANGELOG.md"></embed> |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createGlobalStyle, ThemeProvider } from 'antd-style'; | ||
|
||
const Global = createGlobalStyle` | ||
.ant-custom-button { | ||
color: ${(p) => p.theme.colorPrimary}; | ||
background: ${(p) => p.theme.colorPrimaryBg}; | ||
height: ${(p) => p.theme.controlHeight}px; | ||
border-radius: ${(p) => p.theme.borderRadius}px; | ||
padding: 0 ${(p) => p.theme.paddingContentHorizontal}px; | ||
:hover { | ||
background: ${(p) => p.theme.colorPrimaryBgHover}; | ||
color: ${(p) => p.theme.colorPrimaryTextActive}; | ||
} | ||
:active { | ||
background: ${(p) => p.theme.colorPrimaryBorder}; | ||
color: ${(p) => p.theme.colorPrimaryText}; | ||
} | ||
border: none; | ||
cursor: pointer; | ||
} | ||
`; | ||
|
||
export default () => { | ||
return ( | ||
<ThemeProvider> | ||
<Global /> | ||
<button className="ant-custom-button">antd 中不存在的按钮</button> | ||
</ThemeProvider> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createGlobalStyle } from 'antd-style'; | ||
|
||
const Global = createGlobalStyle` | ||
.no-token-button { | ||
color: ${(p) => p.theme.colorPrimary}; | ||
background: ${(p) => p.theme.colorPrimaryBg}; | ||
height: ${(p) => p.theme.controlHeight}px; | ||
border-radius: ${(p) => p.theme.borderRadius}px; | ||
padding: 0 ${(p) => p.theme.paddingContentHorizontal}px; | ||
:hover { | ||
background: ${(p) => p.theme.colorPrimaryBgHover}; | ||
color: ${(p) => p.theme.colorPrimaryTextActive}; | ||
} | ||
:active { | ||
background: ${(p) => p.theme.colorPrimaryBorder}; | ||
color: ${(p) => p.theme.colorPrimaryText}; | ||
} | ||
border: none; | ||
cursor: pointer; | ||
} | ||
`; | ||
|
||
export default () => { | ||
return ( | ||
<div> | ||
<Global /> | ||
<button className="no-token-button">没了 Provider 就会被打回原形,切记</button> | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createGlobalStyle } from 'antd-style'; | ||
|
||
const Global = createGlobalStyle` | ||
.some-class { | ||
color: hotpink; | ||
} | ||
`; | ||
|
||
export default () => { | ||
return ( | ||
<div> | ||
<Global /> | ||
<div className="some-class">猛男最喜欢的颜色</div> | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: 快速上手 | ||
group: 快速上手 | ||
--- | ||
|
||
# 快速上手 |
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,27 +1,7 @@ | ||
--- | ||
title: 介绍 | ||
hero: | ||
title: antd-style | ||
description: a css-in-js application solution combine emotion with antd v5 token system | ||
--- | ||
|
||
## 简介 | ||
|
||
这是一个模块的简洁 demo | ||
|
||
## 快速上手 | ||
|
||
### 安装 | ||
|
||
推荐使用 pnpm 安装 | ||
|
||
```bash | ||
pnpm i xxx --S | ||
``` | ||
|
||
### 使用 | ||
|
||
核心功能简介 | ||
|
||
## 场景介绍 | ||
|
||
### 消费场景一 | ||
|
||
### 消费场景二 | ||
<embed src="../README.md"></embed> |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: 全局样式 | ||
group: 使用指南 | ||
--- | ||
|
||
# 全局样式 | ||
|
||
使用 `createGlobalStyle` 可以创建注入到全局的样式。 该方法的使用和 styled-component 基本没有区别,但实现上是基于 `@emotion/react` 和 `@emotion/serialize` 做的封装。 | ||
|
||
## 默认用法 | ||
|
||
<code src="../demos/globalStyles/default.tsx"></embed> | ||
|
||
## 结合 antd 的 token 使用 | ||
|
||
利用 antd v5 的 token 系统,我们可以自行组织实现一个在 Ant Design 的 Button 中并不存在的样式。 | ||
|
||
<code src="../demos/globalStyles/AntdToken.tsx"></embed> | ||
|
||
:::warning | ||
|
||
`<Global />` 需要套在 `ThemeProvider` 组件下,token 才能生效,否则是无效的。 | ||
|
||
::: | ||
|
||
<code src="../demos/globalStyles/WithoutProvider.tsx"></embed> |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useTheme } from '@/styled'; | ||
import { Global, Theme } from '@emotion/react'; | ||
import { serializeStyles } from '@emotion/serialize'; | ||
import { Interpolation } from '@emotion/styled'; | ||
import { memo } from 'react'; | ||
|
||
interface GlobalTheme { | ||
theme: Theme; | ||
} | ||
|
||
/** | ||
* 创建全局样式 | ||
* @param styles | ||
*/ | ||
export const createGlobalStyle = ( | ||
...styles: Array<TemplateStringsArray | Interpolation<GlobalTheme>> | ||
) => | ||
memo((props) => { | ||
const theme = useTheme(); | ||
return <Global styles={serializeStyles(styles, undefined, { ...props, theme })} />; | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { render } from '@testing-library/react'; | ||
import { createGlobalStyle, ThemeProvider } from 'antd-style'; | ||
|
||
describe('createGlobalStyle', () => { | ||
it('全局样式', async () => { | ||
const Global = createGlobalStyle` | ||
.some-class { | ||
color: pink; | ||
} | ||
`; | ||
|
||
const { findByTestId } = render( | ||
<div data-testid={'content'}> | ||
<div className="some-class">pink txt</div> | ||
<Global /> | ||
</div>, | ||
); | ||
|
||
const item = await findByTestId('content'); | ||
|
||
expect(item.firstChild).toHaveStyle({ color: 'pink' }); | ||
}); | ||
|
||
it('包裹 ThemeProvider 后可以获取主题样式', async () => { | ||
const Global = createGlobalStyle` | ||
.some-class { | ||
color: ${(p) => p.theme.colorPrimary}; | ||
} | ||
`; | ||
|
||
const { findByTestId } = render( | ||
<div data-testid={'content'}> | ||
<div className="some-class">pink txt</div> | ||
<Global /> | ||
</div>, | ||
{ wrapper: ThemeProvider }, | ||
); | ||
|
||
const item = await findByTestId('content'); | ||
|
||
expect(item.firstChild).toHaveStyle({ color: '#1677FF' }); | ||
}); | ||
|
||
it('不包裹 ThemeProvider 没法获得 token', async () => { | ||
const Global = createGlobalStyle` | ||
.some-class { | ||
color: ${(p) => p.theme.colorPrimary}; | ||
} | ||
`; | ||
|
||
const { findByTestId } = render( | ||
<div data-testid={'content'}> | ||
<div className="some-class">pink txt</div> | ||
<Global /> | ||
</div>, | ||
); | ||
|
||
const item = await findByTestId('content'); | ||
|
||
expect(item.firstChild).toHaveStyle({ color: '' }); | ||
}); | ||
}); |
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