From e28b004883d721d2548c3d290498a06a1635d4f8 Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Tue, 20 Oct 2020 12:46:16 +0800 Subject: [PATCH] refactor: switch to ts --- components/switch/{index.jsx => index.tsx} | 23 +++++++++++-------- .../switch/style/{index.js => index.ts} | 0 2 files changed, 14 insertions(+), 9 deletions(-) rename components/switch/{index.jsx => index.tsx} (82%) rename components/switch/style/{index.js => index.ts} (100%) diff --git a/components/switch/index.jsx b/components/switch/index.tsx similarity index 82% rename from components/switch/index.jsx rename to components/switch/index.tsx index 2037b4e68..005edd496 100644 --- a/components/switch/index.jsx +++ b/components/switch/index.tsx @@ -1,4 +1,4 @@ -import { inject } from 'vue'; +import { defineComponent, inject, App } from 'vue'; import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'; import PropTypes from '../_util/vue-types'; import hasProp, { getOptionProps, getComponent } from '../_util/props-util'; @@ -6,15 +6,16 @@ import VcSwitch from '../vc-switch'; import Wave from '../_util/wave'; import { defaultConfigProvider } from '../config-provider'; import warning from '../_util/warning'; +import { tuple } from '../_util/type'; -const Switch = { +const Switch = defineComponent({ name: 'ASwitch', __ANT_SWITCH: true, inheritAttrs: false, props: { prefixCls: PropTypes.string, // size=default and size=large are the same - size: PropTypes.oneOf(['small', 'default', 'large']), + size: PropTypes.oneOf(tuple('small', 'default', 'large')), disabled: PropTypes.looseBool, checkedChildren: PropTypes.any, unCheckedChildren: PropTypes.any, @@ -26,6 +27,7 @@ const Switch = { }, setup() { return { + refSwitchNode: undefined, configProvider: inject('configProvider', defaultConfigProvider), }; }, @@ -52,12 +54,12 @@ const Switch = { const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps( this, ); - const getPrefixCls = this.configProvider.getPrefixCls; + const { getPrefixCls } = this.configProvider; const prefixCls = getPrefixCls('switch', customizePrefixCls); const { $attrs } = this; const classes = { - [$attrs.class]: $attrs.class, + [$attrs.class as string]: $attrs.class, [`${prefixCls}-small`]: size === 'small', [`${prefixCls}-loading`]: loading, }; @@ -73,13 +75,16 @@ const Switch = { class: classes, ref: this.saveRef, }; - const comp = ; - return {comp}; + return ( + + + + ); }, -}; +}); /* istanbul ignore next */ -Switch.install = function(app) { +Switch.install = function(app: App) { app.component(Switch.name, Switch); return app; }; diff --git a/components/switch/style/index.js b/components/switch/style/index.ts similarity index 100% rename from components/switch/style/index.js rename to components/switch/style/index.ts