docs: Button page show related token (#41176)

* docs: btn token

* docs: btn all tokens
This commit is contained in:
二货爱吃白萝卜 2023-03-12 14:13:03 +08:00 committed by GitHub
parent 828305bea3
commit 9642564eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 372 additions and 17 deletions

View File

@ -0,0 +1,95 @@
/* eslint import/no-unresolved: 0 */
import { ConfigProvider, Table } from 'antd';
import { getDesignToken } from 'antd-token-previewer';
import tokenMeta from 'antd/es/version/token-meta.json';
import tokenData from 'antd/es/version/token.json';
import React from 'react';
import useLocale from '../../../hooks/useLocale';
import useSiteToken from '../../../hooks/useSiteToken';
import { useColumns } from '../TokenTable';
const defaultToken = getDesignToken();
const locales = {
cn: {
token: 'Token 名称',
description: '描述',
type: '类型',
value: '默认值',
},
en: {
token: 'Token Name',
description: 'Description',
type: 'Type',
value: 'Default Value',
},
};
interface SubTokenTableProps {
defaultOpen?: boolean;
title: string;
tokens: string[];
}
function SubTokenTable({ defaultOpen, tokens, title }: SubTokenTableProps) {
const [, lang] = useLocale(locales);
const { token } = useSiteToken();
const columns = useColumns();
if (!tokens.length) {
return null;
}
const data = tokens.map((name) => {
const meta = tokenMeta[name];
return {
name,
desc: lang === 'cn' ? meta.desc : meta.descEn,
type: meta.type,
value: (defaultToken as any)[name],
};
});
return (
// Reuse `.markdown` style
<details className="markdown" open={defaultOpen}>
<summary>
<h3 style={{ display: 'inline' }}>{title}</h3>
</summary>
<ConfigProvider
theme={{
token: {
borderRadius: 0,
},
}}
>
<Table
size="middle"
columns={columns}
bordered
dataSource={data}
style={{ marginBottom: token.margin }}
pagination={false}
/>
</ConfigProvider>
</details>
);
}
export interface ComponentTokenTableProps {
component: string;
}
function ComponentTokenTable({ component }: ComponentTokenTableProps) {
const { global: globalTokens = [], component: componentTokens = [] } = tokenData[component] || {};
return (
<>
<SubTokenTable title="Component Token" tokens={componentTokens} defaultOpen />
<SubTokenTable title="Global Token" tokens={globalTokens} />
</>
);
}
export default React.memo(ComponentTokenTable);

View File

@ -1,11 +1,11 @@
import type { FC } from 'react'; import type { FC } from 'react';
import React, { useMemo } from 'react'; import * as React from 'react';
/* eslint import/no-unresolved: 0 */ /* eslint import/no-unresolved: 0 */
import tokenMeta from 'antd/es/version/token-meta.json';
import { getDesignToken } from 'antd-token-previewer';
import { Table } from 'antd';
import type { TableProps } from 'antd';
import { css } from '@emotion/react'; import { css } from '@emotion/react';
import type { TableProps } from 'antd';
import { Table } from 'antd';
import { getDesignToken } from 'antd-token-previewer';
import tokenMeta from 'antd/es/version/token-meta.json';
import useLocale from '../../../hooks/useLocale'; import useLocale from '../../../hooks/useLocale';
import useSiteToken from '../../../hooks/useSiteToken'; import useSiteToken from '../../../hooks/useSiteToken';
import ColorChunk from '../ColorChunk'; import ColorChunk from '../ColorChunk';
@ -55,10 +55,11 @@ const useStyle = () => {
}; };
}; };
const TokenTable: FC<TokenTableProps> = ({ type }) => { export function useColumns(): Exclude<TableProps<TokenData>['columns'], undefined> {
const [locale] = useLocale(locales);
const styles = useStyle(); const styles = useStyle();
const [locale, lang] = useLocale(locales);
const columns: Exclude<TableProps<TokenData>['columns'], undefined> = [ return [
{ {
title: locale.token, title: locale.token,
key: 'name', key: 'name',
@ -89,8 +90,13 @@ const TokenTable: FC<TokenTableProps> = ({ type }) => {
}, },
}, },
]; ];
}
const data = useMemo<TokenData[]>( const TokenTable: FC<TokenTableProps> = ({ type }) => {
const [, lang] = useLocale(locales);
const columns = useColumns();
const data = React.useMemo<TokenData[]>(
() => () =>
Object.entries(tokenMeta) Object.entries(tokenMeta)
.filter(([, meta]) => meta.source === type) .filter(([, meta]) => meta.source === type)

View File

@ -70,6 +70,10 @@ Different button styles can be generated by setting Button properties. The recom
It accepts all props which native buttons support. It accepts all props which native buttons support.
## Design Token
<ComponentTokenTable component="Button"></ComponentTokenTable>
## FAQ ## FAQ
### How to remove space between 2 chinese characters? ### How to remove space between 2 chinese characters?

View File

@ -75,6 +75,10 @@ group:
支持原生 button 的其他所有属性。 支持原生 button 的其他所有属性。
## Design Token
<ComponentTokenTable component="Button"></ComponentTokenTable>
## FAQ ## FAQ
### 如何移除两个汉字之间的空格? ### 如何移除两个汉字之间的空格?

View File

@ -12,8 +12,20 @@ export interface AliasToken extends MapToken {
colorFillAlter: string; colorFillAlter: string;
colorFillContent: string; colorFillContent: string;
/**
* @desc
* @descEN Disabled container background color.
*/
colorBgContainerDisabled: string; colorBgContainerDisabled: string;
/**
* @desc
* @descEN Hover text background color.
*/
colorBgTextHover: string; colorBgTextHover: string;
/**
* @desc
* @descEN Active text background color.
*/
colorBgTextActive: string; colorBgTextActive: string;
// Border // Border
@ -26,10 +38,18 @@ export interface AliasToken extends MapToken {
// Text // Text
colorTextPlaceholder: string; colorTextPlaceholder: string;
/**
* @desc
* @descEN Disabled text color
*/
colorTextDisabled: string; colorTextDisabled: string;
colorTextHeading: string; colorTextHeading: string;
colorTextLabel: string; colorTextLabel: string;
colorTextDescription: string; colorTextDescription: string;
/**
* @desc Primary Button
* @descEN Fixed text highlight color, used for text with background color such as Primary Button components
*/
colorTextLightSolid: string; colorTextLightSolid: string;
/** Weak action. Such as `allowClear` or Alert close button */ /** Weak action. Such as `allowClear` or Alert close button */
@ -37,14 +57,34 @@ export interface AliasToken extends MapToken {
/** Weak action hover color. Such as `allowClear` or Alert close button */ /** Weak action hover color. Such as `allowClear` or Alert close button */
colorIconHover: string; colorIconHover: string;
/**
* @desc
* @descEN hyperlink color
*/
colorLink: string; colorLink: string;
/**
* @desc
* @descEN hyperlink hover color
*/
colorLinkHover: string; colorLinkHover: string;
/**
* @desc
* @descEN hyperlink active color
*/
colorLinkActive: string; colorLinkActive: string;
colorHighlight: string; colorHighlight: string;
/**
* @desc Outline
* @descEN Input component outline color
*/
controlOutline: string; controlOutline: string;
colorWarningOutline: string; colorWarningOutline: string;
/**
* @desc Outline
* @descEN Input component error outline color
*/
colorErrorOutline: string; colorErrorOutline: string;
// Font // Font
@ -55,6 +95,10 @@ export interface AliasToken extends MapToken {
fontWeightStrong: number; fontWeightStrong: number;
// Control // Control
/**
* @desc Outline
* @descEN Input component outline size
*/
controlOutlineWidth: number; controlOutlineWidth: number;
controlItemBgHover: string; // Note. It also is a color controlItemBgHover: string; // Note. It also is a color
controlItemBgActive: string; // Note. It also is a color controlItemBgActive: string; // Note. It also is a color
@ -63,36 +107,140 @@ export interface AliasToken extends MapToken {
controlItemBgActiveDisabled: string; // Note. It also is a color controlItemBgActiveDisabled: string; // Note. It also is a color
// Line // Line
/**
* @desc Outline
* @descEN Outline size when focused
*/
lineWidthFocus: number; lineWidthFocus: number;
// Padding // Padding
/**
* @desc
* @descEN Padding size
*/
paddingXXS: number; paddingXXS: number;
/**
* @desc
* @descEN Padding size
*/
paddingXS: number; paddingXS: number;
/**
* @desc
* @descEN Padding size
*/
paddingSM: number; paddingSM: number;
/**
* @desc
* @descEN Padding size
*/
padding: number; padding: number;
/**
* @desc
* @descEN Padding size
*/
paddingMD: number; paddingMD: number;
/**
* @desc
* @descEN Padding size
*/
paddingLG: number; paddingLG: number;
/**
* @desc
* @descEN Padding size
*/
paddingXL: number; paddingXL: number;
// Padding Content // Padding Content
/**
* @nameZH
* @nameEN Content horizontal padding
* @desc
* @descEN Control the horizontal padding of content element.
*/
paddingContentHorizontalLG: number; paddingContentHorizontalLG: number;
/**
* @nameZH
* @nameEN Content horizontal padding
* @desc
* @descEN Control the horizontal padding of content element.
*/
paddingContentHorizontal: number; paddingContentHorizontal: number;
/**
* @nameZH
* @nameEN Content horizontal padding
* @desc
* @descEN Control the horizontal padding of content element.
*/
paddingContentHorizontalSM: number; paddingContentHorizontalSM: number;
/**
* @nameZH
* @nameEN Content vertical padding
* @desc
* @descEN Control the vertical padding of content element.
*/
paddingContentVerticalLG: number; paddingContentVerticalLG: number;
/**
* @nameZH
* @nameEN Content vertical padding
* @desc
* @descEN Control the vertical padding of content element.
*/
paddingContentVertical: number; paddingContentVertical: number;
/**
* @nameZH
* @nameEN Content vertical padding
* @desc
* @descEN Control the vertical padding of content element.
*/
paddingContentVerticalSM: number; paddingContentVerticalSM: number;
// Margin // Margin
/**
* @desc
* @descEN Margin size.
*/
marginXXS: number; marginXXS: number;
/**
* @desc
* @descEN Margin size.
*/
marginXS: number; marginXS: number;
/**
* @desc
* @descEN Margin size.
*/
marginSM: number; marginSM: number;
/**
* @desc
* @descEN Margin size.
*/
margin: number; margin: number;
/**
* @desc
* @descEN Margin size.
*/
marginMD: number; marginMD: number;
/**
* @desc
* @descEN Margin size.
*/
marginLG: number; marginLG: number;
/**
* @desc
* @descEN Margin size.
*/
marginXL: number; marginXL: number;
/**
* @desc
* @descEN Margin size.
*/
marginXXL: number; marginXXL: number;
// =============== Legacy: should be remove =============== // =============== Legacy: should be remove ===============
/**
* @desc
* @descEN Loading opacity
*/
opacityLoading: number; opacityLoading: number;
boxShadow: string; boxShadow: string;
@ -125,7 +273,11 @@ export interface AliasToken extends MapToken {
screenXXL: number; screenXXL: number;
screenXXLMin: number; screenXXLMin: number;
/** Used for DefaultButton, Switch which has default outline */ /**
* Used for DefaultButton, Switch which has default outline
* @desc Outline
* @descEN Default style outline color.
*/
controlTmpOutline: string; controlTmpOutline: string;
// FIXME: component box-shadow, should be removed // FIXME: component box-shadow, should be removed

View File

@ -14,6 +14,7 @@ export interface ColorNeutralMapToken {
/** /**
* @nameZH * @nameZH
* @desc W3C标准使 * @desc W3C标准使
* @descEN Default text color which comply with W3C standards, and this color is also the darkest neutral color.
*/ */
colorText: string; colorText: string;
@ -90,6 +91,7 @@ export interface ColorNeutralMapToken {
/** /**
* @nameZH * @nameZH
* @desc `colorBgElevated` * @desc `colorBgElevated`
* @descEN Container background color, e.g: default button, input box, etc. Be sure not to confuse this with `colorBgElevated`.
*/ */
colorBgContainer: string; colorBgContainer: string;
@ -131,25 +133,29 @@ interface ColorPrimaryMapToken {
/** /**
* @nameZH * @nameZH
* @desc Slider * @desc Slider
* @descEN The stroke color under the main color gradient, used on the stroke of components such as Slider
*/ */
colorPrimaryBorder: string; // 3 colorPrimaryBorder: string; // 3
/** /**
* @nameZH * @nameZH
* @desc Slider Button Hover 使 * @desc Slider Button Hover 使
* @descEN The hover state of the stroke color under the main color gradient, which will be used when the stroke Hover of components such as Slider and Button
*/ */
colorPrimaryBorderHover: string; // 4 colorPrimaryBorderHover: string; // 4
/** /**
* @nameZH * @nameZH
* @desc 使 * @desc
* @descEN Suspended state under the main color gradient
*/ */
colorPrimaryHover: string; // 5 colorPrimaryHover: string; // 5
/** /**
* @nameZH * @nameZH
* @desc * @desc
* @descEN Dark active states under dominant color gradient
*/ */
colorPrimaryActive: string; // 7 colorPrimaryActive: string; // 7
@ -356,6 +362,8 @@ interface ColorInfoMapToken {
interface ColorErrorMapToken { interface ColorErrorMapToken {
/** /**
* @nameZH * @nameZH
* @desc
* @descEN Error background color
*/ */
colorErrorBg: string; // 1 colorErrorBg: string; // 1
@ -371,11 +379,15 @@ interface ColorErrorMapToken {
/** /**
* @nameZH * @nameZH
* @desc
* @descEN The stroke color of the wrong color is suspended
*/ */
colorErrorBorderHover: string; // 4 colorErrorBorderHover: string; // 4
/** /**
* @nameZH * @nameZH
* @desc
* @descEN Error hover color
*/ */
colorErrorHover: string; // 5 colorErrorHover: string; // 5
@ -386,6 +398,8 @@ interface ColorErrorMapToken {
/** /**
* @nameZH * @nameZH
* @desc
* @descEN Error active color
*/ */
colorErrorActive: string; // 7 colorErrorActive: string; // 7

View File

@ -1,8 +1,24 @@
export interface FontMapToken { export interface FontMapToken {
// Font Size // Font Size
/**
* @desc
* @descEN Small font size
*/
fontSizeSM: number; fontSizeSM: number;
/**
* @desc
* @descEN Standard font size
*/
fontSize: number; fontSize: number;
/**
* @desc
* @descEN Large font size
*/
fontSizeLG: number; fontSizeLG: number;
/**
* @desc
* @descEN Super large font size
*/
fontSizeXL: number; fontSizeXL: number;
/** /**
@ -37,8 +53,20 @@ export interface FontMapToken {
fontSizeHeading5: number; fontSizeHeading5: number;
// LineHeight // LineHeight
/**
* @desc
* @descEN Line height of text.
*/
lineHeight: number; lineHeight: number;
/**
* @desc
* @descEN Line height of large text.
*/
lineHeightLG: number; lineHeightLG: number;
/**
* @desc
* @descEN Line height of small text.
*/
lineHeightSM: number; lineHeightSM: number;
lineHeightHeading1: number; lineHeightHeading1: number;

View File

@ -1,19 +1,31 @@
import type { ColorPalettes, LegacyColorPalettes } from '../presetColors'; import type { ColorPalettes, LegacyColorPalettes } from '../presetColors';
import type { SeedToken } from '../seeds'; import type { SeedToken } from '../seeds';
import type { SizeMapToken, HeightMapToken } from './size';
import type { ColorMapToken } from './colors'; import type { ColorMapToken } from './colors';
import type { StyleMapToken } from './style';
import type { FontMapToken } from './font'; import type { FontMapToken } from './font';
import type { HeightMapToken, SizeMapToken } from './size';
import type { StyleMapToken } from './style';
export * from './colors'; export * from './colors';
export * from './style';
export * from './size';
export * from './font'; export * from './font';
export * from './size';
export * from './style';
export interface CommonMapToken extends StyleMapToken { export interface CommonMapToken extends StyleMapToken {
// Motion // Motion
/**
* @desc
* @descEN Motion speed, fast speed. Used for small element animation interaction.
*/
motionDurationFast: string; motionDurationFast: string;
/**
* @desc
* @descEN Motion speed, medium speed. Used for medium element animation interaction.
*/
motionDurationMid: string; motionDurationMid: string;
/**
* @desc
* @descEN Motion speed, slow speed. Used for large element animation interaction.
*/
motionDurationSlow: string; motionDurationSlow: string;
} }

View File

@ -51,18 +51,24 @@ export interface HeightMapToken {
/** /**
* @nameZH * @nameZH
* @nameEN XS component height * @nameEN XS component height
* @desc
* @descEN XS component height
*/ */
controlHeightXS: number; controlHeightXS: number;
/** /**
* @nameZH * @nameZH
* @nameEN SM component height * @nameEN SM component height
* @desc
* @descEN SM component height
*/ */
controlHeightSM: number; controlHeightSM: number;
/** /**
* @nameZH * @nameZH
* @nameEN LG component height * @nameEN LG component height
* @desc
* @descEN LG component height
*/ */
controlHeightLG: number; controlHeightLG: number;
} }

View File

@ -83,6 +83,7 @@ export interface SeedToken extends PresetColorType {
* @nameZH * @nameZH
* @nameEN Default Font Size * @nameEN Default Font Size
* @desc 使广 * @desc 使广
* @descEN The most widely used font size in the design system, from which the text gradient will be derived.
* @default 14 * @default 14
*/ */
fontSize: number; fontSize: number;
@ -191,24 +192,57 @@ export interface SeedToken extends PresetColorType {
motionUnit: number; motionUnit: number;
/** /**
* @nameZH * @nameZH
* @nameEN Animation Base Duration.
*/ */
motionBase: number; motionBase: number;
/**
* @desc
* @descEN Preset motion curve.
*/
motionEaseOutCirc: string; motionEaseOutCirc: string;
/**
* @desc
* @descEN Preset motion curve.
*/
motionEaseInOutCirc: string; motionEaseInOutCirc: string;
/**
* @desc
* @descEN Preset motion curve.
*/
motionEaseInOut: string; motionEaseInOut: string;
/**
* @desc
* @descEN Preset motion curve.
*/
motionEaseOutBack: string; motionEaseOutBack: string;
/**
* @desc
* @descEN Preset motion curve.
*/
motionEaseInBack: string; motionEaseInBack: string;
/**
* @desc
* @descEN Preset motion curve.
*/
motionEaseInQuint: string; motionEaseInQuint: string;
/**
* @desc
* @descEN Preset motion curve.
*/
motionEaseOutQuint: string; motionEaseOutQuint: string;
/**
* @desc
* @descEN Preset motion curve.
*/
motionEaseOut: string; motionEaseOut: string;
// ---------- Style ---------- // // ---------- Style ---------- //