Skip to content

Commit 06c4bc4

Browse files
committed
feat(blockheader): use utils tooltip and use BEM style
1 parent b275b5e commit 06c4bc4

File tree

3 files changed

+34
-43
lines changed

3 files changed

+34
-43
lines changed

src/blockHeader/index.tsx

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

6+
import { LabelTooltipType, toTooltipProps } from '../utils';
67
import './style.scss';
78

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 | TooltipProps['title'];
21-
229
export declare type SizeType = 'small' | 'middle' | 'large';
2310

2411
function isControlled(props: IBlockHeaderProps) {
@@ -34,7 +21,7 @@ export interface IBlockHeaderProps {
3421
description?: ReactNode;
3522
/** 默认展示为问号的tooltip */
3623
tooltip?: LabelTooltipType;
37-
// 后缀自定义内容块
24+
/** 后缀自定义内容块 */
3825
addonAfter?: ReactNode;
3926
/**
4027
* 小标题 font-size: 12px; line-height: 32px
@@ -62,12 +49,15 @@ export interface IBlockHeaderProps {
6249
/** 展开/收起时的回调 */
6350
onExpand?: (expand: boolean) => void;
6451
}
52+
53+
const prefixCls = 'dtc-block-header';
54+
const preTitleRowCls = `${prefixCls}__title`;
55+
6556
const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
66-
const prefixCls = 'dtc-block-header';
6757
const {
6858
title,
6959
description = '',
70-
tooltip = '',
60+
tooltip,
7161
size = 'middle',
7262
hasBottom = false,
7363
spaceBottom = 0,
@@ -86,11 +76,9 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
8676

8777
const currentExpand = isControlled(props) ? expand : internalExpand;
8878

89-
const preTitleRowCls = `${prefixCls}__title`;
90-
9179
const tooltipProps = toTooltipProps(tooltip);
9280

93-
const questionTooltip = tooltipProps && (
81+
const questionTooltip = (
9482
<Tooltip {...tooltipProps}>
9583
<QuestionCircleOutlined />
9684
</Tooltip>
@@ -113,21 +101,25 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
113101
[`${preTitleRowCls}--background`]: background,
114102
[`${preTitleRowCls}--pointer`]: children,
115103
})}
116-
onClick={() => handleExpand(!expand)}
104+
onClick={() => handleExpand(!currentExpand)}
117105
>
118106
<div className="title__box">
119107
{addonBefore ? <div className="title__addon-before">{addonBefore}</div> : null}
120108
<div className="title__text">{title}</div>
121-
{questionTooltip ? (
109+
{tooltipProps?.title ? (
122110
<div className={`title__tooltip`}>{questionTooltip}</div>
123111
) : null}
124112
{description ? <div className={`title__description`}>{description}</div> : null}
125113
</div>
126114
{addonAfter && <div className={`title__addon-after`}>{addonAfter}</div>}
127115
{children && (
128116
<div className={`title__collapse`}>
129-
<div className="text">{expand ? '收起' : '展开'}</div>
130-
<UpOutlined className={`icon ${expand ? 'up' : 'down'}`} />
117+
<div className="collapse__text">{currentExpand ? '收起' : '展开'}</div>
118+
<UpOutlined
119+
className={`collapse__icon ${
120+
currentExpand ? 'collapse__icon--up' : 'collapse__icon--down'
121+
}`}
122+
/>
131123
</div>
132124
)}
133125
</div>

src/blockHeader/style.scss

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ $card_prefix: "dtc-block-header";
7272
margin-right: 4px;
7373
font-size: 16px;
7474
color: #B1B4C5;
75+
cursor: pointer;
7576
}
7677
&__text {
7778
color: #3D446E;
@@ -93,18 +94,20 @@ $card_prefix: "dtc-block-header";
9394
align-items: center;
9495
cursor: pointer;
9596
user-select: none;
96-
.text {
97-
font-size: 12px;
98-
margin: 0 4px;
99-
}
100-
.icon {
101-
font-size: 16px;
102-
transition: transform 0.4s;
103-
&.down {
104-
transform: rotate(-180deg);
97+
.collapse {
98+
&__text {
99+
font-size: 12px;
100+
margin: 0 4px;
105101
}
106-
&.up {
107-
transform: rotate(0deg);
102+
&__icon {
103+
font-size: 16px;
104+
transition: transform 0.4s;
105+
&--down {
106+
transform: rotate(-180deg);
107+
}
108+
&--up {
109+
transform: rotate(0deg);
110+
}
108111
}
109112
}
110113
}

src/copy/demos/basic.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@ export default () => {
99
return (
1010
<Space direction="vertical">
1111
<div>
12-
<BlockHeader title="使用 tooltip 对象" showBackground={false} size="small" />
12+
<BlockHeader title="使用 tooltip 对象" background={false} size="small" />
1313
<Copy text={text} tooltip={{ title: '使用 tooltip 对象,复制该文本' }} />
1414
<p>{text}</p>
1515
</div>
1616
<div>
17-
<BlockHeader title="使用 React.ReactNode" showBackground={false} size="small" />
17+
<BlockHeader title="使用 React.ReactNode" background={false} size="small" />
1818
<Copy text={text} tooltip="使用 React.ReactNode,复制该文本" />
1919
<p>{text}</p>
2020
</div>
2121
<div>
22-
<BlockHeader
23-
title={`使用 ()=>React.ReactNode`}
24-
showBackground={false}
25-
size="small"
26-
/>
22+
<BlockHeader title={`使用 ()=>React.ReactNode`} background={false} size="small" />
2723
<Copy text={text} tooltip={() => `使用 ()=>React.ReactNode,复制该文本`} />
2824
<p>{text}</p>
2925
</div>

0 commit comments

Comments
 (0)