maputnik/src/components/inputs/CheckboxInput.jsx

75 lines
1.8 KiB
React
Raw Normal View History

2016-12-18 20:08:20 +01:00
import React from 'react'
import input from '../../config/input.js'
2016-12-21 10:25:32 +01:00
import colors from '../../config/colors'
import { margins } from '../../config/scales'
2016-12-18 20:08:20 +01:00
class CheckboxInput extends React.Component {
2016-12-18 20:08:20 +01:00
static propTypes = {
value: React.PropTypes.bool.isRequired,
2016-12-19 16:21:22 +01:00
style: React.PropTypes.object,
onChange: React.PropTypes.func,
2016-12-18 20:08:20 +01:00
}
render() {
2016-12-21 10:25:32 +01:00
const styles = {
2017-01-09 21:43:14 +01:00
root: {
2016-12-21 10:25:32 +01:00
...input.base,
2017-01-09 21:43:14 +01:00
lineHeight: 0.7,
2016-12-21 10:25:32 +01:00
padding: 0,
2017-01-09 21:43:14 +01:00
position: 'relative',
2016-12-21 10:25:32 +01:00
textAlign: 'center ',
2017-01-09 21:43:14 +01:00
verticalAlign: 'middle',
cursor: 'pointer'
},
input: {
position: 'absolute',
zIndex: -1,
opacity: 0
},
box: {
display: 'inline-block',
2016-12-21 10:25:32 +01:00
textAlign: 'center ',
height: 15,
width: 15,
2017-01-09 21:43:14 +01:00
marginRight: margins[1],
marginBottom: null,
backgroundColor: colors.gray,
borderRadius: 2,
borderStyle: 'solid',
borderWidth: 2,
borderColor: colors.gray,
transition: 'background-color .1s ease-out'
},
icon: {
display: this.props.value ? null : 'none',
width: '75%',
height: '75%',
marginTop: 1,
fill: colors.lowgray
}
2016-12-21 10:25:32 +01:00
}
2017-01-09 21:43:14 +01:00
return <label style={styles.root}>
2016-12-21 10:25:32 +01:00
<input
2017-01-10 21:28:30 +01:00
className="maputnik-checkbox"
2017-01-09 21:43:14 +01:00
type="checkbox"
style={{
2016-12-21 10:25:32 +01:00
...styles.input,
2017-01-09 21:43:14 +01:00
...this.props.style,
}}
onChange={e => this.props.onChange(!this.props.value)}
2017-01-09 21:43:14 +01:00
checked={this.props.value}
/>
2016-12-21 10:25:32 +01:00
<div style={styles.box}>
<svg
viewBox='0 0 32 32'
style={styles.icon}>
<path d='M1 14 L5 10 L13 18 L27 4 L31 8 L13 26 z' />
</svg>
2017-01-09 21:43:14 +01:00
</div>
</label>
2016-12-18 20:08:20 +01:00
}
}
export default CheckboxInput