UNPKG

dh-c

Version:

The front-end development engineers jimberton gulp react component

90 lines (65 loc) 2.91 kB
'use strict'; exports.__esModule = true; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _group = require('./group'); var _group2 = _interopRequireDefault(_group); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } var Checkbox = function (_Component) { _inherits(Checkbox, _Component); function Checkbox(props) { _classCallCheck(this, Checkbox); var _this = _possibleConstructorReturn(this, _Component.call(this, props)); _this.state = { checked: props.defaultValue }; _this.onClickSelect = _this.onClickSelect.bind(_this); return _this; } Checkbox.prototype.onClickSelect = function onClickSelect() { var checked = this.state.checked; if (typeof this.props.checked !== 'undefined') { return this.props.onChange(!this.props.checked); } this.setState({ checked: !checked }); this.props.onChange(!checked); }; Checkbox.prototype.render = function render() { var checked = this.state.checked; if (typeof this.props.checked !== 'undefined') { checked = this.props.checked; } return _react2.default.createElement( 'div', { className: 'dh-checkbox ' + (checked ? 'dh-checkbox-checked' : ''), onClick: this.onClickSelect, style: this.props.style }, _react2.default.createElement('i', { className: 'dh-icon ' + (checked ? 'dh-icon-checkbox-checked' : 'dh-icon-checkbox') }), _react2.default.createElement( 'span', null, this.props.children ) ); }; return Checkbox; }(_react.Component); Checkbox.Group = _group2.default; Checkbox.propTypes = { defaultValue: _propTypes2.default.bool, onChange: _propTypes2.default.func }; Checkbox.defaultProps = { defaultValue: false, onChange: function onChange() {} }; exports.default = Checkbox;