Skip to content

Commit 046ae23

Browse files
committed
feat(blockheader): change tooltip to TooltipProps and use toTooltipProps
1 parent 3b5716a commit 046ae23

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

src/blockHeader/demos/addonAfter.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default () => (
99
background={false}
1010
title="分类标题"
1111
addonAfter={<Input placeholder="请输入" />}
12+
tooltip={{ title: '这里展示问号提示' }}
1213
/>
1314
</Space>
1415
);

src/blockHeader/index.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ demo:
2525

2626
### BlockHeader
2727

28-
| 参数 | 说明 | 类型 | 默认值 |
29-
| ----------------- | ---------------------------------- | --------------------------- | -------- |
30-
| title | 标题 | `string` | - |
31-
| addonBefore | 标题前的图标,默认是一个色块 | `React.ReactNode` | - |
32-
| description | 标题提示文案 | `React.ReactNode` | - |
33-
| tooltip | 默认展示问号提示 | `React.ReactNode` | - |
34-
| addonAfter | 标题后的内容 | `React.ReactNode` | - |
35-
| size | 小标题、中标题,默认为中标题 | `small \| middle \| large` | `middle` |
36-
| titleRowClassName | 标题一行的样式类名 | `string` | - |
37-
| titleClassName | 标题的样式类名 | `string` | - |
38-
| background | 是否显示背景 | `boolean` | `true` |
39-
| defaultExpand | 是否默认展开内容 | `boolean` | `true` |
40-
| hasBottom | 是否有默认下边距 16px | `boolean` | `false` |
41-
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `0` |
42-
| children | 展开/收起的内容 | `React.ReactNode` | - |
43-
| onChange | 展开/收起时的回调 | `(expand: boolean) => void` | - |
28+
| 参数 | 说明 | 类型 | 默认值 |
29+
| ----------------- | ---------------------------------- | --------------------------------- | -------- |
30+
| title | 标题 | `string` | - |
31+
| addonBefore | 标题前的图标,默认是一个色块 | `React.ReactNode` | - |
32+
| description | 标题提示文案 | `React.ReactNode` | - |
33+
| tooltip | 默认展示问号提示 | `TooltipProps \| React.ReactNode` | - |
34+
| addonAfter | 标题后的内容 | `React.ReactNode` | - |
35+
| size | 小标题、中标题,默认为中标题 | `small \| middle \| large` | `middle` |
36+
| titleRowClassName | 标题一行的样式类名 | `string` | - |
37+
| titleClassName | 标题的样式类名 | `string` | - |
38+
| background | 是否显示背景 | `boolean` | `true` |
39+
| defaultExpand | 是否默认展开内容 | `boolean` | `true` |
40+
| hasBottom | 是否有默认下边距 16px | `boolean` | `false` |
41+
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `0` |
42+
| children | 展开/收起的内容 | `React.ReactNode` | - |
43+
| onChange | 展开/收起时的回调 | `(expand: boolean) => void` | - |

src/blockHeader/index.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import React, { ReactNode, useState } from 'react';
22
import { QuestionCircleOutlined, UpOutlined } from '@ant-design/icons';
3-
import { Tooltip } from 'antd';
3+
import { Tooltip, TooltipProps } from 'antd';
44
import classNames from 'classnames';
55

66
import './style.scss';
77

8+
function toTooltipProps(tooltip: LabelTooltipType): TooltipProps | null {
9+
if (!tooltip) {
10+
return null;
11+
}
12+
if (typeof tooltip === 'object' && !React.isValidElement(tooltip)) {
13+
return tooltip as TooltipProps;
14+
}
15+
return {
16+
title: tooltip,
17+
};
18+
}
19+
20+
export type LabelTooltipType = TooltipProps | React.ReactNode;
21+
822
export declare type SizeType = 'small' | 'middle' | 'large';
923

1024
export interface IBlockHeaderProps {
@@ -15,7 +29,7 @@ export interface IBlockHeaderProps {
1529
// 标题后的提示说明文字
1630
description?: ReactNode;
1731
// 默认展示为问号的tooltip
18-
tooltip?: ReactNode;
32+
tooltip?: LabelTooltipType;
1933
// 后缀自定义内容块
2034
addonAfter?: ReactNode;
2135
/**
@@ -61,8 +75,10 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
6175

6276
const preTitleRowCls = `${prefixCls}-title-row`;
6377

64-
const questionTooltip = tooltip && (
65-
<Tooltip title={tooltip}>
78+
const tooltipProps = toTooltipProps(tooltip);
79+
80+
const questionTooltip = tooltipProps && (
81+
<Tooltip {...tooltipProps}>
6682
<QuestionCircleOutlined />
6783
</Tooltip>
6884
);

0 commit comments

Comments
 (0)