From a211756e6b443ec7f68d64de89938043f70f5729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Wed, 30 Dec 2020 17:08:43 +0800 Subject: [PATCH] feat: desc support root level label & content style (#28613) --- components/descriptions/Row.tsx | 29 +++- .../__tests__/__snapshots__/demo.test.js.snap | 159 ++++++++++++++++++ components/descriptions/demo/style.md | 55 ++++-- components/descriptions/index.en-US.md | 2 + components/descriptions/index.tsx | 83 +++++---- components/descriptions/index.zh-CN.md | 2 + 6 files changed, 274 insertions(+), 56 deletions(-) diff --git a/components/descriptions/Row.tsx b/components/descriptions/Row.tsx index 3d7662e1de..02f86017c5 100644 --- a/components/descriptions/Row.tsx +++ b/components/descriptions/Row.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { DescriptionsItemProps } from './Item'; import Cell from './Cell'; +import { DescriptionsContext, DescriptionsContextProps } from '.'; interface CellConfig { component: string | [string, string]; @@ -12,7 +13,14 @@ interface CellConfig { function renderCells( items: React.ReactElement[], { colon, prefixCls, bordered }: RowProps, - { component, type, showLabel, showContent }: CellConfig, + { + component, + type, + showLabel, + showContent, + labelStyle: rootLabelStyle, + contentStyle: rootContentStyle, + }: CellConfig & DescriptionsContextProps, ) { return items.map( ( @@ -37,8 +45,8 @@ function renderCells( key={`${type}-${key || index}`} className={className} style={style} - labelStyle={labelStyle} - contentStyle={contentStyle} + labelStyle={{ ...rootLabelStyle, ...labelStyle }} + contentStyle={{ ...rootContentStyle, ...contentStyle }} span={span} colon={colon} component={component} @@ -54,7 +62,7 @@ function renderCells( = props => { + const descContext = React.useContext(DescriptionsContext); + const { prefixCls, vertical, row, index, bordered } = props; if (vertical) { return ( <> - {renderCells(row, props, { component: 'th', type: 'label', showLabel: true })} + {renderCells(row, props, { + component: 'th', + type: 'label', + showLabel: true, + ...descContext, + })} {renderCells(row, props, { component: 'td', type: 'content', showContent: true, + ...descContext, })} @@ -112,6 +128,7 @@ const Row: React.FC = props => { type: 'item', showLabel: true, showContent: true, + ...descContext, })} ); diff --git a/components/descriptions/__tests__/__snapshots__/demo.test.js.snap b/components/descriptions/__tests__/__snapshots__/demo.test.js.snap index 2ffd3aed1b..1545113e7a 100644 --- a/components/descriptions/__tests__/__snapshots__/demo.test.js.snap +++ b/components/descriptions/__tests__/__snapshots__/demo.test.js.snap @@ -960,6 +960,165 @@ Array [ , +