Skip to content

Commit 4abfd7e

Browse files
committed
refactor: transfer to ts
1 parent 7d379f9 commit 4abfd7e

File tree

7 files changed

+84
-47
lines changed

7 files changed

+84
-47
lines changed

components/transfer/ListItem.jsx renamed to components/transfer/ListItem.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import PropTypes, { withUndefined } from '../_util/vue-types';
22
import classNames from '../_util/classNames';
33
import Lazyload from '../vc-lazy-load';
44
import Checkbox from '../checkbox';
5+
import { defineComponent } from 'vue';
56

67
function noop() {}
78

8-
export default {
9+
export default defineComponent({
910
name: 'ListItem',
1011
inheritAttrs: false,
1112
props: {
@@ -54,12 +55,12 @@ export default {
5455
offset: 500,
5556
throttle: 0,
5657
debounce: false,
57-
...lazy,
58+
...(lazy as any),
5859
};
5960
children = <Lazyload {...lazyProps}>{listItem}</Lazyload>;
6061
} else {
6162
children = listItem;
6263
}
6364
return children;
6465
},
65-
};
66+
});

components/transfer/index.jsx renamed to components/transfer/index.tsx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { inject } from 'vue';
1+
import { App, defineComponent, inject } from 'vue';
22
import PropTypes from '../_util/vue-types';
3-
import { hasProp, initDefaultProps, getOptionProps, getComponent } from '../_util/props-util';
3+
import { hasProp, getOptionProps, getComponent } from '../_util/props-util';
4+
import initDefaultProps from '../_util/props-util/initDefaultProps';
45
import BaseMixin from '../_util/BaseMixin';
56
import classNames from '../_util/classNames';
67
import List from './list';
78
import Operation from './operation';
89
import LocaleReceiver from '../locale-provider/LocaleReceiver';
910
import defaultLocale from '../locale-provider/default';
10-
import { defaultConfigProvider } from '../config-provider';
11+
import { defaultConfigProvider, RenderEmptyHandler } from '../config-provider';
1112

12-
export const TransferDirection = 'left' | 'right';
13+
export type TransferDirection = 'left' | 'right';
1314

