Skip to content

Instantly share code, notes, and snippets.

@adjohu
Created March 30, 2016 14:44
Show Gist options
  • Save adjohu/08f7db2502b70a57f601c8b0aad96083 to your computer and use it in GitHub Desktop.
Save adjohu/08f7db2502b70a57f601c8b0aad96083 to your computer and use it in GitHub Desktop.
local styles transition group
import React, {PropTypes} from 'react';
import TransitionGroup from 'react-addons-css-transition-group';
import styles from './testThing.scss';
function randomItem() {
return {
name: Array(Math.floor(Math.random() * 15)).join('a'),
key: Math.random()
}
}
class TestThing extends React.Component {
static defaultProps = {
};
constructor() {
super();
this.state = {
items: [1,1,1].map(randomItem)
}
}
componentDidMount() {
this.interval = setInterval(() => {
this.setState({
items: [...this.state.items, randomItem()]
})
}, 5000)
}
renderItems() {
return this.state.items.map(item => <div key={item.key}>{item.name}</div>)
}
render() {
console.log('testThing.js', this.props, this.state);
const {...props} = this.props;
return (
// <div {...props} className={styles.base}>
<TransitionGroup
transitionName={styles}
transitionAppear={true}
transitionEnterTimeout={1000}
transitionLeaveTimeout={1000}
>
{this.renderItems()}
</TransitionGroup>
)
}
}
export default TestThing;
.enter {
opacity: 0.01;
transition: opacity 1.5s ease-out;
}
.enter.enterActive {
opacity: 1;
}
.leave {
opacity: 1;
}
.leave.leaveActive {
opacity: 0.01;
}
.appear {
transition: transform 1.5s ease-out;
transform: translateX(500px);
}
.appear.appearActive {
transform: translateX(0px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment