UNPKG

2.99 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
4var __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
17import LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined";
18import classNames from 'classnames';
19import RcSwitch from 'rc-switch';
20import * as React from 'react';
21import { ConfigContext } from '../config-provider';
22import DisabledContext from '../config-provider/DisabledContext';
23import SizeContext from '../config-provider/SizeContext';
24import warning from '../_util/warning';
25import Wave from '../_util/wave';
26var Switch = /*#__PURE__*/React.forwardRef(function (_a, ref) {
27 var _classNames;
28
29 var customizePrefixCls = _a.prefixCls,
30 customizeSize = _a.size,
31 customDisabled = _a.disabled,
32 loading = _a.loading,
33 _a$className = _a.className,
34 className = _a$className === void 0 ? '' : _a$className,
35 props = __rest(_a, ["prefixCls", "size", "disabled", "loading", "className"]);
36
37 process.env.NODE_ENV !== "production" ? warning('checked' in props || !('value' in props), 'Switch', '`value` is not a valid prop, do you mean `checked`?') : void 0;
38
39 var _React$useContext = React.useContext(ConfigContext),
40 getPrefixCls = _React$useContext.getPrefixCls,
41 direction = _React$useContext.direction;
42
43 var size = React.useContext(SizeContext); // ===================== Disabled =====================
44
45 var disabled = React.useContext(DisabledContext);
46 var mergedDisabled = customDisabled || disabled || loading;
47 var prefixCls = getPrefixCls('switch', customizePrefixCls);
48 var loadingIcon = /*#__PURE__*/React.createElement("div", {
49 className: "".concat(prefixCls, "-handle")
50 }, loading && /*#__PURE__*/React.createElement(LoadingOutlined, {
51 className: "".concat(prefixCls, "-loading-icon")
52 }));
53 var classes = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-small"), (customizeSize || size) === 'small'), _defineProperty(_classNames, "".concat(prefixCls, "-loading"), loading), _defineProperty(_classNames, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _classNames), className);
54 return /*#__PURE__*/React.createElement(Wave, {
55 insertExtraNode: true
56 }, /*#__PURE__*/React.createElement(RcSwitch, _extends({}, props, {
57 prefixCls: prefixCls,
58 className: classes,
59 disabled: mergedDisabled,
60 ref: ref,
61 loadingIcon: loadingIcon
62 })));
63});
64Switch.__ANT_SWITCH = true;
65
66if (process.env.NODE_ENV !== 'production') {
67 Switch.displayName = 'Switch';
68}
69
70export default Switch;
\No newline at end of file