Skip to content

Commit edf4d24

Browse files
committed
Merge pull request facebook#3761 from alexpien/CustomClassesForReactCSSTransitionGroup
Custom class names in ReactCSSTransitionGroup
2 parents 6eb5a15 + f1e524b commit edf4d24

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

docs/docs/10.1-animation.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,35 @@ At the initial mount, all children of the `ReactCSSTransitionGroup` will `appear
117117
>
118118
> The prop `transitionAppear` was added to `ReactCSSTransitionGroup` in version `0.13`. To maintain backwards compatibility, the default value is set to `false`.
119119
120+
### Custom Classes
121+
122+
It is also possible to use custom class names for each of the steps in your transitions. Instead of passing a string into transitionName you can pass an object containing either the `enter` and `leave` class names, or an object containing the `enter`, `enter-active`, `leave-active`, and `leave` class names. If only the enter and leave classes are provided, the enter-active and leave-active classes will be determined by appending '-active' to the end of the class name. Here are two examples using custom classes:
123+
124+
```javascript
125+
...
126+
<ReactCSSTransitionGroup
127+
transitionName={
128+
enter: 'enter',
129+
enterActive: 'enterActive',
130+
leave: 'leave',
131+
leaveActive: 'leaveActive',
132+
appear: 'appear',
133+
appearActive: 'appearActive'
134+
}>
135+
{item}
136+
</ReactCSSTransitionGroup>
137+
138+
<ReactCSSTransitionGroup
139+
transitionName={
140+
enter: 'enter',
141+
leave: 'leave',
142+
appear: 'appear'
143+
}>
144+
{item2}
145+
</ReactCSSTransitionGroup>
146+
...
147+
```
148+
120149
### Animation Group Must Be Mounted To Work
121150

122151
In order for it to apply transitions to its children, the `ReactCSSTransitionGroup` must already be mounted in the DOM or the prop `transitionAppear` must be set to `true`. The example below would not work, because the `ReactCSSTransitionGroup` is being mounted along with the new item, instead of the new item being mounted within it. Compare this to the [Getting Started](#getting-started) section above to see the difference.

src/addons/transitions/ReactCSSTransitionGroup.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,22 @@ var ReactCSSTransitionGroup = React.createClass({
2727
displayName: 'ReactCSSTransitionGroup',
2828

2929
propTypes: {
30-
transitionName: React.PropTypes.string.isRequired,
30+
transitionName: React.PropTypes.oneOfType([
31+
React.PropTypes.string,
32+
React.PropTypes.shape({
33+
enter: React.PropTypes.string,
34+
leave: React.PropTypes.string,
35+
active: React.PropTypes.string
36+
}),
37+
React.PropTypes.shape({
38+
enter: React.PropTypes.string,
39+
enterActive: React.PropTypes.string,
40+
leave: React.PropTypes.string,
41+
leaveActive: React.PropTypes.string,
42+
appear: React.PropTypes.string,
43+
appearActive: React.PropTypes.string
44+
})
45+
]).isRequired,
3146
transitionAppear: React.PropTypes.bool,
3247
transitionEnter: React.PropTypes.bool,
3348
transitionLeave: React.PropTypes.bool,

src/addons/transitions/ReactCSSTransitionGroupChild.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ var ReactCSSTransitionGroupChild = React.createClass({
5656
return;
5757
}
5858

59-
var className = this.props.name + '-' + animationType;
60-
var activeClassName = className + '-active';
59+
var className = this.props.name[animationType] || this.props.name + '-' + animationType;
60+
var activeClassName = this.props.name[animationType + 'Active'] || className + '-active';
61+
6162
var noEventTimeout = null;
6263

6364
var endListener = function(e) {

0 commit comments

Comments
 (0)