UNPKG

cpui-components

Version:

94 lines (72 loc) 3.72 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.Checkbox = undefined; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _blacklist = require('blacklist'); var _blacklist2 = _interopRequireDefault(_blacklist); 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 = exports.Checkbox = function (_Component) { _inherits(Checkbox, _Component); function Checkbox() { var _ref; var _temp, _this, _ret; _classCallCheck(this, Checkbox); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Checkbox.__proto__ || Object.getPrototypeOf(Checkbox)).call.apply(_ref, [this].concat(args))), _this), _this.componentDidMount = function () { if (_this.props.autoFocus) { _this.target.focus(); } _this.setIndeterminate(_this.props.indeterminate); }, _this.componentWillReceiveProps = function (nextProps) { _this.setIndeterminate(nextProps.indeterminate); }, _this.setIndeterminate = function (value) { _this.target.indeterminate = value; }, _this.getRef = function (ref) { _this.target = ref; if (_this.props.innerRef) { _this.props.innerRef(ref); } }, _this.render = function () { var componentClass = (0, _classnames2.default)('cp-Checkbox', { 'cp-Checkbox--disabled': _this.props.disabled, 'cp-Checkbox--inline': _this.props.inline }, _this.props.className); var props = (0, _blacklist2.default)(_this.props, 'className', 'label', 'style', 'title'); return _react2.default.createElement( 'label', Object.assign({}, { className: componentClass, style: _this.props.style, title: _this.props.title }), _react2.default.createElement('input', Object.assign({ ref: _this.getRef, type: 'checkbox', className: 'cp-Checkbox-input' }, props)), _this.props.label != null ? _react2.default.createElement( 'span', { className: 'cp-Checkbox-label' }, _this.props.label ) : null ); }, _temp), _possibleConstructorReturn(_this, _ret); } return Checkbox; }(_react.Component); Checkbox.propTypes = { autoFocus: _propTypes2.default.bool, className: _propTypes2.default.string, disabled: _propTypes2.default.bool, indeterminate: _propTypes2.default.bool, innerRef: _propTypes2.default.func, inline: _propTypes2.default.bool, label: _propTypes2.default.string, style: _propTypes2.default.object, title: _propTypes2.default.string }; exports.default = Checkbox;