1415
export const TransferItem = {
1516
key: PropTypes.string.isRequired,
@@ -45,14 +46,15 @@ export const TransferProps = {
4546
onScroll: PropTypes.func,
4647
};
4748

48-
export const TransferLocale = {
49-
titles: PropTypes.arrayOf(PropTypes.string),
50-
notFoundContent: PropTypes.string,
51-
itemUnit: PropTypes.string,
52-
itemsUnit: PropTypes.string,
53-
};
49+
export interface TransferLocale {
50+
titles: string[];
51+
notFoundContent: string;
52+
searchPlaceholder: string;
53+
itemUnit: string;
54+
itemsUnit: string;
55+
}
5456

55-
const Transfer = {
57+
const Transfer = defineComponent({
5658
name: 'ATransfer',
5759
inheritAttrs: false,
5860
mixins: [BaseMixin],
@@ -64,6 +66,9 @@ const Transfer = {
6466
}),
6567
setup() {
6668
return {
69+
selectedKeys: [],
70+
targetKeys: [],
71+
separatedDataSource: null,
6772
configProvider: inject('configProvider', defaultConfigProvider),
6873
};
6974
},
@@ -114,16 +119,16 @@ const Transfer = {
114119
return direction === 'left' ? 'sourceSelectedKeys' : 'targetSelectedKeys';
115120
},
116121

117-
getTitles(transferLocale) {
122+
getTitles(transferLocale: TransferLocale) {
118123
if (this.titles) {
119124
return this.titles;
120125
}
121126
return transferLocale.titles || ['', ''];
122127
},
123128

124-
getLocale(transferLocale, renderEmpty) {
129+
getLocale(transferLocale: TransferLocale, renderEmpty: RenderEmptyHandler) {
125130
// Keep old locale props still working.
126-
const oldLocale = {
131+
const oldLocale: { notFoundContent?: any; searchPlaceholder?: string } = {
127132
notFoundContent: renderEmpty('Transfer'),
128133
};
129134
const notFoundContent = getComponent(this, 'notFoundContent');
@@ -161,7 +166,7 @@ const Transfer = {
161166
}
162167
},
163168

164-
moveTo(direction) {
169+
moveTo(direction: TransferDirection) {
165170
const { targetKeys = [], dataSource = [] } = this.$props;
166171
const { sourceSelectedKeys, targetSelectedKeys } = this;
167172
const moveKeys = direction === 'right' ? sourceSelectedKeys : targetSelectedKeys;
@@ -191,7 +196,7 @@ const Transfer = {
191196
this.moveTo('right');
192197
},
193198

194-
onItemSelectAll(direction, selectedKeys, checkAll) {
199+
onItemSelectAll(direction: TransferDirection, selectedKeys: string[], checkAll: boolean) {
195200
const originalSelectedKeys = this.$data[this.getSelectedKeysName(direction)] || [];
196201

197202
let mergedCheckedKeys = [];
@@ -319,7 +324,7 @@ const Transfer = {
319324
this.handleScroll('right', e);
320325
},
321326

322-
handleSelectChange(direction, holder) {
327+
handleSelectChange(direction: TransferDirection, holder: string[]) {
323328
const { sourceSelectedKeys, targetSelectedKeys } = this;
324329

325330
if (direction === 'left') {
@@ -361,7 +366,7 @@ const Transfer = {
361366
};
362367
},
363368

364-
renderTransfer(transferLocale) {
369+
renderTransfer(transferLocale: TransferLocale) {
365370
const props = getOptionProps(this);
366371
const {
367372
prefixCls: customizePrefixCls,
@@ -478,10 +483,10 @@ const Transfer = {
478483
/>
479484
);
480485
},
481-
};
486+
});
482487

483488
/* istanbul ignore next */
484-
Transfer.install = function(app) {
489+
Transfer.install = function(app: App) {
485490
app.component(Transfer.name, Transfer);
486491
return app;
487492
};

components/transfer/list.jsx renamed to components/transfer/list.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import classNames from '../_util/classNames';
22
import PropTypes, { withUndefined } from '../_util/vue-types';
3-
import {
4-
isValidElement,
5-
initDefaultProps,
6-
splitAttrs,
7-
findDOMNode,
8-
filterEmpty,
9-
} from '../_util/props-util';
3+
import { isValidElement, splitAttrs, findDOMNode, filterEmpty } from '../_util/props-util';
4+
import initDefaultProps from '../_util/props-util/initDefaultProps';
105
import BaseMixin from '../_util/BaseMixin';
116
import Checkbox from '../checkbox';
127
import Search from './search';
138
import defaultRenderList from './renderListBody';
149
import triggerEvent from '../_util/triggerEvent';
10+
import { defineComponent } from 'vue';
1511

1612
const defaultRender = () => null;
1713

@@ -71,7 +67,7 @@ function renderListNode(renderList, props) {
7167
};
7268
}
7369

74-
export default {
70+
export default defineComponent({
7571
name: 'TransferList',
7672
mixins: [BaseMixin],
7773
inheritAttrs: false,
@@ -81,9 +77,14 @@ export default {
8177
showSearch: false,
8278
lazy: {},
8379
}),
80+
setup() {
81+
return {
82+
timer: null,
83+
triggerScrollTimer: null,
84+
scrollEvent: null,
85+
};
86+
},
8487
data() {
85-
this.timer = null;
86-
this.triggerScrollTimer = null;
8788
return {
8889
filterValue: '',
8990
};
@@ -345,4 +346,4 @@ export default {
345346
</div>
346347
);
347348
},
348-
};
349+
});

components/transfer/operation.jsx renamed to components/transfer/operation.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
import { CSSProperties, FunctionalComponent } from 'vue';
12
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
23
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
34
import Button from '../button';
45

56
function noop() {}
67

7-
const Operation = (_, { attrs }) => {
8+
export interface TransferOperationProps {
9+
class?: any;
10+
leftArrowText?: string;
11+
rightArrowText?: string;
12+
moveToLeft?: (e: MouseEvent) => void;
13+
moveToRight?: (e: MouseEvent) => void;
14+
leftActive?: boolean;
15+
rightActive?: boolean;
16+
style?: CSSProperties | string;
17+
disabled?: boolean;
18+
}
19+
20+
const Operation: FunctionalComponent<TransferOperationProps> = props => {
821
const {
922
disabled,
1023
moveToLeft = noop,
@@ -15,7 +28,7 @@ const Operation = (_, { attrs }) => {
1528
rightActive,
1629
class: className,
1730
style,
18-
} = attrs;
31+
} = props;
1932

2033
return (
2134
<div class={className} style={style}>
@@ -40,6 +53,7 @@ const Operation = (_, { attrs }) => {
4053
</div>
4154
);
4255
};
56+
4357
Operation.inheritAttrs = false;
4458

4559
export default Operation;

components/transfer/renderListBody.jsx renamed to components/transfer/renderListBody.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { TransitionGroup } from 'vue';
1+
import { defineComponent, TransitionGroup } from 'vue';
22
import raf from '../_util/raf';
33
import ListItem from './ListItem';
44
import PropTypes, { withUndefined } from '../_util/vue-types';
55
import getTransitionProps from '../_util/getTransitionProps';
66
import { findDOMNode } from '../_util/props-util';
77
function noop() {}
8-
const ListBody = {
8+
const ListBody = defineComponent({
99
name: 'ListBody',
1010
inheritAttrs: false,
1111
props: {
@@ -18,13 +18,19 @@ const ListBody = {
1818
onItemSelectAll: PropTypes.func,
1919
onScroll: PropTypes.func,
2020
},
21+
setup() {
22+
return {
23+
mountId: null,
24+
lazyId: null,
25+
};
26+
},
2127
data() {
2228
return {
2329
mounted: false,
2430
};
2531
},
2632
computed: {
27-
itemsLength() {
33+
itemsLength(): number {
2834
return this.filteredRenderItems ? this.filteredRenderItems.length : 0;
2935
},
3036
},
@@ -74,7 +80,7 @@ const ListBody = {
7480
selectedKeys,
7581
disabled: globalDisabled,
7682
} = this.$props;
77-
const items = filteredRenderItems.map(({ renderedEl, renderedText, item }) => {
83+
const items = filteredRenderItems.map(({ renderedEl, renderedText, item }: any) => {
7884
const { disabled } = item;
7985
const checked = selectedKeys.indexOf(item.key) >= 0;
8086

@@ -101,11 +107,11 @@ const ListBody = {
101107
},
102108
);
103109
return (
104-
<TransitionGroup class={`${prefixCls}-content`} {...transitionProps}>
110+
<TransitionGroup moveClass={`${prefixCls}-content`} {...transitionProps}>
105111
{items}
106112
</TransitionGroup>
107113
);
108114
},
109-
};
115+
});
110116

111117
export default props => <ListBody {...props} />;

components/transfer/search.jsx renamed to components/transfer/search.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import PropTypes from '../_util/vue-types';
2-
import { initDefaultProps, getOptionProps } from '../_util/props-util';
2+
import { getOptionProps } from '../_util/props-util';
3+
import initDefaultProps from '../_util/props-util/initDefaultProps';
34
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
45
import SearchOutlined from '@ant-design/icons-vue/SearchOutlined';
56
import Input from '../input';
7+
import { defineComponent } from 'vue';
68

79
export const TransferSearchProps = {
810
prefixCls: PropTypes.string,
@@ -13,7 +15,7 @@ export const TransferSearchProps = {
1315
onChange: PropTypes.func,
1416
};
1517

16-
export default {
18+
export default defineComponent({
1719
name: 'Search',
1820
inheritAttrs: false,
1921
props: initDefaultProps(TransferSearchProps, {
@@ -45,7 +47,7 @@ export default {
4547
);
4648

4749
return (
48-
<div>
50+
<>
4951
<Input
5052
placeholder={placeholder}
5153
class={prefixCls}
@@ -54,7 +56,7 @@ export default {
5456
disabled={disabled}
5557
/>
5658
{icon}
57-
</div>
59+
</>
5860
);
5961
},
60-
};
62+
});

components/transfer/style/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import '../../style/index.less';
2+
import './index.less';
3+
4+
// style dependencies
5+
import '../../empty/style';
6+
import '../../checkbox/style';
7+
import '../../button/style';
8+
import '../../input/style';

0 commit comments

Comments
 (0)