1 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 |
|
4 | var __rest = this && this.__rest || function (s, e) {
|
5 | var t = {};
|
6 |
|
7 | for (var p in s) {
|
8 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
9 | }
|
10 |
|
11 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
12 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
13 | }
|
14 | return t;
|
15 | };
|
16 |
|
17 | import * as React from 'react';
|
18 | import RcCheckbox from 'rc-checkbox';
|
19 | import classNames from 'classnames';
|
20 | import { composeRef } from "rc-util/es/ref";
|
21 | import { ConfigContext } from '../config-provider';
|
22 | import RadioGroupContext from './context';
|
23 | import devWarning from '../_util/devWarning';
|
24 |
|
25 | var InternalRadio = function InternalRadio(props, ref) {
|
26 | var _classNames;
|
27 |
|
28 | var context = React.useContext(RadioGroupContext);
|
29 |
|
30 | var _React$useContext = React.useContext(ConfigContext),
|
31 | getPrefixCls = _React$useContext.getPrefixCls,
|
32 | direction = _React$useContext.direction;
|
33 |
|
34 | var innerRef = React.useRef();
|
35 | var mergedRef = composeRef(ref, innerRef);
|
36 | React.useEffect(function () {
|
37 | devWarning(!('optionType' in props), 'Radio', '`optionType` is only support in Radio.Group.');
|
38 | }, []);
|
39 |
|
40 | var onChange = function onChange(e) {
|
41 | var _a, _b;
|
42 |
|
43 | (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
44 | (_b = context === null || context === void 0 ? void 0 : context.onChange) === null || _b === void 0 ? void 0 : _b.call(context, e);
|
45 | };
|
46 |
|
47 | var customizePrefixCls = props.prefixCls,
|
48 | className = props.className,
|
49 | children = props.children,
|
50 | style = props.style,
|
51 | restProps = __rest(props, ["prefixCls", "className", "children", "style"]);
|
52 |
|
53 | var prefixCls = getPrefixCls('radio', customizePrefixCls);
|
54 |
|
55 | var radioProps = _extends({}, restProps);
|
56 |
|
57 | if (context) {
|
58 | radioProps.name = context.name;
|
59 | radioProps.onChange = onChange;
|
60 | radioProps.checked = props.value === context.value;
|
61 | radioProps.disabled = props.disabled || context.disabled;
|
62 | }
|
63 |
|
64 | 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'), _classNames), className);
|
65 | return (
|
66 |
|
67 |
|
68 | React.createElement("label", {
|
69 | className: wrapperClassString,
|
70 | style: style,
|
71 | onMouseEnter: props.onMouseEnter,
|
72 | onMouseLeave: props.onMouseLeave
|
73 | }, React.createElement(RcCheckbox, _extends({}, radioProps, {
|
74 | prefixCls: prefixCls,
|
75 | ref: mergedRef
|
76 | })), children !== undefined ? React.createElement("span", null, children) : null)
|
77 | );
|
78 | };
|
79 |
|
80 | var Radio = React.forwardRef(InternalRadio);
|
81 | Radio.displayName = 'Radio';
|
82 | Radio.defaultProps = {
|
83 | type: 'radio'
|
84 | };
|
85 | export default Radio; |
\ | No newline at end of file |