forked from chenglou/react-treeview
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move and refactor react-treeview to use babel
Sugar + using webpack's (or babel's at dev time) import parsing. No more ad-hoc UMD code.
- Loading branch information
Showing
3 changed files
with
59 additions
and
76 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, {PropTypes} from 'react'; | ||
|
||
const TreeView = React.createClass({ | ||
propTypes: { | ||
collapsed: PropTypes.bool, | ||
defaultCollapsed: PropTypes.bool, | ||
nodeLabel: PropTypes.node.isRequired, | ||
}, | ||
|
||
getInitialState() { | ||
return {collapsed: this.props.defaultCollapsed}; | ||
}, | ||
|
||
handleClick(...args) { | ||
this.setState({collapsed: !this.state.collapsed}); | ||
if (this.props.onClick) { | ||
this.props.onClick(...args); | ||
} | ||
}, | ||
|
||
render() { | ||
const { | ||
collapsed = this.state.collapsed, | ||
className = '', | ||
nodeLabel, | ||
children, | ||
...rest, | ||
} = this.props; | ||
|
||
let arrowClassName = 'tree-view_arrow'; | ||
let containerClassName = 'tree-view_children'; | ||
if (collapsed) { | ||
arrowClassName += ' tree-view_arrow-collapsed'; | ||
containerClassName += ' tree-view_children-collapsed'; | ||
} | ||
|
||
const arrow = | ||
<div | ||
{...rest} | ||
className={className + ' ' + arrowClassName} | ||
onClick={this.handleClick}> | ||
▾ | ||
</div>; | ||
|
||
return ( | ||
<div className="tree-view"> | ||
<div className="tree-view_item"> | ||
{arrow} | ||
{nodeLabel} | ||
</div> | ||
<div className={containerClassName}> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
}, | ||
}); | ||
|
||
export default TreeView; |