Skip to content

Commit 0d308cd

Browse files
committed
Sets defaultProps for transitions, stabilises unmounting
1 parent da8f3cd commit 0d308cd

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/Node/index.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ export default class Node extends React.Component {
4242
return transform;
4343
}
4444

45-
applyTransform(transform, done) {
46-
select(this.node)
47-
.transition()
48-
.duration(500)
49-
.attr('transform', transform)
50-
.each('end', done);
45+
applyTransform(transform, done = () => {}) {
46+
const { enabled, duration } = this.props.transitions;
47+
if (enabled) {
48+
select(this.node)
49+
.transition()
50+
.duration(duration)
51+
.attr('transform', transform)
52+
.each('end', done);
53+
} else {
54+
done();
55+
}
5156
}
5257

5358
componentWillLeave(done) {
@@ -64,7 +69,11 @@ export default class Node extends React.Component {
6469
}
6570

6671
render() {
67-
const { nodeData, depthFactor } = this.props;
72+
const { nodeData, depthFactor, transitions } = this.props;
73+
const transform = transitions.enabled ?
74+
this.state.transform :
75+
this.setTransformOrientation(nodeData.x, nodeData.y);
76+
6877

6978
if (depthFactor) {
7079
nodeData.y = nodeData.depth * depthFactor;
@@ -74,7 +83,7 @@ export default class Node extends React.Component {
7483
id={nodeData.id}
7584
ref={(n) => { this.node = n; }}
7685
className={nodeData._children ? 'nodeBase' : 'leafNodeBase'}
77-
transform={this.state.transform}
86+
transform={transform}
7887
onClick={this.handleClick}
7988
>
8089
<text
@@ -111,6 +120,7 @@ export default class Node extends React.Component {
111120
}
112121

113122
Node.defaultProps = {
123+
depthFactor: undefined,
114124
circleRadius: 10,
115125
circleStyle: {
116126
stroke: '#000',
@@ -124,14 +134,15 @@ Node.defaultProps = {
124134
},
125135
};
126136

127-
/* eslint-disable*/
137+
/* eslint-disable */
128138
Node.propTypes = {
129139
nodeData: PropTypes.object.isRequired,
130140
orientation: PropTypes.oneOf([
131141
'horizontal',
132142
'vertical',
133143
]).isRequired,
134-
onClick: PropTypes.func,
144+
transitions: PropTypes.object.isRequired,
145+
onClick: PropTypes.func.isRequired,
135146
depthFactor: PropTypes.number,
136147
primaryLabel: PropTypes.string,
137148
primaryLabelStyle: PropTypes.object,

src/Tree/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export default class Tree extends React.Component {
210210
}
211211

212212
render() {
213-
const { orientation, translate, pathFunc, depthFactor } = this.props;
213+
const { orientation, translate, pathFunc, depthFactor, transitions } = this.props;
214214
const { nodes, links } = this.generateTree();
215215
return (
216216
<div className="treeContainer">
@@ -224,6 +224,7 @@ export default class Tree extends React.Component {
224224
key={nodeData.id}
225225
orientation={orientation}
226226
depthFactor={depthFactor}
227+
transitions={transitions}
227228
textAnchor="start"
228229
nodeData={nodeData}
229230
primaryLabel={nodeData.name}
@@ -251,6 +252,10 @@ Tree.defaultProps = {
251252
orientation: 'horizontal',
252253
translate: { x: 0, y: 0 },
253254
pathFunc: 'diagonal',
255+
transitions: {
256+
enabled: false,
257+
duration: 500,
258+
},
254259
depthFactor: undefined,
255260
collapsible: true,
256261
initialDepth: undefined,
@@ -272,6 +277,10 @@ Tree.propTypes = {
272277
'diagonal',
273278
'elbow',
274279
]),
280+
transitions: PropTypes.shape({
281+
enabled: PropTypes.bool.isRequired,
282+
duration: PropTypes.number,
283+
}),
275284
depthFactor: PropTypes.number,
276285
collapsible: PropTypes.bool,
277286
initialDepth: PropTypes.number,

0 commit comments

Comments
 (0)