ssc-refer
Version:
React refer component for SSC 3.0
92 lines (79 loc) • 2.2 kB
JavaScript
;
import cx from 'classnames';
import { noop } from 'lodash';
import React from 'react';
import getOptionLabel from './utils/getOptionLabel';
import menuItemContainer from '../containers/menuItemContainer';
var BaseListItem = React.createClass({
displayName: 'BaseListItem',
getDefaultProps: function getDefaultProps() {
return {
onClick: noop
};
},
render: function render() {
var _props = this.props,
active = _props.active,
children = _props.children,
className = _props.className,
disabled = _props.disabled,
labelKey = _props.labelKey;
var label = getOptionLabel(children, labelKey);
var item = void 0;
if (children.isLeaf === 'true') {
item = React.createElement(
'li',
{ className: cx({
'active': active,
'disabled': disabled
}, className) },
React.createElement(
'span',
{ className: 'hoverBackground', onClick: this._handleIsLeaf },
label
)
);
} else {
item = React.createElement(
'li',
{ className: cx({
'active': active,
'disabled': disabled
}, className) },
React.createElement(
'span',
{ className: 'hoverBackground', onClick: this._handleIsLeaf },
label
),
' ',
React.createElement('span', { className: 'glyphicon glyphicon-menu-right' })
);
}
return React.createElement(
'div',
null,
item
);
},
_handleClick: function _handleClick(e) {
var _props2 = this.props,
disabled = _props2.disabled,
onClick = _props2.onClick;
e.preventDefault();
!disabled && onClick(e);
},
_handleIsLeaf: function _handleIsLeaf(e) {
var _props3 = this.props,
children = _props3.children,
changeStatus = _props3.changeStatus;
if (children.isLeaf == 'false') {
e.preventDefault();
this.props.changeStatus(children);
} else {
this._handleClick(e);
}
}
});
var ListItem = menuItemContainer(BaseListItem);
export { BaseListItem };
export default ListItem;