refactor: switch to ts

feat-dayjs^2
Amour1688 2020-10-20 12:46:16 +08:00
parent 7f6d718c84
commit e28b004883
2 changed files with 14 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import { inject } from 'vue'; import { defineComponent, inject, App } from 'vue';
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'; import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import hasProp, { getOptionProps, getComponent } from '../_util/props-util'; import hasProp, { getOptionProps, getComponent } from '../_util/props-util';
@ -6,15 +6,16 @@ import VcSwitch from '../vc-switch';
import Wave from '../_util/wave'; import Wave from '../_util/wave';
import { defaultConfigProvider } from '../config-provider'; import { defaultConfigProvider } from '../config-provider';
import warning from '../_util/warning'; import warning from '../_util/warning';
import { tuple } from '../_util/type';
const Switch = { const Switch = defineComponent({
name: 'ASwitch', name: 'ASwitch',
__ANT_SWITCH: true, __ANT_SWITCH: true,
inheritAttrs: false, inheritAttrs: false,
props: { props: {
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
// size=default and size=large are the same // size=default and size=large are the same
size: PropTypes.oneOf(['small', 'default', 'large']), size: PropTypes.oneOf(tuple('small', 'default', 'large')),
disabled: PropTypes.looseBool, disabled: PropTypes.looseBool,
checkedChildren: PropTypes.any, checkedChildren: PropTypes.any,
unCheckedChildren: PropTypes.any, unCheckedChildren: PropTypes.any,
@ -26,6 +27,7 @@ const Switch = {
}, },
setup() { setup() {
return { return {
refSwitchNode: undefined,
configProvider: inject('configProvider', defaultConfigProvider), configProvider: inject('configProvider', defaultConfigProvider),
}; };
}, },
@ -52,12 +54,12 @@ const Switch = {
const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps( const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps(
this, this,
); );
const getPrefixCls = this.configProvider.getPrefixCls; const { getPrefixCls } = this.configProvider;
const prefixCls = getPrefixCls('switch', customizePrefixCls); const prefixCls = getPrefixCls('switch', customizePrefixCls);
const { $attrs } = this; const { $attrs } = this;
const classes = { const classes = {
[$attrs.class]: $attrs.class, [$attrs.class as string]: $attrs.class,
[`${prefixCls}-small`]: size === 'small', [`${prefixCls}-small`]: size === 'small',
[`${prefixCls}-loading`]: loading, [`${prefixCls}-loading`]: loading,
}; };
@ -73,13 +75,16 @@ const Switch = {
class: classes, class: classes,
ref: this.saveRef, ref: this.saveRef,
}; };
const comp = <VcSwitch {...switchProps} />; return (
return <Wave insertExtraNode>{comp}</Wave>; <Wave insertExtraNode>
<VcSwitch {...switchProps} />
</Wave>
);
}, },
}; });
/* istanbul ignore next */ /* istanbul ignore next */
Switch.install = function(app) { Switch.install = function(app: App) {
app.component(Switch.name, Switch); app.component(Switch.name, Switch);
return app; return app;
}; };