Last active
March 12, 2016 16:17
-
-
Save dtothefp/1c4564baeaaa722dcac1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export default [ | |
{title: 'red', message: 'I\'m red', color: 'red'}, | |
{title: 'blue', message: 'I\'m blue', color: 'blue'}, | |
{title: 'green', message: 'I\'m green', color: 'green'} | |
] |
This file contains hidden or 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 cx from 'classnames' | |
import data from './data' | |
class Whateves extends Component { | |
constructor(props) { | |
super(props) | |
const [first] = data | |
this.state = { | |
hide: true | |
...data | |
} | |
this.next = 1 | |
} | |
componentDidMount() { | |
this.setState( | |
Object.assign({}, this.state, hide: false) | |
) | |
} | |
handleClick(e) { | |
e.preventDefault() | |
this.next = this.next === data.length ? 0 : this.next + 1 | |
this.setState( | |
Object.assign({}, this.state, data[this.next]) | |
) | |
} | |
render() { | |
const {color, message, title, hide} = this.state | |
const classes = cx('anim-container', color, { | |
hide, | |
show: !hide | |
}) | |
return ( | |
<div className={classes}> | |
<h1>this.state.title</h1> | |
<p>this.state.message</p> | |
<button type="text" onClick={::this.handleClick}>Click Me</button> | |
</div> | |
) | |
} | |
} |
This file contains hidden or 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
.anim-container { | |
transition: all linear 0.3s; | |
} | |
.hide { | |
opacity: 0; | |
} | |
.show { | |
opacity: 1; | |
} | |
.red { | |
background: //dark red | |
h1 { | |
background: //light red | |
} | |
} | |
.blue { | |
background: //dark blue | |
h1 { | |
background: //light blue | |
} | |
} | |
.green { | |
background: //dark green | |
h1 { | |
background: //light green | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment