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 React, { useMemo } from 'react';
import * as React from 'react';
/* 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 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 useSiteToken from '../../../hooks/useSiteToken';
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 [locale, lang] = useLocale(locales);
const columns: Exclude<TableProps<TokenData>['columns'], undefined> = [
return [
{
title: locale.token,
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)
.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.
## Design Token
<ComponentTokenTable component="Button"></ComponentTokenTable>
## FAQ
### How to remove space between 2 chinese characters?

View File

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

View File

@ -12,8 +12,20 @@ export interface AliasToken extends MapToken {
colorFillAlter: string;
colorFillContent: string;
/**
* @desc
* @descEN Disabled container background color.
*/
colorBgContainerDisabled: string;
/**
* @desc
* @descEN Hover text background color.
*/
colorBgTextHover: string;
/**
* @desc
* @descEN Active text background color.
*/
colorBgTextActive: string;
// Border
@ -26,10 +38,18 @@ export interface AliasToken extends MapToken {
// Text
colorTextPlaceholder: string;
/**
* @desc
* @descEN Disabled text color
*/
colorTextDisabled: string;
colorTextHeading: string;
colorTextLabel: string;
colorTextDescription: string;
/**
* @desc Primary Button
* @descEN Fixed text highlight color, used for text with background color such as Primary Button components
*/
colorTextLightSolid: string;
/** 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 */
colorIconHover: string;
/**
* @desc
* @descEN hyperlink color
*/
colorLink: string;
/**
* @desc
* @descEN hyperlink hover color
*/
colorLinkHover: string;
/**
* @desc
* @descEN hyperlink active color
*/
colorLinkActive: string;
colorHighlight: string;
/**
* @desc Outline
* @descEN Input component outline color
*/
controlOutline: string;
colorWarningOutline: string;
/**
* @desc Outline
* @descEN Input component error outline color
*/
colorErrorOutline: string;
// Font
@ -55,6 +95,10 @@ export interface AliasToken extends MapToken {
fontWeightStrong: number;
// Control
/**
* @desc Outline
* @descEN Input component outline size
*/
controlOutlineWidth: number;
controlItemBgHover: 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
// Line
/**
* @desc Outline
* @descEN Outline size when focused
*/
lineWidthFocus: number;
// Padding
/**
* @desc
* @descEN Padding size
*/
paddingXXS: number;
/**
* @desc
* @descEN Padding size
*/
paddingXS: number;
/**
* @desc
* @descEN Padding size
*/
paddingSM: number;
/**
* @desc
* @descEN Padding size
*/
padding: number;
/**
* @desc
* @descEN Padding size
*/
paddingMD: number;
/**
* @desc
* @descEN Padding size
*/
paddingLG: number;
/**
* @desc
* @descEN Padding size
*/
paddingXL: number;
// Padding Content
/**
* @nameZH
* @nameEN Content horizontal padding
* @desc
* @descEN Control the horizontal padding of content element.
*/
paddingContentHorizontalLG: number;
/**
* @nameZH
* @nameEN Content horizontal padding
* @desc
* @descEN Control the horizontal padding of content element.
*/
paddingContentHorizontal: number;
/**
* @nameZH
* @nameEN Content horizontal padding
* @desc
* @descEN Control the horizontal padding of content element.
*/
paddingContentHorizontalSM: number;
/**
* @nameZH
* @nameEN Content vertical padding
* @desc
* @descEN Control the vertical padding of content element.
*/
paddingContentVerticalLG: number;
/**
* @nameZH
* @nameEN Content vertical padding
* @desc
* @descEN Control the vertical padding of content element.
*/
paddingContentVertical: number;
/**
* @nameZH
* @nameEN Content vertical padding
* @desc
* @descEN Control the vertical padding of content element.
*/
paddingContentVerticalSM: number;
// Margin
/**
* @desc
* @descEN Margin size.
*/
marginXXS: number;
/**
* @desc
* @descEN Margin size.
*/
marginXS: number;
/**
* @desc
* @descEN Margin size.
*/
marginSM: number;
/**
* @desc
* @descEN Margin size.
*/
margin: number;
/**
* @desc
* @descEN Margin size.
*/
marginMD: number;
/**
* @desc
* @descEN Margin size.
*/
marginLG: number;
/**
* @desc
* @descEN Margin size.
*/
marginXL: number;
/**
* @desc
* @descEN Margin size.
*/
marginXXL: number;
// =============== Legacy: should be remove ===============
/**
* @desc
* @descEN Loading opacity
*/
opacityLoading: number;
boxShadow: string;
@ -125,7 +273,11 @@ export interface AliasToken extends MapToken {
screenXXL: 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;
// FIXME: component box-shadow, should be removed

View File

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

View File

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

View File

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

View File

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

View File

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