var React = require('react'); import history from 'utils/History'; import styles from './Tree.scss'; import classNames from 'classnames/bind'; const cx = classNames.bind(styles); var Node = React.createClass({ displayName: 'UITreeNode', renderCollapse() { var index = this.props.index; if(index.children && index.children.length) { var collapsed = index.node.collapsed; return ( ); } return null; }, renderChildren() { var index = this.props.index; var tree = this.props.tree; var dragging = this.props.dragging; if(index.children && index.children.length) { var childrenStyles = {}; if (!this.props.rootNode) { if(index.node.collapsed) childrenStyles.display = 'none'; childrenStyles['paddingLeft'] = this.props.paddingLeft + 'px'; } return (
{index.children.map((child) => { var childIndex = tree.getIndex(child); return ( ); })}
); } return null; }, render() { var tree = this.props.tree; var index = this.props.index; var dragging = this.props.dragging; var node = index.node; var style = {}; return (
e.stopPropagation() : this.handleMouseDown} > {!this.props.rootNode && this.renderCollapse()} { history.push(node.url) }} > { node.title }
{this.renderChildren()}
); }, handleCollapse(e) { e.stopPropagation(); var nodeId = this.props.index.id; if(this.props.onCollapse) this.props.onCollapse(nodeId); }, handleMouseDown(e) { var nodeId = this.props.index.id; var dom = this.refs.inner; if(this.props.onDragStart) { this.props.onDragStart(nodeId, dom, e); } } }); module.exports = Node;