"use strict"; "use client"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var React = _interopRequireWildcard(require("react")); var _LoadingOutlined = _interopRequireDefault(require("@ant-design/icons/LoadingOutlined")); var _classnames = _interopRequireDefault(require("classnames")); var _rcSwitch = _interopRequireDefault(require("rc-switch")); var _warning = require("../_util/warning"); var _wave = _interopRequireDefault(require("../_util/wave")); var _configProvider = require("../config-provider"); var _DisabledContext = _interopRequireDefault(require("../config-provider/DisabledContext")); var _useSize = _interopRequireDefault(require("../config-provider/hooks/useSize")); var _style = _interopRequireDefault(require("./style")); var __rest = void 0 && (void 0).__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; }; const Switch = /*#__PURE__*/React.forwardRef((props, ref) => { const { prefixCls: customizePrefixCls, size: customizeSize, disabled: customDisabled, loading, className, rootClassName, style } = props, restProps = __rest(props, ["prefixCls", "size", "disabled", "loading", "className", "rootClassName", "style"]); if (process.env.NODE_ENV !== 'production') { const warning = (0, _warning.devUseWarning)('Switch'); process.env.NODE_ENV !== "production" ? warning('checked' in props || !('value' in props), 'usage', '`value` is not a valid prop, do you mean `checked`?') : void 0; } const { getPrefixCls, direction, switch: SWITCH } = React.useContext(_configProvider.ConfigContext); // ===================== Disabled ===================== const disabled = React.useContext(_DisabledContext.default); const mergedDisabled = (customDisabled !== null && customDisabled !== void 0 ? customDisabled : disabled) || loading; const prefixCls = getPrefixCls('switch', customizePrefixCls); const loadingIcon = /*#__PURE__*/React.createElement("div", { className: `${prefixCls}-handle` }, loading && /*#__PURE__*/React.createElement(_LoadingOutlined.default, { className: `${prefixCls}-loading-icon` })); // Style const [wrapSSR, hashId] = (0, _style.default)(prefixCls); const mergedSize = (0, _useSize.default)(customizeSize); const classes = (0, _classnames.default)(SWITCH === null || SWITCH === void 0 ? void 0 : SWITCH.className, { [`${prefixCls}-small`]: mergedSize === 'small', [`${prefixCls}-loading`]: loading, [`${prefixCls}-rtl`]: direction === 'rtl' }, className, rootClassName, hashId); const mergedStyle = Object.assign(Object.assign({}, SWITCH === null || SWITCH === void 0 ? void 0 : SWITCH.style), style); return wrapSSR( /*#__PURE__*/React.createElement(_wave.default, { component: "Switch" }, /*#__PURE__*/React.createElement(_rcSwitch.default, Object.assign({}, restProps, { prefixCls: prefixCls, className: classes, style: mergedStyle, disabled: mergedDisabled, ref: ref, loadingIcon: loadingIcon })))); }); Switch.__ANT_SWITCH = true; if (process.env.NODE_ENV !== 'production') { Switch.displayName = 'Switch'; } var _default = exports.default = Switch;