1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
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 LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined";
|
18 | import classNames from 'classnames';
|
19 | import RcSwitch from 'rc-switch';
|
20 | import * as React from 'react';
|
21 | import { ConfigContext } from '../config-provider';
|
22 | import DisabledContext from '../config-provider/DisabledContext';
|
23 | import SizeContext from '../config-provider/SizeContext';
|
24 | import warning from '../_util/warning';
|
25 | import Wave from '../_util/wave';
|
26 | var Switch = 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);
|
44 |
|
45 | var disabled = React.useContext(DisabledContext);
|
46 | var mergedDisabled = customDisabled || disabled || loading;
|
47 | var prefixCls = getPrefixCls('switch', customizePrefixCls);
|
48 | var loadingIcon = React.createElement("div", {
|
49 | className: "".concat(prefixCls, "-handle")
|
50 | }, loading && 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 React.createElement(Wave, {
|
55 | insertExtraNode: true
|
56 | }, React.createElement(RcSwitch, _extends({}, props, {
|
57 | prefixCls: prefixCls,
|
58 | className: classes,
|
59 | disabled: mergedDisabled,
|
60 | ref: ref,
|
61 | loadingIcon: loadingIcon
|
62 | })));
|
63 | });
|
64 | Switch.__ANT_SWITCH = true;
|
65 |
|
66 | if (process.env.NODE_ENV !== 'production') {
|
67 | Switch.displayName = 'Switch';
|
68 | }
|
69 |
|
70 | export default Switch; |
\ | No newline at end of file |