Skip to content

Commit 90da59c

Browse files
committed
Simplify transitions API by only exposing transitionDuration
1 parent 4678ca9 commit 90da59c

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

src/Link/index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import './style.css';
55

66
export default class Link extends React.PureComponent {
77

8+
constructor(props) {
9+
super(props);
10+
this.state = {
11+
initialStyle: {
12+
opacity: 0,
13+
},
14+
};
15+
}
16+
817
componentDidMount() {
918
this.applyOpacity(1);
1019
}
@@ -14,16 +23,13 @@ export default class Link extends React.PureComponent {
1423
}
1524

1625
applyOpacity(opacity, done = () => {}) {
17-
const { enabled, duration } = this.props.transitions;
18-
if (enabled) {
19-
select(this.link)
20-
.transition()
21-
.duration(duration)
22-
.style('opacity', opacity)
23-
.each('end', done);
24-
} else {
25-
done();
26-
}
26+
const { transitionDuration } = this.props;
27+
28+
select(this.link)
29+
.transition()
30+
.duration(transitionDuration)
31+
.style('opacity', opacity)
32+
.each('end', done);
2733
}
2834

2935
diagonalPath(linkData, orientation) {
@@ -59,6 +65,7 @@ export default class Link extends React.PureComponent {
5965
return (
6066
<path
6167
ref={(l) => { this.link = l; }}
68+
style={this.state.initialStyle}
6269
className="linkBase"
6370
d={this.expandPath()}
6471
/>
@@ -76,5 +83,5 @@ Link.propTypes = {
7683
'diagonal',
7784
'elbow',
7885
]).isRequired,
79-
transitions: PropTypes.object.isRequired,
86+
transitionDuration: PropTypes.number.isRequired,
8087
};

src/Node/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@ export default class Node extends React.Component {
4747
}
4848

4949
applyTransform(transform, opacity = 1, done = () => {}) {
50-
const { enabled, duration } = this.props.transitions;
51-
if (enabled) {
52-
select(this.node)
53-
.transition()
54-
.duration(duration)
55-
.attr('transform', transform)
56-
.style('opacity', opacity)
57-
.each('end', done);
58-
} else {
59-
done();
60-
}
50+
const { transitionDuration } = this.props;
51+
52+
select(this.node)
53+
.transition()
54+
.duration(transitionDuration)
55+
.attr('transform', transform)
56+
.style('opacity', opacity)
57+
.each('end', done);
6158
}
6259

6360
handleClick() {
@@ -71,13 +68,12 @@ export default class Node extends React.Component {
7168
const transform = this.setTransformOrientation(originX, originY);
7269

7370
this.applyTransform(transform, 0, done);
74-
// this.applyOpacity(0, done);
7571
}
7672

7773
render() {
78-
const { nodeData, transitions } = this.props;
74+
const { nodeData, transitionDuration } = this.props;
7975

80-
const transform = transitions.enabled && this.state.transform ?
76+
const transform = transitionDuration && transitionDuration > 0 ?
8177
this.state.transform :
8278
this.setTransformOrientation(nodeData.x, nodeData.y);
8379

@@ -144,7 +140,7 @@ Node.propTypes = {
144140
'horizontal',
145141
'vertical',
146142
]).isRequired,
147-
transitions: PropTypes.object.isRequired,
143+
transitionDuration: PropTypes.number.isRequired,
148144
onClick: PropTypes.func.isRequired,
149145
depthFactor: PropTypes.number,
150146
primaryLabel: PropTypes.string,

src/Tree/index.js

Lines changed: 5 additions & 11 deletions
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, transitions } = this.props;
213+
const { orientation, translate, pathFunc, depthFactor, transitionDuration } = this.props;
214214
const { nodes, links } = this.generateTree();
215215

216216
return (
@@ -225,7 +225,7 @@ export default class Tree extends React.Component {
225225
key={nodeData.id}
226226
orientation={orientation}
227227
depthFactor={depthFactor}
228-
transitions={transitions}
228+
transitionDuration={transitionDuration}
229229
textAnchor="start"
230230
nodeData={nodeData}
231231
primaryLabel={nodeData.name}
@@ -240,7 +240,7 @@ export default class Tree extends React.Component {
240240
orientation={orientation}
241241
pathFunc={pathFunc}
242242
linkData={linkData}
243-
transitions={transitions}
243+
transitionDuration={transitionDuration}
244244
/>
245245
)}
246246
</TransitionGroup>
@@ -254,10 +254,7 @@ Tree.defaultProps = {
254254
orientation: 'horizontal',
255255
translate: { x: 0, y: 0 },
256256
pathFunc: 'diagonal',
257-
transitions: {
258-
enabled: false,
259-
duration: 500,
260-
},
257+
transitionDuration: 500,
261258
depthFactor: undefined,
262259
collapsible: true,
263260
initialDepth: undefined,
@@ -279,10 +276,7 @@ Tree.propTypes = {
279276
'diagonal',
280277
'elbow',
281278
]),
282-
transitions: PropTypes.shape({
283-
enabled: PropTypes.bool.isRequired,
284-
duration: PropTypes.number,
285-
}),
279+
transitionDuration: PropTypes.number,
286280
depthFactor: PropTypes.number,
287281
collapsible: PropTypes.bool,
288282
initialDepth: PropTypes.number,

0 commit comments

Comments
 (0)