chore(form/toggle): simplify implementation

This commit is contained in:
Julien Fontanet
2017-05-15 16:32:05 +02:00
parent 9dbef0c20a
commit 7f503cfc21
2 changed files with 14 additions and 23 deletions

View File

@@ -2,11 +2,9 @@ import React from 'react'
import classNames from 'classnames'
import uncontrollableInput from 'uncontrollable-input'
import Component from '../../base-component'
import Icon from '../../icon'
import propTypes from '../../prop-types'
import styles from './index.css'
import Component from '../base-component'
import Icon from '../icon'
import propTypes from '../prop-types'
@uncontrollableInput()
@propTypes({
@@ -25,30 +23,26 @@ export default class Toggle extends Component {
iconSize: 2
}
_onChange = event => this.props.onChange(event.target.checked)
_toggle = () => {
const { props } = this
props.onChange(!props.value)
}
render () {
const { props } = this
console.log({ value: props.value })
return (
<label
<Icon
className={classNames(
props.disabled ? 'text-muted' : props.value ? 'text-success' : null,
props.className
)}
>
<Icon
icon={props.icon || (props.value ? props.iconOn : props.iconOff)}
size={props.iconSize}
/>
<input
checked={props.value || false}
className={styles.checkbox}
disabled={props.disabled}
onChange={this._onChange}
type='checkbox'
/>
</label>
icon={props.icon || (props.value ? props.iconOn : props.iconOff)}
onClick={this._toggle}
size={props.iconSize}
/>
)
}
}

View File

@@ -1,3 +0,0 @@
.checkbox {
display: none;
}