Skip to content

Commit

Permalink
Move and refactor react-treeview to use babel
Browse files Browse the repository at this point in the history
Sugar + using webpack's (or babel's at dev time) import parsing. No more
ad-hoc UMD code.
  • Loading branch information
chenglou committed Jul 31, 2015
1 parent 088f9c1 commit bfde3b7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 76 deletions.
76 changes: 0 additions & 76 deletions react-treeview.jsx

This file was deleted.

File renamed without changes.
59 changes: 59 additions & 0 deletions src/react-treeview.jsx
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;

0 comments on commit bfde3b7

Please sign in to comment.