From 1c1ebbe36d992494ec3ef37bb0c112833af35003 Mon Sep 17 00:00:00 2001 From: hms181231 Date: Fri, 11 Aug 2023 13:43:44 +0800 Subject: [PATCH] feat: Divider Component Token (#42627) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Divider Component Token * feat: 更改token命名规范 * feat: 增加token demo * test: Update Test Snapshots * feat: token * chore: update * fix: lint * chore: lint * chore: update snapshot --------- Co-authored-by: MadCcc <1075746765@qq.com> --- .../__snapshots__/demo-extend.test.ts.snap | 77 +++++++++++++++++++ .../__tests__/__snapshots__/demo.test.ts.snap | 75 ++++++++++++++++++ components/divider/demo/component-token.md | 7 ++ components/divider/demo/component-token.tsx | 58 ++++++++++++++ components/divider/index.en-US.md | 1 + components/divider/index.zh-CN.md | 1 + components/divider/style/index.ts | 53 +++++++++---- docs/react/migrate-less-variables.en-US.md | 11 ++- docs/react/migrate-less-variables.zh-CN.md | 10 ++- 9 files changed, 278 insertions(+), 15 deletions(-) create mode 100644 components/divider/demo/component-token.md create mode 100644 components/divider/demo/component-token.tsx diff --git a/components/divider/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/divider/__tests__/__snapshots__/demo-extend.test.ts.snap index e232e1f781..e20e15157c 100644 --- a/components/divider/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/divider/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -1,5 +1,82 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`renders components/divider/demo/component-token.tsx extend context correctly 1`] = ` +Array [ +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, +] +`; + +exports[`renders components/divider/demo/component-token.tsx extend context correctly 2`] = `[]`; + exports[`renders components/divider/demo/customize-style.tsx extend context correctly 1`] = ` Array [
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, + , +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo. +

, +] +`; + exports[`renders components/divider/demo/customize-style.tsx correctly 1`] = ` Array [
( + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista + probare, quae sunt a te dicta? Refert tamen, quo modo. +

+ Text +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista + probare, quae sunt a te dicta? Refert tamen, quo modo. +

+ Left Text +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista + probare, quae sunt a te dicta? Refert tamen, quo modo. +

+ Right Text +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista + probare, quae sunt a te dicta? Refert tamen, quo modo. +

+ + Left Text with 0 orientationMargin + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista + probare, quae sunt a te dicta? Refert tamen, quo modo. +

+ + Right Text with 50px orientationMargin + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista + probare, quae sunt a te dicta? Refert tamen, quo modo. +

+
+); + +export default App; diff --git a/components/divider/index.en-US.md b/components/divider/index.en-US.md index a42f90e9a3..76b0a34f71 100644 --- a/components/divider/index.en-US.md +++ b/components/divider/index.en-US.md @@ -25,6 +25,7 @@ A divider line separates different content. Text without heading style Vertical Style Customization +Component Token ## API diff --git a/components/divider/index.zh-CN.md b/components/divider/index.zh-CN.md index c5005e4079..b4d96b0f62 100644 --- a/components/divider/index.zh-CN.md +++ b/components/divider/index.zh-CN.md @@ -26,6 +26,7 @@ group: 分割文字使用正文样式 垂直分割线 样式自定义 +组件 Token ## API diff --git a/components/divider/style/index.ts b/components/divider/style/index.ts index adb3c87255..11ad427643 100644 --- a/components/divider/style/index.ts +++ b/components/divider/style/index.ts @@ -1,22 +1,45 @@ import type { CSSObject } from '@ant-design/cssinjs'; +import type { CSSProperties } from 'react'; import { resetComponent } from '../../style'; import type { FullToken, GenerateStyle } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal'; /** Component only token. Which will handle additional calculation of alias token */ export interface ComponentToken { - sizePaddingEdgeHorizontal: number; + /** + * @desc 文本横向内间距 + * @descEN Horizontal padding of text + */ + textPaddingInline: CSSProperties['paddingInline']; + /** + * @desc 文本与边缘距离,取值 0 ~ 1 + * @descEN Distance between text and edge, which should be a number between 0 and 1. + */ + orientationMargin: number; + /** + * @desc 纵向分割线的横向外间距 + * @descEN Horizontal margin of vertical Divider + */ + verticalMarginInline: CSSProperties['marginInline']; } interface DividerToken extends FullToken<'Divider'> { - dividerVerticalGutterMargin: number; + sizePaddingEdgeHorizontal: number; dividerHorizontalWithTextGutterMargin: number; dividerHorizontalGutterMargin: number; } // ============================== Shared ============================== const genSharedDividerStyle: GenerateStyle = (token): CSSObject => { - const { componentCls, sizePaddingEdgeHorizontal, colorSplit, lineWidth } = token; + const { + componentCls, + sizePaddingEdgeHorizontal, + colorSplit, + lineWidth, + textPaddingInline, + orientationMargin, + verticalMarginInline, + } = token; return { [componentCls]: { @@ -29,7 +52,8 @@ const genSharedDividerStyle: GenerateStyle = (token): CSSObject => top: '-0.06em', display: 'inline-block', height: '0.9em', - margin: `0 ${token.dividerVerticalGutterMargin}px`, + marginInline: verticalMarginInline, + marginBlock: 0, verticalAlign: 'middle', borderTop: 0, borderInlineStart: `${lineWidth}px solid ${colorSplit}`, @@ -68,27 +92,28 @@ const genSharedDividerStyle: GenerateStyle = (token): CSSObject => [`&-horizontal${componentCls}-with-text-left`]: { '&::before': { - width: '5%', + width: `${orientationMargin * 100}%`, }, '&::after': { - width: '95%', + width: `${100 - orientationMargin * 100}%`, }, }, [`&-horizontal${componentCls}-with-text-right`]: { '&::before': { - width: '95%', + width: `${100 - orientationMargin * 100}%`, }, '&::after': { - width: '5%', + width: `${orientationMargin * 100}%`, }, }, [`${componentCls}-inner-text`]: { display: 'inline-block', - padding: '0 1em', + paddingBlock: 0, + paddingInline: textPaddingInline, }, '&-dashed': { @@ -155,13 +180,15 @@ export default genComponentStyleHook( 'Divider', (token) => { const dividerToken = mergeToken(token, { - dividerVerticalGutterMargin: token.marginXS, dividerHorizontalWithTextGutterMargin: token.margin, dividerHorizontalGutterMargin: token.marginLG, + sizePaddingEdgeHorizontal: 0, }); return [genSharedDividerStyle(dividerToken)]; }, - { - sizePaddingEdgeHorizontal: 0, - }, + (token) => ({ + textPaddingInline: '1em', + orientationMargin: 0.05, + verticalMarginInline: token.marginXS, + }), ); diff --git a/docs/react/migrate-less-variables.en-US.md b/docs/react/migrate-less-variables.en-US.md index a361053e45..26b9d0776f 100644 --- a/docs/react/migrate-less-variables.en-US.md +++ b/docs/react/migrate-less-variables.en-US.md @@ -220,7 +220,16 @@ export default App; | `@descriptions-item-label-colon-margin-left` | `colonMarginLeft` | - | | `@descriptions-extra-color` | `extraColor` | - | - +### Divider + + +| Less variables | Component Token | Note | +| --- | --- | --- | +| --- | --- | --- | +| `@divider-text-padding` | `textPaddingInline` | - | +| `@divider-orientation-margin` | `orientationMargin` | - | +| `@divider-color` | `colorSplit` | Global Token | +| `@divider-vertical-gutter` | `verticalMarginInline` | - | ### Drawer diff --git a/docs/react/migrate-less-variables.zh-CN.md b/docs/react/migrate-less-variables.zh-CN.md index b813da1d0c..05b06b30e4 100644 --- a/docs/react/migrate-less-variables.zh-CN.md +++ b/docs/react/migrate-less-variables.zh-CN.md @@ -218,7 +218,15 @@ export default App; | `@descriptions-item-label-colon-margin-left` | `colonMarginLeft` | - | | `@descriptions-extra-color` | `extraColor` | - | - +### Divider 分割线 + + +| less 变量 | Component Token | 备注 | +| --- | --- | --- | +| `@divider-text-padding` | `textPaddingInline` | - | +| `@divider-orientation-margin` | `orientationMargin` | - | +| `@divider-color` | `colorSplit` | 全局 Token | +| `@divider-vertical-gutter` | `verticalMarginInline` | - | ### Drawer 抽屉