UNPKG

sophia-components

Version:
71 lines (48 loc) 2.6 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _compose = require('recompose/compose'); var _compose2 = _interopRequireDefault(_compose); var _withAttrs = require('../base/withAttrs'); var _withAttrs2 = _interopRequireDefault(_withAttrs); var _withIsHas = require('../base/withIsHas'); var _withIsHas2 = _interopRequireDefault(_withIsHas); var _withEvents = require('../base/withEvents'); var _withEvents2 = _interopRequireDefault(_withEvents); var _helpers = require('../utils/helpers'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } var Checkbox = function Checkbox(_ref) { var _ref$attrs = _ref.attrs, className = _ref$attrs.className, restAttrs = _objectWithoutProperties(_ref$attrs, ['className']), events = _ref.events, label = _ref.label; var _propsSegregator = (0, _helpers.propsSegregator)(restAttrs, { labelAttrs: _withAttrs.labelAttrs, checkboxAttrs: _withAttrs.checkboxAttrs }), defaultProps = _propsSegregator.labelAttrs, checkboxProps = _propsSegregator.checkboxAttrs; if (checkboxProps.disabled) { defaultProps.disabled = true; } return _react2.default.createElement( 'label', _extends({ className: (0, _helpers.classNameJoiner)('checkbox', className) }, defaultProps), _react2.default.createElement('input', _extends({ type: 'checkbox' }, events, checkboxProps)), label ); }; Checkbox.propTypes = { attrs: _propTypes2.default.shape().isRequired, events: _propTypes2.default.shape().isRequired, label: _propTypes2.default.string }; Checkbox.defaultProps = { label: null }; exports.default = (0, _compose2.default)((0, _withEvents2.default)(_withEvents.inputSet), (0, _withIsHas2.default)(_withIsHas.helpersIsKeys, _withIsHas.helpersHasKeys), (0, _withAttrs2.default)((0, _helpers.combineSets)(_withAttrs.labelAttrs, _withAttrs.checkboxAttrs)))(Checkbox);