1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import Pop from 'pop';
import Icon from 'icon';

export default class BlockHeader extends Component {
static propTypes = {
className: PropTypes.string, // 自定义类名
title: PropTypes.string.isRequired, // 标题
tooltip: PropTypes.node, // pop显示内容
content: PropTypes.node, // 自定义content
position: PropTypes.string, // pop posotion
prefix: PropTypes.string // 自定义前缀
};

static defaultProps = {
prefix: 'zent',
className: '',
position: 'top-right',
tooltip: '',
content: ''
};

render() {
const {
prefix,
content,
title,
tooltip,
position,
className,
children
} = this.props;
return (
<div className={cx(`${prefix}-block-header`, className)}>
{title && (
<div className={`${prefix}-block-header__left`}>
<h3>{title}</h3>
</div>
)}
<div className={`${prefix}-block-header__content`}>
{/* 把传入的 content 和 children 都渲染出来 */}
{content && content}
{children && children}
</div>
<div className={`${prefix}-block-header__pop`}>
{tooltip && (
<Pop
trigger="hover"
centerArrow
position={position}
content={
<p className={`${prefix}-block-header__tooltip`}>{tooltip}</p>
}
wrapperClassName={`${prefix}-block-header__tooltip-trigger`}
>
<Icon type="help-circle" />
</Pop>
)}
</div>
</div>
);
}
}