@bigfishtv/cockpit
Version:
64 lines (51 loc) • 2.41 kB
JavaScript
var _class, _temp;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import classnames from 'classnames';
var SwitchInput = (_temp = _class = function (_Component) {
_inherits(SwitchInput, _Component);
function SwitchInput() {
_classCallCheck(this, SwitchInput);
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
}
SwitchInput.prototype.handleChange = function handleChange(value) {
var _props = this.props,
disabled = _props.disabled,
readOnly = _props.readOnly,
onChange = _props.onChange;
if (!disabled && !readOnly) onChange(value);
};
SwitchInput.prototype.render = function render() {
var _this2 = this;
var _props2 = this.props,
value = _props2.value,
style = _props2.style,
disabled = _props2.disabled,
readOnly = _props2.readOnly;
return React.createElement(
'div',
{
className: classnames('switch', style && 'switch-' + style, { on: value, disabled: disabled || readOnly }),
onClick: function onClick() {
return _this2.handleChange(!value);
} },
React.createElement('div', { className: 'switch-toggle' })
);
};
return SwitchInput;
}(Component), _class.propTypes = {
value: PropTypes.bool,
onChange: PropTypes.func
}, _class.defaultProps = {
value: false,
style: null,
disabled: false,
readOnly: false,
onChange: function onChange() {
return console.warn('No onChange provided for Switch');
}
}, _temp);
export { SwitchInput as default };