Last active
August 9, 2018 15:46
-
-
Save danielpowell4/2cec5adb702249a408f4159ac0bf15b1 to your computer and use it in GitHub Desktop.
Example reusable scss mixin of a slide in animation for a React component using CSSTransitionGroup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ReactCSSTransitionGroup from "react-addons-css-transition-group"; | |
import SomeOtherComponentOrChild from "./SomeOtherComponentOrChild" // more likely defined inline | |
// Great for list items or quick, inline forms! | |
const AnimatedComponent = props => | |
<ReactCSSTransitionGroup | |
transitionName="transition-name" // creates class that is passed to scss mixin | |
transitionEnterTimeout={400} | |
transitionLeaveTimeout={400} | |
> | |
<SomeOtherComponentOrChild {...props} /> | |
</ReactCSSTransitionGroup> | |
export default AnimatedComponent; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// scss mixin by @ashsidhu | |
@mixin slideInAnimation($selector, $height: 9rem, $duration: 400ms) { | |
%#{$selector}-closed { | |
opacity: 0.01; | |
height: 0rem; | |
} | |
%#{$selector}-open { | |
opacity: 1; | |
height: $height; | |
overflow: hidden; | |
} | |
%#{$selector}-transition { | |
transition: all #{$duration} ease-in; | |
} | |
.#{$selector}-enter { | |
@extend %#{$selector}-closed, %#{$selector}-transition; | |
} | |
.#{$selector}-enter.#{$selector}-enter-active { | |
@extend %#{$selector}-open; | |
} | |
.#{$selector}-leave { | |
@extend %#{$selector}-open, %#{$selector}-transition; | |
} | |
.#{$selector}-leave.#{$selector}-leave-active { | |
@extend %#{$selector}-closed; | |
} | |
} | |
// specific inclusion w/ transitionName string prop | |
@include slideInAnimation("transition-name", 9rem); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment