Skip to content

Custom collapse icon #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions dist/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ var Node = React.createClass({

renderCollapse: function renderCollapse() {
var index = this.props.index;
var renderCollapse = this.props.renderCollapse;

if (index.children && index.children.length) {
var collapsed = index.node.collapsed;

return React.createElement('span', {
className: cx('collapse', collapsed ? 'caret-right' : 'caret-down'),
onMouseDown: function onMouseDown(e) {
e.stopPropagation();
return React.createElement(
'span',
{
onMouseDown: function onMouseDown(e) {
e.stopPropagation();
},
onClick: this.handleCollapse
},
onClick: this.handleCollapse });
renderCollapse(collapsed)
);
}

return null;
Expand Down Expand Up @@ -47,7 +52,8 @@ var Node = React.createClass({
dragging: dragging,
paddingLeft: _this.props.paddingLeft,
onCollapse: _this.props.onCollapse,
onDragStart: _this.props.onDragStart
onDragStart: _this.props.onDragStart,
renderCollapse: _this.props.renderCollapse
});
})
);
Expand All @@ -71,7 +77,7 @@ var Node = React.createClass({
'div',
{ className: 'inner', ref: 'inner', onMouseDown: this.handleMouseDown },
this.renderCollapse(),
tree.renderNode(node)
tree.renderNode(node, index.id)
),
this.renderChildren()
);
Expand Down
6 changes: 4 additions & 2 deletions dist/react-ui-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ module.exports = React.createClass({
React.createElement(Node, {
tree: tree,
index: draggingIndex,
paddingLeft: this.props.paddingLeft
paddingLeft: this.props.paddingLeft,
renderCollapse: this.props.renderCollapse
})
);
}
Expand All @@ -83,7 +84,8 @@ module.exports = React.createClass({
paddingLeft: this.props.paddingLeft,
onDragStart: this.dragStart,
onCollapse: this.toggleCollapse,
dragging: dragging && dragging.id
dragging: dragging && dragging.id,
renderCollapse: this.props.renderCollapse
})
);
},
Expand Down
11 changes: 11 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ var App = React.createClass({
});
},

renderCollapse(collapsed) {
return (
<span
className={cx('collapse', collapsed ? 'caret-right' : 'caret-down')}
onMouseDown={function(e) {e.stopPropagation()}}
onClick={this.handleCollapse}>
</span>
)
},

render() {
return (
<div className="app">
Expand All @@ -42,6 +52,7 @@ var App = React.createClass({
onChange={this.handleChange}
isNodeCollapsed={this.isNodeCollapsed}
renderNode={this.renderNode}
renderCollapse={this.renderCollapse}
/>
</div>
<div className="inspector">
Expand Down
9 changes: 6 additions & 3 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ var Node = React.createClass({

renderCollapse() {
var index = this.props.index;
var renderCollapse = this.props.renderCollapse;

if(index.children && index.children.length) {
var collapsed = index.node.collapsed;

return (
<span
className={cx('collapse', collapsed ? 'caret-right' : 'caret-down')}
onMouseDown={function(e) {e.stopPropagation()}}
onClick={this.handleCollapse}>
onClick={this.handleCollapse}
>
{renderCollapse(collapsed)}
</span>
);
}
Expand Down Expand Up @@ -46,6 +48,7 @@ var Node = React.createClass({
paddingLeft={this.props.paddingLeft}
onCollapse={this.props.onCollapse}
onDragStart={this.props.onDragStart}
renderCollapse={this.props.renderCollapse}
/>
);
})}
Expand All @@ -69,7 +72,7 @@ var Node = React.createClass({
})} style={styles}>
<div className="inner" ref="inner" onMouseDown={this.handleMouseDown}>
{this.renderCollapse()}
{tree.renderNode(node)}
{tree.renderNode(node, index.id)}
</div>
{this.renderChildren()}
</div>
Expand Down
2 changes: 2 additions & 0 deletions lib/react-ui-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = React.createClass({
tree={tree}
index={draggingIndex}
paddingLeft={this.props.paddingLeft}
renderCollapse={this.props.renderCollapse}
/>
</div>
);
Expand All @@ -87,6 +88,7 @@ module.exports = React.createClass({
onDragStart={this.dragStart}
onCollapse={this.toggleCollapse}
dragging={dragging && dragging.id}
renderCollapse={this.props.renderCollapse}
/>
</div>
);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "react-ui-tree",
"version": "2.6.0",
"version": "2.6.2",
"description": "React tree component",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server -c --port=8888",
"build": "make",
"deploy": "npm run build && github-pages-deploy",
"test": "mocha"
"test": "mocha",
"upgrade:version": "npm run build && npm version patch && git push && npm publish"
},
"github-pages-deploy": {
"src": "example"
Expand Down