feat: Spin token (#44334)

* feat: Spin token

* chore: code clean
This commit is contained in:
MadCcc 2023-08-22 11:47:07 +08:00 committed by GitHub
parent d1d3b57dcb
commit 820a9213c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 28 deletions

View File

@ -10,13 +10,25 @@ export interface ComponentToken {
* @descEN Height of content area * @descEN Height of content area
*/ */
contentHeight: number; contentHeight: number;
/**
* @desc
* @descEN Loading icon size
*/
dotSize: number;
/**
* @desc
* @descEN Small loading icon size
*/
dotSizeSM: number;
/**
* @desc
* @descEN Large loading icon size
*/
dotSizeLG: number;
} }
interface SpinToken extends FullToken<'Spin'> { interface SpinToken extends FullToken<'Spin'> {
spinDotDefault: string; spinDotDefault: string;
spinDotSize: number;
spinDotSizeSM: number;
spinDotSizeLG: number;
} }
const antSpinMove = new Keyframes('antSpinMove', { const antSpinMove = new Keyframes('antSpinMove', {
@ -61,43 +73,43 @@ const genSpinStyle: GenerateStyle<SpinToken> = (token: SpinToken): CSSObject =>
position: 'absolute', position: 'absolute',
top: '50%', top: '50%',
insetInlineStart: '50%', insetInlineStart: '50%',
margin: -token.spinDotSize / 2, margin: -token.dotSize / 2,
}, },
[`${token.componentCls}-text`]: { [`${token.componentCls}-text`]: {
position: 'absolute', position: 'absolute',
top: '50%', top: '50%',
width: '100%', width: '100%',
paddingTop: (token.spinDotSize - token.fontSize) / 2 + 2, paddingTop: (token.dotSize - token.fontSize) / 2 + 2,
textShadow: `0 1px 2px ${token.colorBgContainer}`, // FIXME: shadow textShadow: `0 1px 2px ${token.colorBgContainer}`, // FIXME: shadow
fontSize: token.fontSize, fontSize: token.fontSize,
}, },
[`&${token.componentCls}-show-text ${token.componentCls}-dot`]: { [`&${token.componentCls}-show-text ${token.componentCls}-dot`]: {
marginTop: -(token.spinDotSize / 2) - 10, marginTop: -(token.dotSize / 2) - 10,
}, },
'&-sm': { '&-sm': {
[`${token.componentCls}-dot`]: { [`${token.componentCls}-dot`]: {
margin: -token.spinDotSizeSM / 2, margin: -token.dotSizeSM / 2,
}, },
[`${token.componentCls}-text`]: { [`${token.componentCls}-text`]: {
paddingTop: (token.spinDotSizeSM - token.fontSize) / 2 + 2, paddingTop: (token.dotSizeSM - token.fontSize) / 2 + 2,
}, },
[`&${token.componentCls}-show-text ${token.componentCls}-dot`]: { [`&${token.componentCls}-show-text ${token.componentCls}-dot`]: {
marginTop: -(token.spinDotSizeSM / 2) - 10, marginTop: -(token.dotSizeSM / 2) - 10,
}, },
}, },
'&-lg': { '&-lg': {
[`${token.componentCls}-dot`]: { [`${token.componentCls}-dot`]: {
margin: -(token.spinDotSizeLG / 2), margin: -(token.dotSizeLG / 2),
}, },
[`${token.componentCls}-text`]: { [`${token.componentCls}-text`]: {
paddingTop: (token.spinDotSizeLG - token.fontSize) / 2 + 2, paddingTop: (token.dotSizeLG - token.fontSize) / 2 + 2,
}, },
[`&${token.componentCls}-show-text ${token.componentCls}-dot`]: { [`&${token.componentCls}-show-text ${token.componentCls}-dot`]: {
marginTop: -(token.spinDotSizeLG / 2) - 10, marginTop: -(token.dotSizeLG / 2) - 10,
}, },
}, },
}, },
@ -147,15 +159,15 @@ const genSpinStyle: GenerateStyle<SpinToken> = (token: SpinToken): CSSObject =>
[`${token.componentCls}-dot`]: { [`${token.componentCls}-dot`]: {
position: 'relative', position: 'relative',
display: 'inline-block', display: 'inline-block',
fontSize: token.spinDotSize, fontSize: token.dotSize,
width: '1em', width: '1em',
height: '1em', height: '1em',
'&-item': { '&-item': {
position: 'absolute', position: 'absolute',
display: 'block', display: 'block',
width: (token.spinDotSize - token.marginXXS / 2) / 2, width: (token.dotSize - token.marginXXS / 2) / 2,
height: (token.spinDotSize - token.marginXXS / 2) / 2, height: (token.dotSize - token.marginXXS / 2) / 2,
backgroundColor: token.colorPrimary, backgroundColor: token.colorPrimary,
borderRadius: '100%', borderRadius: '100%',
transform: 'scale(0.75)', transform: 'scale(0.75)',
@ -205,21 +217,21 @@ const genSpinStyle: GenerateStyle<SpinToken> = (token: SpinToken): CSSObject =>
// small // small
[`&-sm ${token.componentCls}-dot`]: { [`&-sm ${token.componentCls}-dot`]: {
fontSize: token.spinDotSizeSM, fontSize: token.dotSizeSM,
i: { i: {
width: (token.spinDotSizeSM - token.marginXXS / 2) / 2, width: (token.dotSizeSM - token.marginXXS / 2) / 2,
height: (token.spinDotSizeSM - token.marginXXS / 2) / 2, height: (token.dotSizeSM - token.marginXXS / 2) / 2,
}, },
}, },
// large // large
[`&-lg ${token.componentCls}-dot`]: { [`&-lg ${token.componentCls}-dot`]: {
fontSize: token.spinDotSizeLG, fontSize: token.dotSizeLG,
i: { i: {
width: (token.spinDotSizeLG - token.marginXXS) / 2, width: (token.dotSizeLG - token.marginXXS) / 2,
height: (token.spinDotSizeLG - token.marginXXS) / 2, height: (token.dotSizeLG - token.marginXXS) / 2,
}, },
}, },
@ -235,13 +247,13 @@ export default genComponentStyleHook(
(token) => { (token) => {
const spinToken = mergeToken<SpinToken>(token, { const spinToken = mergeToken<SpinToken>(token, {
spinDotDefault: token.colorTextDescription, spinDotDefault: token.colorTextDescription,
spinDotSize: token.controlHeightLG / 2,
spinDotSizeSM: token.controlHeightLG * 0.35,
spinDotSizeLG: token.controlHeight,
}); });
return [genSpinStyle(spinToken)]; return [genSpinStyle(spinToken)];
}, },
{ (token) => ({
contentHeight: 400, contentHeight: 400,
}, dotSize: token.controlHeightLG / 2,
dotSizeSM: token.controlHeightLG * 0.35,
dotSizeLG: token.controlHeight,
}),
); );

View File

@ -14,8 +14,8 @@ This document contains the correspondence between all the less variables related
We could configure global token and component token for each component through the `theme` property of ConfigProvider. We could configure global token and component token for each component through the `theme` property of ConfigProvider.
```tsx ```tsx
import { Checkbox, ConfigProvider, Radio } from 'antd';
import React from 'react'; import React from 'react';
import { Checkbox, ConfigProvider, Radio } from 'antd';
const App: React.FC = () => ( const App: React.FC = () => (
<ConfigProvider <ConfigProvider
@ -670,6 +670,15 @@ export default App;
| `@slider-disabled-color` | `trackBgDisabled` | - | | `@slider-disabled-color` | `trackBgDisabled` | - |
| `@slider-disabled-background-color` | - | Deprecated | | `@slider-disabled-background-color` | - | Deprecated |
### Spin
<!-- prettier-ignore -->
| Less variables | Component Token | Note |
| --- | --- | --- |
| `@spin-dot-size-sm` | `dotSizeSM` | - |
| `@spin-dot-size` | `dotSize` | - |
| `@spin-dot-size-lg` | `dotSizeLG` | - |
### Statistic ### Statistic
<!-- prettier-ignore --> <!-- prettier-ignore -->

View File

@ -14,8 +14,8 @@ title: 从 Less 变量到 Design Token
通过 ConfigProvider 的 `theme` 属性,我们可以对每一个组件单独配置全局 Token 和组件 Token 通过 ConfigProvider 的 `theme` 属性,我们可以对每一个组件单独配置全局 Token 和组件 Token
```tsx ```tsx
import { Checkbox, ConfigProvider, Radio } from 'antd';
import React from 'react'; import React from 'react';
import { Checkbox, ConfigProvider, Radio } from 'antd';
const App: React.FC = () => ( const App: React.FC = () => (
<ConfigProvider <ConfigProvider
@ -668,6 +668,15 @@ Mentions 提及
| `@slider-disabled-color` | `trackBgDisabled` | - | | `@slider-disabled-color` | `trackBgDisabled` | - |
| `@slider-disabled-background-color` | - | 已废弃 | | `@slider-disabled-background-color` | - | 已废弃 |
### Spin 加载中
<!-- prettier-ignore -->
| Less 变量 | Component Token | 备注 |
| --- | --- | --- |
| `@spin-dot-size-sm` | `dotSizeSM` | - |
| `@spin-dot-size` | `dotSize` | - |
| `@spin-dot-size-lg` | `dotSizeLG` | - |
### Statistic 统计数值 ### Statistic 统计数值
<!-- prettier-ignore --> <!-- prettier-ignore -->