UNPKG

1.64 kBJavaScriptView Raw
1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
3import shallowequal from 'shallowequal';
4
5const 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
14class 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
47ExpandIcon.propTypes = propTypes;
48
49export default ExpandIcon;