Skip to content

Instantly share code, notes, and snippets.

@dtothefp
Last active March 12, 2016 16:17
Show Gist options
  • Save dtothefp/1c4564baeaaa722dcac1 to your computer and use it in GitHub Desktop.
Save dtothefp/1c4564baeaaa722dcac1 to your computer and use it in GitHub Desktop.
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'}
]
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>
)
}
}
.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