Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mr-kenhoff/react-treeview
Browse files Browse the repository at this point in the history
…into mr-kenhoff-master

# Conflicts:
#	src/react-treeview.jsx
  • Loading branch information
chenglou committed Jun 25, 2017
2 parents 2338312 + 8675404 commit 17ccd10
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
23 changes: 14 additions & 9 deletions demos/controlled.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@ const dataSource = [
// (http://facebook.github.io/react/docs/forms.html#controlled-components), has
// many benefits. Among others, you can expand/collapse everything (i.e. easily
// trigger those somewhere else).
const Lists = React.createClass({
getInitialState() {
return {
collapsedBookkeeping: dataSource.map(() => false),
class Lists extends React.Component {

constructor(props) {
super(props);

this.state = {
collapsedBookkeeping: dataSource.map(() => false)
};
},
this.handleClick = this.handleClick.bind(this);
this.collapseAll = this.collapseAll.bind(this);
}

handleClick(i) {
let [...collapsedBookkeeping] = this.state.collapsedBookkeeping;
collapsedBookkeeping[i] = !collapsedBookkeeping[i];
this.setState({collapsedBookkeeping: collapsedBookkeeping});
},
}

collapseAll() {
this.setState({
collapsedBookkeeping: this.state.collapsedBookkeeping.map(() => true),
});
},
}

render() {
const collapsedBookkeeping = this.state.collapsedBookkeeping;
Expand All @@ -57,7 +62,7 @@ const Lists = React.createClass({
})}
</div>
);
},
});
}
}

export default Lists;
6 changes: 3 additions & 3 deletions demos/uncontrolled.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const dataSource = [
// For the sake of simplicity, we're gonna use `defaultCollapsed`. Usually, a
// [controlled component](http://facebook.github.io/react/docs/forms.html#controlled-components)
// is preferred.
const CompanyPeople = React.createClass({
class CompanyPeople extends React.Component {
render() {
return (
<div>
Expand All @@ -49,7 +49,7 @@ const CompanyPeople = React.createClass({
})}
</div>
);
},
});
}
}

export default CompanyPeople;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"react-hot-loader": "^1.3.0",
"webpack": "^1.10.1",
"webpack-dev-server": "^1.10.1"
},
"dependencies": {
"prop-types": "^15.5.8"
}
}
24 changes: 15 additions & 9 deletions src/react-treeview.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { PropTypes } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

const TreeView = React.createClass({
class TreeView extends React.Component {
propTypes: {
collapsed: PropTypes.bool,
defaultCollapsed: PropTypes.bool,
Expand All @@ -9,18 +10,23 @@ const TreeView = React.createClass({
itemClassName: PropTypes.string,
childrenClassName: PropTypes.string,
treeViewClassName: PropTypes.string,
},
}

getInitialState() {
return { collapsed: this.props.defaultCollapsed };
},
constructor(props) {
super(props);

this.state = {
collapsed: props.defaultCollapsed
};
this.handleClick = this.handleClick.bind(this);
}

handleClick(...args) {
this.setState({ collapsed: !this.state.collapsed });
if (this.props.onClick) {
this.props.onClick(...args);
}
},
}

render() {
const {
Expand Down Expand Up @@ -61,7 +67,7 @@ const TreeView = React.createClass({
</div>
</div>
);
},
});
}
}

export default TreeView;

0 comments on commit 17ccd10

Please sign in to comment.