feat: less to component token for Typography (#42442)

* feat: less to component token for Typography

* feat: add titleFontWeight token

* feat: add debug demo

* chore: rename token

* chore: rename demo name

* chore: rename titleFontWeight

---------

Co-authored-by: zhangjianxiong <zhangjx@tsintergy.com>
Co-authored-by: MadCcc <1075746765@qq.com>
Co-authored-by: lijianan <574980606@qq.com>
This commit is contained in:
Zack Chang 2023-05-19 09:46:15 +08:00 committed by GitHub
parent 43d7b9ca92
commit 3bfb7ac2a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 582 additions and 15 deletions

View File

@ -215,6 +215,221 @@ exports[`renders components/typography/demo/basic.tsx extend context correctly 1
</article>
`;
exports[`renders components/typography/demo/componentToken-debug.tsx extend context correctly 1`] = `
<article
class="ant-typography"
>
<h1
class="ant-typography"
>
Introduction
</h1>
<div
class="ant-typography"
>
In the process of internal desktop applications development, many different design specs and implementations would be involved, which might cause designers and developers difficulties and duplication and reduce the efficiency of development.
</div>
<div
class="ant-typography"
>
After massive project practice and summaries, Ant Design, a design language for background applications, is refined by Ant UED Team, which aims to
<span
class="ant-typography"
>
<strong>
uniform the user interface specs for internal background projects, lower the unnecessary cost of design differences and implementation and liberate the resources of design and front-end development
</strong>
</span>
.
</div>
<h2
class="ant-typography"
>
Guidelines and Resources
</h2>
<div
class="ant-typography"
>
We supply a series of design principles, practical patterns and high quality design resources (
<span
class="ant-typography"
>
<code>
Sketch
</code>
</span>
and
<span
class="ant-typography"
>
<code>
Axure
</code>
</span>
), to help people create their product prototypes beautifully and efficiently.
</div>
<div
class="ant-typography"
>
<ul>
<li>
<a
class="ant-typography"
href="/docs/spec/proximity"
>
Principles
</a>
</li>
<li>
<a
class="ant-typography"
href="/docs/spec/overview"
>
Patterns
</a>
</li>
<li>
<a
class="ant-typography"
href="/docs/resources"
>
Resource Download
</a>
</li>
</ul>
</div>
<div
class="ant-typography"
>
Press
<span
class="ant-typography"
>
<kbd>
Esc
</kbd>
</span>
to exit...
</div>
<div
class="ant-divider ant-divider-horizontal"
role="separator"
/>
<h1
class="ant-typography"
>
介绍
</h1>
<div
class="ant-typography"
>
蚂蚁的企业级产品是一个庞大且复杂的体系。这类产品不仅量级巨大且功能复杂,而且变动和并发频繁,常常需要设计与开发能够快速的做出响应。同时这类产品中有存在很多类似的页面以及组件,可以通过抽象得到一些稳定且高复用性的内容。
</div>
<div
class="ant-typography"
>
随着商业化的趋势,越来越多的企业级产品对更好的用户体验有了进一步的要求。带着这样的一个终极目标,我们(蚂蚁金服体验技术部)经过大量的项目实践和总结,逐步打磨出一个服务于企业级产品的设计体系 Ant Design。基于
<span
class="ant-typography"
>
<mark>
『确定』和『自然』
</mark>
</span>
的设计价值观,通过模块化的解决方案,降低冗余的生产成本,让设计者专注于
<span
class="ant-typography"
>
<strong>
更好的用户体验
</strong>
</span>
</div>
<h2
class="ant-typography"
>
设计资源
</h2>
<div
class="ant-typography"
>
我们提供完善的设计原则、最佳实践和设计资源文件(
<span
class="ant-typography"
>
<code>
Sketch
</code>
</span>
<span
class="ant-typography"
>
<code>
Axure
</code>
</span>
),来帮助业务快速设计出高质量的产品原型。
</div>
<div
class="ant-typography"
>
<ul>
<li>
<a
class="ant-typography"
href="/docs/spec/proximity-cn"
>
设计原则
</a>
</li>
<li>
<a
class="ant-typography"
href="/docs/spec/overview-cn"
>
设计模式
</a>
</li>
<li>
<a
class="ant-typography"
href="/docs/resources-cn"
>
设计资源
</a>
</li>
</ul>
</div>
<div
class="ant-typography"
>
<blockquote>
AntV 是蚂蚁金服全新一代数据可视化解决方案致力于提供一套简单方便、专业可靠、不限可能的数据可视化最佳实践。得益于丰富的业务场景和用户需求挑战AntV 经历多年积累与不断打磨,已支撑整个阿里集团内外 20000+ 业务系统,通过了日均千万级 UV 产品的严苛考验。
我们正在基础图表,图分析,图编辑,地理空间可视化,智能可视化等各个可视化的领域耕耘,欢迎同路人一起前行。
</blockquote>
<pre>
AntV 是蚂蚁金服全新一代数据可视化解决方案致力于提供一套简单方便、专业可靠、不限可能的数据可视化最佳实践。得益于丰富的业务场景和用户需求挑战AntV 经历多年积累与不断打磨,已支撑整个阿里集团内外 20000+ 业务系统,通过了日均千万级 UV 产品的严苛考验。
我们正在基础图表,图分析,图编辑,地理空间可视化,智能可视化等各个可视化的领域耕耘,欢迎同路人一起前行。
</pre>
</div>
<div
class="ant-typography"
>
<span
class="ant-typography"
>
<kbd>
Esc
</kbd>
</span>
键退出阅读……
</div>
</article>
`;
exports[`renders components/typography/demo/ellipsis.tsx extend context correctly 1`] = `
Array [
<button

View File

@ -216,6 +216,222 @@ exports[`renders components/typography/demo/basic.tsx correctly 1`] = `
</article>
`;
exports[`renders components/typography/demo/componentToken-debug.tsx correctly 1`] = `
<article
class="ant-typography"
>
<h1
class="ant-typography"
>
Introduction
</h1>
<div
class="ant-typography"
>
In the process of internal desktop applications development, many different design specs and implementations would be involved, which might cause designers and developers difficulties and duplication and reduce the efficiency of development.
</div>
<div
class="ant-typography"
>
After massive project practice and summaries, Ant Design, a design language for background applications, is refined by Ant UED Team, which aims to
<!-- -->
<span
class="ant-typography"
>
<strong>
uniform the user interface specs for internal background projects, lower the unnecessary cost of design differences and implementation and liberate the resources of design and front-end development
</strong>
</span>
.
</div>
<h2
class="ant-typography"
>
Guidelines and Resources
</h2>
<div
class="ant-typography"
>
We supply a series of design principles, practical patterns and high quality design resources (
<span
class="ant-typography"
>
<code>
Sketch
</code>
</span>
and
<span
class="ant-typography"
>
<code>
Axure
</code>
</span>
), to help people create their product prototypes beautifully and efficiently.
</div>
<div
class="ant-typography"
>
<ul>
<li>
<a
class="ant-typography"
href="/docs/spec/proximity"
>
Principles
</a>
</li>
<li>
<a
class="ant-typography"
href="/docs/spec/overview"
>
Patterns
</a>
</li>
<li>
<a
class="ant-typography"
href="/docs/resources"
>
Resource Download
</a>
</li>
</ul>
</div>
<div
class="ant-typography"
>
Press
<span
class="ant-typography"
>
<kbd>
Esc
</kbd>
</span>
to exit...
</div>
<div
class="ant-divider ant-divider-horizontal"
role="separator"
/>
<h1
class="ant-typography"
>
介绍
</h1>
<div
class="ant-typography"
>
蚂蚁的企业级产品是一个庞大且复杂的体系。这类产品不仅量级巨大且功能复杂,而且变动和并发频繁,常常需要设计与开发能够快速的做出响应。同时这类产品中有存在很多类似的页面以及组件,可以通过抽象得到一些稳定且高复用性的内容。
</div>
<div
class="ant-typography"
>
随着商业化的趋势,越来越多的企业级产品对更好的用户体验有了进一步的要求。带着这样的一个终极目标,我们(蚂蚁金服体验技术部)经过大量的项目实践和总结,逐步打磨出一个服务于企业级产品的设计体系 Ant Design。基于
<span
class="ant-typography"
>
<mark>
『确定』和『自然』
</mark>
</span>
的设计价值观,通过模块化的解决方案,降低冗余的生产成本,让设计者专注于
<span
class="ant-typography"
>
<strong>
更好的用户体验
</strong>
</span>
</div>
<h2
class="ant-typography"
>
设计资源
</h2>
<div
class="ant-typography"
>
我们提供完善的设计原则、最佳实践和设计资源文件(
<span
class="ant-typography"
>
<code>
Sketch
</code>
</span>
<span
class="ant-typography"
>
<code>
Axure
</code>
</span>
),来帮助业务快速设计出高质量的产品原型。
</div>
<div
class="ant-typography"
>
<ul>
<li>
<a
class="ant-typography"
href="/docs/spec/proximity-cn"
>
设计原则
</a>
</li>
<li>
<a
class="ant-typography"
href="/docs/spec/overview-cn"
>
设计模式
</a>
</li>
<li>
<a
class="ant-typography"
href="/docs/resources-cn"
>
设计资源
</a>
</li>
</ul>
</div>
<div
class="ant-typography"
>
<blockquote>
AntV 是蚂蚁金服全新一代数据可视化解决方案致力于提供一套简单方便、专业可靠、不限可能的数据可视化最佳实践。得益于丰富的业务场景和用户需求挑战AntV 经历多年积累与不断打磨,已支撑整个阿里集团内外 20000+ 业务系统,通过了日均千万级 UV 产品的严苛考验。
我们正在基础图表,图分析,图编辑,地理空间可视化,智能可视化等各个可视化的领域耕耘,欢迎同路人一起前行。
</blockquote>
<pre>
AntV 是蚂蚁金服全新一代数据可视化解决方案致力于提供一套简单方便、专业可靠、不限可能的数据可视化最佳实践。得益于丰富的业务场景和用户需求挑战AntV 经历多年积累与不断打磨,已支撑整个阿里集团内外 20000+ 业务系统,通过了日均千万级 UV 产品的严苛考验。
我们正在基础图表,图分析,图编辑,地理空间可视化,智能可视化等各个可视化的领域耕耘,欢迎同路人一起前行。
</pre>
</div>
<div
class="ant-typography"
>
<span
class="ant-typography"
>
<kbd>
Esc
</kbd>
</span>
键退出阅读……
</div>
</article>
`;
exports[`renders components/typography/demo/ellipsis.tsx correctly 1`] = `
Array [
<button

View File

@ -0,0 +1,7 @@
## zh-CN
自定义组件 Token。
## en-US
Custom component token.

View File

@ -0,0 +1,107 @@
import { ConfigProvider, Divider, Typography } from 'antd';
import React from 'react';
const { Title, Paragraph, Text, Link } = Typography;
const blockContent = `AntV 是蚂蚁金服全新一代数据可视化解决方案致力于提供一套简单方便、专业可靠、不限可能的数据可视化最佳实践。得益于丰富的业务场景和用户需求挑战AntV 经历多年积累与不断打磨,已支撑整个阿里集团内外 20000+ 业务系统,通过了日均千万级 UV 产品的严苛考验。
`;
const App: React.FC = () => (
<ConfigProvider
theme={{
components: {
Typography: {
fontWeightStrong: 700,
titleMarginTop: '2.4em',
titleMarginBottom: '1em',
},
},
}}
>
<Typography>
<Title>Introduction</Title>
<Paragraph>
In the process of internal desktop applications development, many different design specs and
implementations would be involved, which might cause designers and developers difficulties
and duplication and reduce the efficiency of development.
</Paragraph>
<Paragraph>
After massive project practice and summaries, Ant Design, a design language for background
applications, is refined by Ant UED Team, which aims to{' '}
<Text strong>
uniform the user interface specs for internal background projects, lower the unnecessary
cost of design differences and implementation and liberate the resources of design and
front-end development
</Text>
.
</Paragraph>
<Title level={2}>Guidelines and Resources</Title>
<Paragraph>
We supply a series of design principles, practical patterns and high quality design
resources (<Text code>Sketch</Text> and <Text code>Axure</Text>), to help people create
their product prototypes beautifully and efficiently.
</Paragraph>
<Paragraph>
<ul>
<li>
<Link href="/docs/spec/proximity">Principles</Link>
</li>
<li>
<Link href="/docs/spec/overview">Patterns</Link>
</li>
<li>
<Link href="/docs/resources">Resource Download</Link>
</li>
</ul>
</Paragraph>
<Paragraph>
Press <Text keyboard>Esc</Text> to exit...
</Paragraph>
<Divider />
<Title></Title>
<Paragraph>
</Paragraph>
<Paragraph>
Ant Design<Text mark></Text>
<Text strong></Text>
</Paragraph>
<Title level={2}></Title>
<Paragraph>
<Text code>Sketch</Text>
<Text code>Axure</Text>
</Paragraph>
<Paragraph>
<ul>
<li>
<Link href="/docs/spec/proximity-cn"></Link>
</li>
<li>
<Link href="/docs/spec/overview-cn"></Link>
</li>
<li>
<Link href="/docs/resources-cn"></Link>
</li>
</ul>
</Paragraph>
<Paragraph>
<blockquote>{blockContent}</blockquote>
<pre>{blockContent}</pre>
</Paragraph>
<Paragraph>
<Text keyboard>Esc</Text>退
</Paragraph>
</Typography>
</ConfigProvider>
);
export default App;

View File

@ -25,6 +25,7 @@ Basic text writing, including headings, body text, lists, and more.
<code src="./demo/ellipsis-middle.tsx">Ellipsis from middle</code>
<code src="./demo/ellipsis-debug.tsx" debug>Ellipsis Debug</code>
<code src="./demo/suffix.tsx">suffix</code>
<code src="./demo/componentToken-debug.tsx" debug>Component Token</code>
## API

View File

@ -26,6 +26,7 @@ coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*LT2jR41Uj2EAAA
<code src="./demo/ellipsis-middle.tsx">省略中间</code>
<code src="./demo/ellipsis-debug.tsx" debug>省略号 Debug</code>
<code src="./demo/suffix.tsx">后缀</code>
<code src="./demo/componentToken-debug.tsx" debug>组件 Token</code>
## API

View File

@ -1,3 +1,4 @@
import { operationUnit } from '../../style';
import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook } from '../../theme/internal';
import {
@ -8,18 +9,18 @@ import {
getResetStyles,
getTitleStyles,
} from './mixins';
import { operationUnit } from '../../style';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
sizeMarginHeadingVerticalStart: number | string;
sizeMarginHeadingVerticalEnd: number | string;
titleMarginTop: number | string;
titleMarginBottom: number | string;
fontWeightStrong: number;
}
export type TypographyToken = FullToken<'Typography'>;
const genTypographyStyle: GenerateStyle<TypographyToken> = (token) => {
const { componentCls, sizeMarginHeadingVerticalStart } = token;
const { componentCls, titleMarginTop } = token;
return {
[componentCls]: {
@ -70,7 +71,7 @@ const genTypographyStyle: GenerateStyle<TypographyToken> = (token) => {
& + h4${componentCls},
& + h5${componentCls}
`]: {
marginTop: sizeMarginHeadingVerticalStart,
marginTop: titleMarginTop,
},
[`
@ -90,7 +91,7 @@ const genTypographyStyle: GenerateStyle<TypographyToken> = (token) => {
+ h4,
+ h5
`]: {
marginTop: sizeMarginHeadingVerticalStart,
marginTop: titleMarginTop,
},
},
@ -122,7 +123,12 @@ const genTypographyStyle: GenerateStyle<TypographyToken> = (token) => {
};
// ============================== Export ==============================
export default genComponentStyleHook('Typography', (token) => [genTypographyStyle(token)], {
sizeMarginHeadingVerticalStart: '1.2em',
sizeMarginHeadingVerticalEnd: '0.5em',
});
export default genComponentStyleHook(
'Typography',
(token) => [genTypographyStyle(token)],
(token) => ({
titleMarginTop: '1.2em',
titleMarginBottom: '0.5em',
fontWeightStrong: token.fontWeightStrong,
}),
);

View File

@ -11,8 +11,8 @@ import { gold } from '@ant-design/colors';
import type { CSSObject } from '@ant-design/cssinjs';
import type { TypographyToken } from '.';
import { initInputToken } from '../../input/style';
import type { GenerateStyle } from '../../theme/internal';
import { operationUnit } from '../../style';
import type { GenerateStyle } from '../../theme/internal';
// eslint-disable-next-line import/prefer-default-export
const getTitleStyle = (
@ -21,10 +21,10 @@ const getTitleStyle = (
color: string,
token: TypographyToken,
) => {
const { sizeMarginHeadingVerticalEnd, fontWeightStrong } = token;
const { titleMarginBottom, fontWeightStrong } = token;
return {
marginBottom: sizeMarginHeadingVerticalEnd,
marginBottom: titleMarginBottom,
color,
fontWeight: fontWeightStrong,
fontSize,

View File

@ -277,6 +277,13 @@ This document contains the correspondence between all the less variables related
<!-- ### Tree -->
<!-- ### Typography -->
### Typography
<!-- prettier-ignore -->
| Less variables | Component Token | Note |
| --- | --- | --- |
| `@typography-title-font-weight` | `fontWeightStrong` | Global Token |
| `@typography-title-margin-top` | `titleMarginTop` | - |
| `@typography-title-margin-bottom` | `titleMarginBottom` | - |
<!-- ### Upload -->

View File

@ -275,6 +275,13 @@ title: Less 变量迁移 Design Token
<!-- ### Tree 树形控件 -->
<!-- ### Typography 排版 -->
### Typography 排版
<!-- prettier-ignore -->
| less 变量 | Component Token | 备注 |
| --- | --- | --- |
| `@typography-title-font-weight` | `fontWeightStrong` | 全局 Token |
| `@typography-title-margin-top` | `titleMarginTop` | - |
| `@typography-title-margin-bottom` | `titleMarginBottom` | - |
<!-- ### Upload 上传 -->