Skip to content
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

Custom class names in ReactCSSTransitionGroup #3761

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/docs/10.1-animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ You'll notice that when you try to remove an item `ReactCSSTransitionGroup` keep
}
```

### Custom Classes ###

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:

```javascript
...
<ReactCSSTransitionGroup
transitionName={
enter: 'enter',
enterActive: 'enterActive',
leave: 'leave',
leaveActive: 'leaveActive',
appear: 'appear',
appearActive: 'appearActive'
}>
{item}
</ReactCSSTransitionGroup>

<ReactCSSTransitionGroup
transitionName={
enter: 'enter',
leave: 'leave',
appear: 'appear'
}>
{item2}
</ReactCSSTransitionGroup>
...

```

### Animation Group Must Be Mounted To Work

In order for it to apply transitions to its children, the `ReactCSSTransitionGroup` must already be mounted in the DOM. 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.
Expand Down
17 changes: 16 additions & 1 deletion src/addons/transitions/ReactCSSTransitionGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ var ReactCSSTransitionGroup = React.createClass({
displayName: 'ReactCSSTransitionGroup',

propTypes: {
transitionName: React.PropTypes.string.isRequired,
transitionName: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.shape({
enter: React.PropTypes.string,
leave: React.PropTypes.string,
active: React.PropTypes.string
}),
React.PropTypes.shape({
enter: React.PropTypes.string,
enterActive: React.PropTypes.string,
leave: React.PropTypes.string,
leaveActive: React.PropTypes.string,
appear: React.PropTypes.string,
appearActive: React.PropTypes.string
})
]).isRequired,
transitionAppear: React.PropTypes.bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure we support appear in the object as well.

transitionEnter: React.PropTypes.bool,
transitionLeave: React.PropTypes.bool
Expand Down
4 changes: 2 additions & 2 deletions src/addons/transitions/ReactCSSTransitionGroupChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ var ReactCSSTransitionGroupChild = React.createClass({

transition: function(animationType, finishCallback) {
var node = React.findDOMNode(this);
var className = this.props.name + '-' + animationType;
var activeClassName = className + '-active';
var className = this.props.name[animationType] || this.props.name + '-' + animationType;
var activeClassName = this.props.name[animationType + 'Active'] || className + '-active';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should perhaps write some tests to make sure these work :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to get tests to work :/ any suggestions on how I should approach it? There aren't currently any tests to make sure the classnames are correct.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zpao can you help on this? I would also love to help out on this if i can. Maybe with the test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry! I missed this comment. Let's skip the test for now. Just make sure appear works and this should be good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, ill make sure appear works and put something up today

var noEventTimeout = null;

var endListener = function(e) {
Expand Down