1 | import React, { Component } from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import shallowequal from 'shallowequal';
|
4 |
|
5 | const propTypes = {
|
6 | record: PropTypes.object,
|
7 | clsPrefix: PropTypes.string,
|
8 | expandable: PropTypes.any,
|
9 | expanded: PropTypes.bool,
|
10 | needIndentSpaced: PropTypes.bool,
|
11 | onExpand: PropTypes.func,
|
12 | };
|
13 |
|
14 | class ExpandIcon extends Component{
|
15 | constructor(props){
|
16 | super(props);
|
17 | }
|
18 | shouldComponentUpdate(nextProps) {
|
19 | return !shallowequal(nextProps, this.props);
|
20 | }
|
21 |
|
22 | onExpand = (status, record, e) => {
|
23 | const { onExpand } = this.props;
|
24 | e.stopPropagation();
|
25 | onExpand(status, record, e);
|
26 | };
|
27 | render() {
|
28 | const { expandable, clsPrefix, onExpand, needIndentSpaced, expanded, record, isHiddenExpandIcon,expandedIcon,collapsedIcon } = this.props;
|
29 | if (expandable && !isHiddenExpandIcon) {
|
30 | const expandClassName = expanded ? 'expanded' : 'collapsed';
|
31 | let currentIcon = <span
|
32 | className={`${clsPrefix}-expand-icon ${clsPrefix}-${expandClassName}`}
|
33 | />;
|
34 | if(expanded && expandedIcon){
|
35 | currentIcon = expandedIcon;
|
36 | }else if(!expanded && collapsedIcon){
|
37 | currentIcon = collapsedIcon;
|
38 | }
|
39 | return (<span onClick={(e) => this.onExpand(!expanded, record, e)} className='expand-icon-con'>{currentIcon}</span>);
|
40 | } else if (needIndentSpaced || isHiddenExpandIcon) {
|
41 | return <span className={`${clsPrefix}-expand-icon ${clsPrefix}-spaced`} />;
|
42 | }
|
43 | return null;
|
44 | }
|
45 | };
|
46 |
|
47 | ExpandIcon.propTypes = propTypes;
|
48 |
|
49 | export default ExpandIcon;
|