@bigfishtv/cockpit
Version:
35 lines (30 loc) • 842 B
JavaScript
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import classnames from 'classnames'
export default class SwitchInput extends Component {
static propTypes = {
value: PropTypes.bool,
onChange: PropTypes.func,
}
static defaultProps = {
value: false,
style: null,
disabled: false,
readOnly: false,
onChange: () => console.warn('No onChange provided for Switch'),
}
handleChange(value) {
const { disabled, readOnly, onChange } = this.props
if (!disabled && !readOnly) onChange(value)
}
render() {
const { value, style, disabled, readOnly } = this.props
return (
<div
className={classnames('switch', style && 'switch-' + style, { on: value, disabled: disabled || readOnly })}
onClick={() => this.handleChange(!value)}>
<div className="switch-toggle" />
</div>
)
}
}