diff --git a/components/switch/index.tsx b/components/switch/index.tsx index 50a0538702..106623c537 100755 --- a/components/switch/index.tsx +++ b/components/switch/index.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import RcSwitch from 'rc-switch'; import classNames from 'classnames'; -import omit from 'omit.js'; import LoadingOutlined from '@ant-design/icons/LoadingOutlined'; import Wave from '../_util/wave'; @@ -35,50 +34,55 @@ interface CompoundedComponent __ANT_SWITCH: boolean; } -const Switch = React.forwardRef((props, ref) => { - devWarning( - 'checked' in props || !('value' in props), - 'Switch', - '`value` is not a valid prop, do you mean `checked`?', - ); +const Switch = React.forwardRef( + ( + { + prefixCls: customizePrefixCls, + size: customizeSize, + loading, + className = '', + disabled, + ...props + }, + ref, + ) => { + devWarning( + 'checked' in props || !('value' in props), + 'Switch', + '`value` is not a valid prop, do you mean `checked`?', + ); - const { - prefixCls: customizePrefixCls, - size: customizeSize, - loading, - className = '', - disabled, - } = props; + const { getPrefixCls, direction } = React.useContext(ConfigContext); + const size = React.useContext(SizeContext); + const prefixCls = getPrefixCls('switch', customizePrefixCls); + const loadingIcon = ( +
+ {loading && } +
+ ); - const { getPrefixCls, direction } = React.useContext(ConfigContext); - const size = React.useContext(SizeContext); - const prefixCls = getPrefixCls('switch', customizePrefixCls); - const loadingIcon = ( -
- {loading && } -
- ); + const classes = classNames(className, { + [`${prefixCls}-small`]: (customizeSize || size) === 'small', + [`${prefixCls}-loading`]: loading, + [`${prefixCls}-rtl`]: direction === 'rtl', + }); - const classes = classNames(className, { - [`${prefixCls}-small`]: (customizeSize || size) === 'small', - [`${prefixCls}-loading`]: loading, - [`${prefixCls}-rtl`]: direction === 'rtl', - }); - - return ( - - - - ); -}) as CompoundedComponent; + return ( + + + + ); + }, +) as CompoundedComponent; Switch.__ANT_SWITCH = true; +Switch.displayName = 'Switch'; export default Switch;