11import React , { ReactNode , useState } from 'react' ;
22import { QuestionCircleOutlined , UpOutlined } from '@ant-design/icons' ;
3- import { Tooltip , TooltipProps } from 'antd' ;
3+ import { Tooltip } from 'antd' ;
44import classNames from 'classnames' ;
55
6+ import { LabelTooltipType , toTooltipProps } from '../utils' ;
67import './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-
229export declare type SizeType = 'small' | 'middle' | 'large' ;
2310
2411function 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+
6556const 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 >
0 commit comments