choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
149 lines (122 loc) • 4.59 kB
JavaScript
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 Radio =
/*#__PURE__*/
function (_Component) {
_inherits(Radio, _Component);
var _super = _createSuper(Radio);
function Radio() {
var _this;
_classCallCheck(this, Radio);
_this = _super.apply(this, arguments);
_this.saveCheckbox = function (node) {
_this.rcCheckbox = node;
};
_this.onChange = function (e) {
var onChange = _this.props.onChange;
var radioGroup = _this.context.radioGroup;
if (onChange) {
onChange(e);
}
if (radioGroup && radioGroup.onChange) {
radioGroup.onChange(e);
}
};
return _this;
}
_createClass(Radio, [{
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps, nextState, nextContext) {
var radioGroup = this.context.radioGroup;
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState) || !shallowEqual(radioGroup, nextContext.radioGroup);
}
}, {
key: "focus",
value: function focus() {
this.rcCheckbox.focus();
}
}, {
key: "blur",
value: function blur() {
this.rcCheckbox.blur();
}
}, {
key: "render",
value: function render() {
var _classNames;
var props = this.props,
context = this.context;
var customizePrefixCls = props.prefixCls,
className = props.className,
children = props.children,
style = props.style,
restProps = _objectWithoutProperties(props, ["prefixCls", "className", "children", "style"]);
var prefixCls = getPrefixCls('radio', customizePrefixCls);
var radioGroup = context.radioGroup;
var radioProps = _objectSpread({}, restProps);
if (radioGroup) {
radioProps.name = radioGroup.name;
radioProps.onChange = this.onChange;
radioProps.checked = props.value === radioGroup.value;
radioProps.disabled = props.disabled || radioGroup.disabled;
}
var wrapperClassString = classNames(className, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-wrapper"), true), _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-checked"), radioProps.checked), _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-disabled"), radioProps.disabled), _classNames));
return React.createElement("label", {
className: wrapperClassString,
style: style,
onMouseEnter: props.onMouseEnter,
onMouseLeave: props.onMouseLeave
}, React.createElement(RcCheckbox, _extends({}, radioProps, {
prefixCls: prefixCls,
ref: this.saveCheckbox
})), children !== undefined ? React.createElement("span", null, children) : null);
}
}]);
return Radio;
}(Component);
export { Radio as default };
Radio.displayName = 'Radio';
Radio.defaultProps = {
type: 'radio'
};
Radio.contextTypes = {
radioGroup: PropTypes.any
};
//# sourceMappingURL=radio.js.map