/
Button.js
59 lines (53 loc) 路 1.25 KB
/
Button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { Component } from 'react'
import { css, StyleSheet } from 'aphrodite'
import classnames from 'classnames'
const styles = StyleSheet.create({
btn: {
display: 'inline-block',
outline: 'none',
textAlign: 'center',
font: 'bold 32px helvetica',
padding: '20px 40px',
border: '0',
cursor: 'pointer',
color: '#fff',
backgroundColor: '#ec4800',
transition: 'all 300ms',
},
depressed: {
color: '#848484',
backgroundColor: '#bebebe',
},
hover: {
':hover': {
backgroundColor: '#f98d00'
}
},
hoverDepressed: {
':hover': {
backgroundColor: '#bebebe'
}
}
})
export class Button extends Component {
state = { depressed: false }
onButtonClicked = () => this.setState({
depressed: !this.state.depressed
})
render () {
const normalClassnames = css(styles.btn, styles.hover, styles.hover.depressed)
const depressedClassnames = css(styles.depressed, styles.hoverDepressed)
const buttonClassNames = classnames(normalClassnames,
{
[depressedClassnames]: this.state.depressed
}
)
return (
<button
className={ buttonClassNames }
onClick={ this.onButtonClicked }
{ ...this.props }>
</button>
)
}
}