UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

144 lines (120 loc) 4.57 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import shallowEqual from 'lodash/isEqual'; import RcCheckbox from '../rc-components/checkbox'; import { getPrefixCls } from '../configure'; var Checkbox = /*#__PURE__*/ function (_Component) { _inherits(Checkbox, _Component); var _super = _createSuper(Checkbox); function Checkbox() { var _this; _classCallCheck(this, Checkbox); _this = _super.apply(this, arguments); _this.saveCheckbox = function (node) { _this.rcCheckbox = node; }; return _this; } _createClass(Checkbox, [{ key: "shouldComponentUpdate", value: function shouldComponentUpdate(nextProps, nextState, nextContext) { var checkboxGroup = this.context.checkboxGroup; return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState) || !shallowEqual(checkboxGroup, nextContext.checkboxGroup); } }, { key: "focus", value: function focus() { this.rcCheckbox.focus(); } }, { key: "blur", value: function blur() { this.rcCheckbox.blur(); } }, { key: "render", value: function render() { var props = this.props, context = this.context; var customizePrefixCls = props.prefixCls, className = props.className, children = props.children, indeterminate = props.indeterminate, style = props.style, onMouseEnter = props.onMouseEnter, onMouseLeave = props.onMouseLeave, restProps = _objectWithoutProperties(props, ["prefixCls", "className", "children", "indeterminate", "style", "onMouseEnter", "onMouseLeave"]); var prefixCls = getPrefixCls('checkbox', customizePrefixCls); var checkboxGroup = context.checkboxGroup; var checkboxProps = _objectSpread({}, restProps); if (checkboxGroup) { checkboxProps.onChange = function () { return checkboxGroup.toggleOption({ label: children, value: props.value }); }; checkboxProps.checked = checkboxGroup.value.indexOf(props.value) !== -1; checkboxProps.disabled = props.disabled || checkboxGroup.disabled; } var classString = classNames(className, _defineProperty({}, "".concat(prefixCls, "-wrapper"), true)); var checkboxClass = classNames(_defineProperty({}, "".concat(prefixCls, "-indeterminate"), indeterminate)); return React.createElement("label", { className: classString, style: style, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, React.createElement(RcCheckbox, _extends({}, checkboxProps, { prefixCls: prefixCls, className: checkboxClass, ref: this.saveCheckbox })), children !== undefined ? React.createElement("span", null, children) : null); } }]); return Checkbox; }(Component); export { Checkbox as default }; Checkbox.displayName = 'Checkbox'; Checkbox.defaultProps = { indeterminate: false }; Checkbox.contextTypes = { checkboxGroup: PropTypes.any }; //# sourceMappingURL=Checkbox.js.map