mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
feat: Support label & content style of Desc (#27897)
* feat: Support label & content style of Desc * test: Update snasphot * docs: fix desc
This commit is contained in:
parent
e18c13940f
commit
093a458026
@ -11,6 +11,8 @@ export interface CellProps {
|
|||||||
className?: string;
|
className?: string;
|
||||||
component: string;
|
component: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
|
labelStyle?: React.CSSProperties;
|
||||||
|
contentStyle?: React.CSSProperties;
|
||||||
bordered?: boolean;
|
bordered?: boolean;
|
||||||
label?: React.ReactNode;
|
label?: React.ReactNode;
|
||||||
content?: React.ReactNode;
|
content?: React.ReactNode;
|
||||||
@ -23,6 +25,8 @@ const Cell: React.FC<CellProps> = ({
|
|||||||
span,
|
span,
|
||||||
className,
|
className,
|
||||||
style,
|
style,
|
||||||
|
labelStyle,
|
||||||
|
contentStyle,
|
||||||
bordered,
|
bordered,
|
||||||
label,
|
label,
|
||||||
content,
|
content,
|
||||||
@ -60,11 +64,16 @@ const Cell: React.FC<CellProps> = ({
|
|||||||
className={classNames(`${itemPrefixCls}-item-label`, {
|
className={classNames(`${itemPrefixCls}-item-label`, {
|
||||||
[`${itemPrefixCls}-item-no-colon`]: !colon,
|
[`${itemPrefixCls}-item-no-colon`]: !colon,
|
||||||
})}
|
})}
|
||||||
|
style={labelStyle}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{content && <span className={classNames(`${itemPrefixCls}-item-content`)}>{content}</span>}
|
{content && (
|
||||||
|
<span className={classNames(`${itemPrefixCls}-item-content`)} style={contentStyle}>
|
||||||
|
{content}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Component>
|
</Component>
|
||||||
);
|
);
|
||||||
|
@ -5,6 +5,8 @@ export interface DescriptionsItemProps {
|
|||||||
className?: string;
|
className?: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
label?: React.ReactNode;
|
label?: React.ReactNode;
|
||||||
|
labelStyle?: React.CSSProperties;
|
||||||
|
contentStyle?: React.CSSProperties;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
span?: number;
|
span?: number;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ function renderCells(
|
|||||||
prefixCls: itemPrefixCls = prefixCls,
|
prefixCls: itemPrefixCls = prefixCls,
|
||||||
className,
|
className,
|
||||||
style,
|
style,
|
||||||
|
labelStyle,
|
||||||
|
contentStyle,
|
||||||
span = 1,
|
span = 1,
|
||||||
},
|
},
|
||||||
key,
|
key,
|
||||||
@ -35,6 +37,8 @@ function renderCells(
|
|||||||
key={`${type}-${key || index}`}
|
key={`${type}-${key || index}`}
|
||||||
className={className}
|
className={className}
|
||||||
style={style}
|
style={style}
|
||||||
|
labelStyle={labelStyle}
|
||||||
|
contentStyle={contentStyle}
|
||||||
span={span}
|
span={span}
|
||||||
colon={colon}
|
colon={colon}
|
||||||
component={component}
|
component={component}
|
||||||
@ -50,7 +54,7 @@ function renderCells(
|
|||||||
<Cell
|
<Cell
|
||||||
key={`label-${key || index}`}
|
key={`label-${key || index}`}
|
||||||
className={className}
|
className={className}
|
||||||
style={style}
|
style={{ ...style, ...labelStyle }}
|
||||||
span={1}
|
span={1}
|
||||||
colon={colon}
|
colon={colon}
|
||||||
component={component[0]}
|
component={component[0]}
|
||||||
@ -61,7 +65,7 @@ function renderCells(
|
|||||||
<Cell
|
<Cell
|
||||||
key={`content-${key || index}`}
|
key={`content-${key || index}`}
|
||||||
className={className}
|
className={className}
|
||||||
style={style}
|
style={{ ...style, ...contentStyle }}
|
||||||
span={span * 2 - 1}
|
span={span * 2 - 1}
|
||||||
component={component[1]}
|
component={component[1]}
|
||||||
itemPrefixCls={itemPrefixCls}
|
itemPrefixCls={itemPrefixCls}
|
||||||
|
@ -811,6 +811,158 @@ exports[`renders ./components/descriptions/demo/size.md correctly 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`renders ./components/descriptions/demo/style.md correctly 1`] = `
|
||||||
|
Array [
|
||||||
|
<div
|
||||||
|
class="ant-descriptions"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-header"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-title"
|
||||||
|
>
|
||||||
|
User Info
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-view"
|
||||||
|
>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr
|
||||||
|
class="ant-descriptions-row"
|
||||||
|
>
|
||||||
|
<td
|
||||||
|
class="ant-descriptions-item"
|
||||||
|
colspan="1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-item-container"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="ant-descriptions-item-label"
|
||||||
|
style="background:red"
|
||||||
|
>
|
||||||
|
Product
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="ant-descriptions-item-content"
|
||||||
|
style="background:green"
|
||||||
|
>
|
||||||
|
Cloud Database
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="ant-descriptions-item"
|
||||||
|
colspan="1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-item-container"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="ant-descriptions-item-label"
|
||||||
|
>
|
||||||
|
Billing Mode
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="ant-descriptions-item-content"
|
||||||
|
>
|
||||||
|
Prepaid
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="ant-descriptions-item"
|
||||||
|
colspan="1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-item-container"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="ant-descriptions-item-label"
|
||||||
|
>
|
||||||
|
Automatic Renewal
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="ant-descriptions-item-content"
|
||||||
|
>
|
||||||
|
YES
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>,
|
||||||
|
<div
|
||||||
|
class="ant-descriptions ant-descriptions-bordered"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-header"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-title"
|
||||||
|
>
|
||||||
|
User Info
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="ant-descriptions-view"
|
||||||
|
>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr
|
||||||
|
class="ant-descriptions-row"
|
||||||
|
>
|
||||||
|
<th
|
||||||
|
class="ant-descriptions-item-label"
|
||||||
|
colspan="1"
|
||||||
|
style="background:red"
|
||||||
|
>
|
||||||
|
Product
|
||||||
|
</th>
|
||||||
|
<td
|
||||||
|
class="ant-descriptions-item-content"
|
||||||
|
colspan="1"
|
||||||
|
style="background:green"
|
||||||
|
>
|
||||||
|
Cloud Database
|
||||||
|
</td>
|
||||||
|
<th
|
||||||
|
class="ant-descriptions-item-label"
|
||||||
|
colspan="1"
|
||||||
|
>
|
||||||
|
Billing Mode
|
||||||
|
</th>
|
||||||
|
<td
|
||||||
|
class="ant-descriptions-item-content"
|
||||||
|
colspan="1"
|
||||||
|
>
|
||||||
|
Prepaid
|
||||||
|
</td>
|
||||||
|
<th
|
||||||
|
class="ant-descriptions-item-label"
|
||||||
|
colspan="1"
|
||||||
|
>
|
||||||
|
Automatic Renewal
|
||||||
|
</th>
|
||||||
|
<td
|
||||||
|
class="ant-descriptions-item-content"
|
||||||
|
colspan="1"
|
||||||
|
>
|
||||||
|
YES
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>,
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`renders ./components/descriptions/demo/text.md correctly 1`] = `
|
exports[`renders ./components/descriptions/demo/text.md correctly 1`] = `
|
||||||
<div
|
<div
|
||||||
class="ant-descriptions"
|
class="ant-descriptions"
|
||||||
|
43
components/descriptions/demo/style.md
Normal file
43
components/descriptions/demo/style.md
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
order: 999
|
||||||
|
title:
|
||||||
|
zh-CN: 自定义 label & wrapper 样式
|
||||||
|
en-US: Customize label & wrapper style
|
||||||
|
debug: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## zh-CN
|
||||||
|
|
||||||
|
自定义 label & wrapper 样式
|
||||||
|
|
||||||
|
## en-US
|
||||||
|
|
||||||
|
Customize label & wrapper style
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
import { Descriptions } from 'antd';
|
||||||
|
|
||||||
|
const labelStyle: React.CSSProperties = { background: 'red' };
|
||||||
|
const contentStyle: React.CSSProperties = { background: 'green' };
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<>
|
||||||
|
<Descriptions title="User Info">
|
||||||
|
<Descriptions.Item label="Product" labelStyle={labelStyle} contentStyle={contentStyle}>
|
||||||
|
Cloud Database
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="Billing Mode">Prepaid</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="Automatic Renewal">YES</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
|
||||||
|
<Descriptions title="User Info" bordered>
|
||||||
|
<Descriptions.Item label="Product" labelStyle={labelStyle} contentStyle={contentStyle}>
|
||||||
|
Cloud Database
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="Billing Mode">Prepaid</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="Automatic Renewal">YES</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
</>,
|
||||||
|
mountNode,
|
||||||
|
);
|
||||||
|
```
|
@ -30,7 +30,10 @@ Commonly displayed on the details page.
|
|||||||
|
|
||||||
| Property | Description | Type | Default | Version |
|
| Property | Description | Type | Default | Version |
|
||||||
| --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- |
|
||||||
|
| contentStyle | Customize label style | CSSProperties | - | 4.9.0 |
|
||||||
| label | The description of the content | ReactNode | - | |
|
| label | The description of the content | ReactNode | - | |
|
||||||
|
| labelStyle | Customize label style | CSSProperties | - | 4.9.0 |
|
||||||
| span | The number of columns included | number | 1 | |
|
| span | The number of columns included | number | 1 | |
|
||||||
|
|
||||||
> The number of span Description.Item. Span={2} takes up the width of two DescriptionItems.
|
> The number of span Description.Item. Span={2} takes up the width of two DescriptionItems.
|
||||||
|
> When both `style` and `labelStyle`(or `contentStyle`) configured, both of them will work. And next one will overwrite first when conflict.
|
||||||
|
@ -31,7 +31,10 @@ cover: https://gw.alipayobjects.com/zos/alicdn/MjtG9_FOI/Descriptions.svg
|
|||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||||
| --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- |
|
||||||
|
| contentStyle | 自定义内容样式 | CSSProperties | - | 4.9.0 |
|
||||||
| label | 内容的描述 | ReactNode | - | |
|
| label | 内容的描述 | ReactNode | - | |
|
||||||
|
| labelStyle | 自定义标签样式 | CSSProperties | - | 4.9.0 |
|
||||||
| span | 包含列的数量 | number | 1 | |
|
| span | 包含列的数量 | number | 1 | |
|
||||||
|
|
||||||
> span 是 Description.Item 的数量。 span={2} 会占用两个 DescriptionItem 的宽度。
|
> span 是 Description.Item 的数量。 span={2} 会占用两个 DescriptionItem 的宽度。
|
||||||
|
> 当同时配置 `style` 和 `labelStyle`(或 `contentStyle`)时,两者会同时作用。样式冲突时,后者会覆盖前者。
|
||||||
|
Loading…
Reference in New Issue
Block a user