UNPKG

antd

Version:

An enterprise-class UI design language and React components implementation

85 lines (68 loc) 3.43 kB
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _extends() { _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; }; return _extends.apply(this, arguments); } var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; } if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; import RcCheckbox from 'rc-checkbox'; import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import RadioGroupContext from './context'; import { composeRef } from '../_util/ref'; var InternalRadio = function InternalRadio(props, ref) { var _classNames; var context = React.useContext(RadioGroupContext); var _React$useContext = React.useContext(ConfigContext), getPrefixCls = _React$useContext.getPrefixCls, direction = _React$useContext.direction; var innerRef = React.useRef(); var mergedRef = composeRef(ref, innerRef); var onChange = function onChange(e) { if (props.onChange) { props.onChange(e); } if (context === null || context === void 0 ? void 0 : context.onChange) { context.onChange(e); } }; var customizePrefixCls = props.prefixCls, className = props.className, children = props.children, style = props.style, restProps = __rest(props, ["prefixCls", "className", "children", "style"]); var prefixCls = getPrefixCls('radio', customizePrefixCls); var radioProps = _extends({}, restProps); if (context) { radioProps.name = context.name; radioProps.onChange = onChange; radioProps.checked = props.value === context.value; radioProps.disabled = props.disabled || context.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), _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-rtl"), direction === 'rtl'), _classNames)); return ( /*#__PURE__*/ // eslint-disable-next-line jsx-a11y/label-has-associated-control React.createElement("label", { className: wrapperClassString, style: style, onMouseEnter: props.onMouseEnter, onMouseLeave: props.onMouseLeave }, /*#__PURE__*/React.createElement(RcCheckbox, _extends({}, radioProps, { prefixCls: prefixCls, ref: mergedRef })), children !== undefined ? /*#__PURE__*/React.createElement("span", null, children) : null) ); }; var Radio = /*#__PURE__*/React.forwardRef(InternalRadio); Radio.displayName = 'Radio'; Radio.defaultProps = { type: 'radio' }; export default Radio;