Skip to content

Commit 5643bfe

Browse files
committed
refactor: tree-select to ts
1 parent e066785 commit 5643bfe

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

components/select/index.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ export interface SelectPropsTypes<VT>
3939
}
4040
export type SelectTypes = SelectPropsTypes<SelectValue>;
4141
export const SelectProps = () => ({
42-
...omit(BaseProps(), ['inputIcon', 'mode', 'getInputElement', 'backfill', 'class', 'style']),
42+
...(omit(BaseProps(), [
43+
'inputIcon',
44+
'mode',
45+
'getInputElement',
46+
'backfill',
47+
'class',
48+
'style',
49+
]) as Omit<
50+
ReturnType<typeof BaseProps>,
51+
'inputIcon' | 'mode' | 'getInputElement' | 'backfill' | 'class' | 'style'
52+
>),
4353
value: {
4454
type: [Array, Object, String, Number] as PropType<SelectValue>,
4555
},

components/tree-select/index.jsx renamed to components/tree-select/index.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import VcTreeSelect, { TreeNode, SHOW_ALL, SHOW_PARENT, SHOW_CHILD } from '../vc-tree-select';
2-
import { inject } from 'vue';
2+
import { App, defineComponent, inject } from 'vue';
33
import classNames from '../_util/classNames';
44
import { TreeSelectProps } from './interface';
55
import warning from '../_util/warning';
6-
import { initDefaultProps, getOptionProps, getComponent, getSlot } from '../_util/props-util';
6+
import { getOptionProps, getComponent, getSlot } from '../_util/props-util';
7+
import initDefaultProps from '../_util/props-util/initDefaultProps';
78
import { defaultConfigProvider } from '../config-provider';
89

910
export { TreeData, TreeSelectProps } from './interface';
@@ -14,7 +15,7 @@ import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
1415
import CloseCircleOutlined from '@ant-design/icons-vue/CloseCircleOutlined';
1516
import omit from 'omit.js';
1617

17-
const TreeSelect = {
18+
const TreeSelect = defineComponent({
1819
TreeNode,
1920
SHOW_ALL,
2021
SHOW_PARENT,
@@ -28,6 +29,7 @@ const TreeSelect = {
2829
}),
2930
setup() {
3031
return {
32+
vcTreeSelect: null,
3133
configProvider: inject('configProvider', defaultConfigProvider),
3234
};
3335
},
@@ -111,7 +113,7 @@ const TreeSelect = {
111113
},
112114

113115
render() {
114-
const props = getOptionProps(this);
116+
const props: any = getOptionProps(this);
115117
const {
116118
prefixCls: customizePrefixCls,
117119
size,
@@ -121,10 +123,9 @@ const TreeSelect = {
121123
...restProps
122124
} = props;
123125
const { class: className } = this.$attrs;
124-
const getPrefixCls = this.configProvider.getPrefixCls;
126+
const { renderEmpty, getPrefixCls } = this.configProvider;
125127
const prefixCls = getPrefixCls('select', customizePrefixCls);
126128

127-
const renderEmpty = this.configProvider.renderEmpty;
128129
const notFoundContent = getComponent(this, 'notFoundContent');
129130
const removeIcon = getComponent(this, 'removeIcon');
130131
const clearIcon = getComponent(this, 'clearIcon');
@@ -145,7 +146,7 @@ const TreeSelect = {
145146
const cls = {
146147
[`${prefixCls}-lg`]: size === 'large',
147148
[`${prefixCls}-sm`]: size === 'small',
148-
[className]: className,
149+
[className as string]: className,
149150
};
150151

151152
// showSearch: single - false, multiple - true
@@ -196,10 +197,10 @@ const TreeSelect = {
196197
/>
197198
);
198199
},
199-
};
200+
});
200201

201202
/* istanbul ignore next */
202-
TreeSelect.install = function(app) {
203+
TreeSelect.install = function(app: App) {
203204
app.component(TreeSelect.name, TreeSelect);
204205
app.component('ATreeSelectNode', TreeSelect.TreeNode);
205206
return app;

components/tree-select/interface.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PropTypes, { withUndefined } from '../_util/vue-types';
22
import { SelectProps } from '../select';
3+
import { tuple } from '../_util/type';
34

45
export const TreeData = PropTypes.shape({
56
key: PropTypes.string,
@@ -35,7 +36,7 @@ export const TreeSelectProps = () => ({
3536
notFoundContent: PropTypes.any,
3637
searchPlaceholder: PropTypes.string,
3738
searchValue: PropTypes.string,
38-
showCheckedStrategy: PropTypes.oneOf(['SHOW_ALL', 'SHOW_PARENT', 'SHOW_CHILD']),
39+
showCheckedStrategy: PropTypes.oneOf(tuple('SHOW_ALL', 'SHOW_PARENT', 'SHOW_CHILD')),
3940
suffixIcon: PropTypes.any,
4041
treeCheckable: PropTypes.looseBool,
4142
treeCheckStrictly: PropTypes.looseBool,

0 commit comments

Comments
 (0)