linkmore-design
Version:
π πlmη»δ»ΆεΊγπ
53 lines (52 loc) β’ 2.68 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["prefixCls", "size", "disabled", "loading", "className"];
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
import classNames from 'classnames';
import RcSwitch from 'rc-switch';
import * as React from 'react';
import { ConfigContext } from "../config-provider";
import DisabledContext from "../config-provider/DisabledContext";
import SizeContext from "../config-provider/SizeContext";
import warning from "../_util/warning";
import Wave from "../_util/wave";
var Switch = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
var _classNames;
var customizePrefixCls = _ref.prefixCls,
customizeSize = _ref.size,
customDisabled = _ref.disabled,
loading = _ref.loading,
_ref$className = _ref.className,
className = _ref$className === void 0 ? '' : _ref$className,
props = _objectWithoutProperties(_ref, _excluded);
warning('checked' in props || !('value' in props), 'Switch', '`value` is not a valid prop, do you mean `checked`?');
var _React$useContext = React.useContext(ConfigContext),
getPrefixCls = _React$useContext.getPrefixCls,
direction = _React$useContext.direction;
var size = React.useContext(SizeContext);
// ===================== Disabled =====================
var disabled = React.useContext(DisabledContext);
var mergedDisabled = (customDisabled !== null && customDisabled !== void 0 ? customDisabled : disabled) || loading;
var prefixCls = getPrefixCls('switch', customizePrefixCls);
var loadingIcon = /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-handle")
}, loading && /*#__PURE__*/React.createElement(LoadingOutlined, {
className: "".concat(prefixCls, "-loading-icon")
}));
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);
return /*#__PURE__*/React.createElement(Wave, {
insertExtraNode: true
}, /*#__PURE__*/React.createElement(RcSwitch, _extends({}, props, {
prefixCls: prefixCls,
className: classes,
disabled: mergedDisabled,
ref: ref,
loadingIcon: loadingIcon
})));
});
Switch.__ANT_SWITCH = true;
if (process.env.NODE_ENV !== 'production') {
Switch.displayName = 'Switch';
}
export default Switch;