UNPKG

linkmore-design

Version:

🌈 πŸš€lmη»„δ»ΆεΊ“γ€‚πŸš€

73 lines (72 loc) β€’ 4.2 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["prefixCls", "className", "children", "style", "disabled"]; import classNames from 'classnames'; import RcCheckbox from 'rc-checkbox'; import { composeRef } from 'rc-util/lib/ref'; import * as React from 'react'; import { useContext } from 'react'; import { ConfigContext } from "../config-provider"; import DisabledContext from "../config-provider/DisabledContext"; import { FormItemInputContext } from "../form/context"; import warning from "../_util/warning"; import RadioGroupContext, { RadioOptionTypeContext } from "./context"; var InternalRadio = function InternalRadio(props, ref) { var _classNames; var groupContext = React.useContext(RadioGroupContext); var radioOptionTypeContext = React.useContext(RadioOptionTypeContext); var _React$useContext = React.useContext(ConfigContext), getPrefixCls = _React$useContext.getPrefixCls, direction = _React$useContext.direction; var innerRef = React.useRef(); var mergedRef = composeRef(ref, innerRef); var _useContext = useContext(FormItemInputContext), isFormItemInput = _useContext.isFormItemInput; warning(!('optionType' in props), 'Radio', '`optionType` is only support in Radio.Group.'); var onChange = function onChange(e) { var _props$onChange, _groupContext$onChang; (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, e); groupContext === null || groupContext === void 0 ? void 0 : (_groupContext$onChang = groupContext.onChange) === null || _groupContext$onChang === void 0 ? void 0 : _groupContext$onChang.call(groupContext, e); }; var customizePrefixCls = props.prefixCls, className = props.className, children = props.children, style = props.style, customDisabled = props.disabled, restProps = _objectWithoutProperties(props, _excluded); var radioPrefixCls = getPrefixCls('radio', customizePrefixCls); var prefixCls = ((groupContext === null || groupContext === void 0 ? void 0 : groupContext.optionType) || radioOptionTypeContext) === 'button' ? "".concat(radioPrefixCls, "-button") : radioPrefixCls; var radioProps = _objectSpread({}, restProps); // ===================== Disabled ===================== var disabled = React.useContext(DisabledContext); radioProps.disabled = customDisabled !== null && customDisabled !== void 0 ? customDisabled : disabled; if (groupContext) { var _radioProps$disabled; radioProps.name = groupContext.name; radioProps.onChange = onChange; radioProps.checked = props.value === groupContext.value; radioProps.disabled = (_radioProps$disabled = radioProps.disabled) !== null && _radioProps$disabled !== void 0 ? _radioProps$disabled : groupContext.disabled; } var wrapperClassString = classNames("".concat(prefixCls, "-wrapper"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-checked"), radioProps.checked), _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-disabled"), radioProps.disabled), _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-rtl"), direction === 'rtl'), _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-in-form-item"), isFormItemInput), _classNames), className); 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, { type: "radio", prefixCls: prefixCls, ref: mergedRef })), children !== undefined ? /*#__PURE__*/React.createElement("span", null, children) : null) ); }; var Radio = /*#__PURE__*/React.forwardRef(InternalRadio); if (process.env.NODE_ENV !== 'production') { Radio.displayName = 'Radio'; } export default Radio;