refactor: transfer to ts
parent
7d379f9438
commit
4abfd7ea52
|
@ -2,10 +2,11 @@ import PropTypes, { withUndefined } from '../_util/vue-types';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import Lazyload from '../vc-lazy-load';
|
import Lazyload from '../vc-lazy-load';
|
||||||
import Checkbox from '../checkbox';
|
import Checkbox from '../checkbox';
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
name: 'ListItem',
|
name: 'ListItem',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
|
@ -54,7 +55,7 @@ export default {
|
||||||
offset: 500,
|
offset: 500,
|
||||||
throttle: 0,
|
throttle: 0,
|
||||||
debounce: false,
|
debounce: false,
|
||||||
...lazy,
|
...(lazy as any),
|
||||||
};
|
};
|
||||||
children = <Lazyload {...lazyProps}>{listItem}</Lazyload>;
|
children = <Lazyload {...lazyProps}>{listItem}</Lazyload>;
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,4 +63,4 @@ export default {
|
||||||
}
|
}
|
||||||
return children;
|
return children;
|
||||||
},
|
},
|
||||||
};
|
});
|
|
@ -1,15 +1,16 @@
|
||||||
import { inject } from 'vue';
|
import { App, defineComponent, inject } from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { hasProp, initDefaultProps, getOptionProps, getComponent } from '../_util/props-util';
|
import { hasProp, getOptionProps, getComponent } from '../_util/props-util';
|
||||||
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import List from './list';
|
import List from './list';
|
||||||
import Operation from './operation';
|
import Operation from './operation';
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
import defaultLocale from '../locale-provider/default';
|
import defaultLocale from '../locale-provider/default';
|
||||||
import { defaultConfigProvider } from '../config-provider';
|
import { defaultConfigProvider, RenderEmptyHandler } from '../config-provider';
|
||||||
|
|
||||||
export const TransferDirection = 'left' | 'right';
|
export type TransferDirection = 'left' | 'right';
|
||||||
|
|
||||||
export const TransferItem = {
|
export const TransferItem = {
|
||||||
key: PropTypes.string.isRequired,
|
key: PropTypes.string.isRequired,
|
||||||
|
@ -45,14 +46,15 @@ export const TransferProps = {
|
||||||
onScroll: PropTypes.func,
|
onScroll: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TransferLocale = {
|
export interface TransferLocale {
|
||||||
titles: PropTypes.arrayOf(PropTypes.string),
|
titles: string[];
|
||||||
notFoundContent: PropTypes.string,
|
notFoundContent: string;
|
||||||
itemUnit: PropTypes.string,
|
searchPlaceholder: string;
|
||||||
itemsUnit: PropTypes.string,
|
itemUnit: string;
|
||||||
};
|
itemsUnit: string;
|
||||||
|
}
|
||||||
|
|
||||||
const Transfer = {
|
const Transfer = defineComponent({
|
||||||
name: 'ATransfer',
|
name: 'ATransfer',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
|
@ -64,6 +66,9 @@ const Transfer = {
|
||||||
}),
|
}),
|
||||||
setup() {
|
setup() {
|
||||||
return {
|
return {
|
||||||
|
selectedKeys: [],
|
||||||
|
targetKeys: [],
|
||||||
|
separatedDataSource: null,
|
||||||
configProvider: inject('configProvider', defaultConfigProvider),
|
configProvider: inject('configProvider', defaultConfigProvider),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -114,16 +119,16 @@ const Transfer = {
|
||||||
return direction === 'left' ? 'sourceSelectedKeys' : 'targetSelectedKeys';
|
return direction === 'left' ? 'sourceSelectedKeys' : 'targetSelectedKeys';
|
||||||
},
|
},
|
||||||
|
|
||||||
getTitles(transferLocale) {
|
getTitles(transferLocale: TransferLocale) {
|
||||||
if (this.titles) {
|
if (this.titles) {
|
||||||
return this.titles;
|
return this.titles;
|
||||||
}
|
}
|
||||||
return transferLocale.titles || ['', ''];
|
return transferLocale.titles || ['', ''];
|
||||||
},
|
},
|
||||||
|
|
||||||
getLocale(transferLocale, renderEmpty) {
|
getLocale(transferLocale: TransferLocale, renderEmpty: RenderEmptyHandler) {
|
||||||
// Keep old locale props still working.
|
// Keep old locale props still working.
|
||||||
const oldLocale = {
|
const oldLocale: { notFoundContent?: any; searchPlaceholder?: string } = {
|
||||||
notFoundContent: renderEmpty('Transfer'),
|
notFoundContent: renderEmpty('Transfer'),
|
||||||
};
|
};
|
||||||
const notFoundContent = getComponent(this, 'notFoundContent');
|
const notFoundContent = getComponent(this, 'notFoundContent');
|
||||||
|
@ -161,7 +166,7 @@ const Transfer = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
moveTo(direction) {
|
moveTo(direction: TransferDirection) {
|
||||||
const { targetKeys = [], dataSource = [] } = this.$props;
|
const { targetKeys = [], dataSource = [] } = this.$props;
|
||||||
const { sourceSelectedKeys, targetSelectedKeys } = this;
|
const { sourceSelectedKeys, targetSelectedKeys } = this;
|
||||||
const moveKeys = direction === 'right' ? sourceSelectedKeys : targetSelectedKeys;
|
const moveKeys = direction === 'right' ? sourceSelectedKeys : targetSelectedKeys;
|
||||||
|
@ -191,7 +196,7 @@ const Transfer = {
|
||||||
this.moveTo('right');
|
this.moveTo('right');
|
||||||
},
|
},
|
||||||
|
|
||||||
onItemSelectAll(direction, selectedKeys, checkAll) {
|
onItemSelectAll(direction: TransferDirection, selectedKeys: string[], checkAll: boolean) {
|
||||||
const originalSelectedKeys = this.$data[this.getSelectedKeysName(direction)] || [];
|
const originalSelectedKeys = this.$data[this.getSelectedKeysName(direction)] || [];
|
||||||
|
|
||||||
let mergedCheckedKeys = [];
|
let mergedCheckedKeys = [];
|
||||||
|
@ -319,7 +324,7 @@ const Transfer = {
|
||||||
this.handleScroll('right', e);
|
this.handleScroll('right', e);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSelectChange(direction, holder) {
|
handleSelectChange(direction: TransferDirection, holder: string[]) {
|
||||||
const { sourceSelectedKeys, targetSelectedKeys } = this;
|
const { sourceSelectedKeys, targetSelectedKeys } = this;
|
||||||
|
|
||||||
if (direction === 'left') {
|
if (direction === 'left') {
|
||||||
|
@ -361,7 +366,7 @@ const Transfer = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
renderTransfer(transferLocale) {
|
renderTransfer(transferLocale: TransferLocale) {
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
|
@ -478,10 +483,10 @@ const Transfer = {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Transfer.install = function(app) {
|
Transfer.install = function(app: App) {
|
||||||
app.component(Transfer.name, Transfer);
|
app.component(Transfer.name, Transfer);
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
|
@ -1,17 +1,13 @@
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import PropTypes, { withUndefined } from '../_util/vue-types';
|
import PropTypes, { withUndefined } from '../_util/vue-types';
|
||||||
import {
|
import { isValidElement, splitAttrs, findDOMNode, filterEmpty } from '../_util/props-util';
|
||||||
isValidElement,
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
||||||
initDefaultProps,
|
|
||||||
splitAttrs,
|
|
||||||
findDOMNode,
|
|
||||||
filterEmpty,
|
|
||||||
} from '../_util/props-util';
|
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import Checkbox from '../checkbox';
|
import Checkbox from '../checkbox';
|
||||||
import Search from './search';
|
import Search from './search';
|
||||||
import defaultRenderList from './renderListBody';
|
import defaultRenderList from './renderListBody';
|
||||||
import triggerEvent from '../_util/triggerEvent';
|
import triggerEvent from '../_util/triggerEvent';
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
|
||||||
const defaultRender = () => null;
|
const defaultRender = () => null;
|
||||||
|
|
||||||
|
@ -71,7 +67,7 @@ function renderListNode(renderList, props) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
name: 'TransferList',
|
name: 'TransferList',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
@ -81,9 +77,14 @@ export default {
|
||||||
showSearch: false,
|
showSearch: false,
|
||||||
lazy: {},
|
lazy: {},
|
||||||
}),
|
}),
|
||||||
|
setup() {
|
||||||
|
return {
|
||||||
|
timer: null,
|
||||||
|
triggerScrollTimer: null,
|
||||||
|
scrollEvent: null,
|
||||||
|
};
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
this.timer = null;
|
|
||||||
this.triggerScrollTimer = null;
|
|
||||||
return {
|
return {
|
||||||
filterValue: '',
|
filterValue: '',
|
||||||
};
|
};
|
||||||
|
@ -345,4 +346,4 @@ export default {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
});
|
|
@ -1,10 +1,23 @@
|
||||||
|
import { CSSProperties, FunctionalComponent } from 'vue';
|
||||||
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
|
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
|
||||||
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
|
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
|
||||||
import Button from '../button';
|
import Button from '../button';
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
const Operation = (_, { attrs }) => {
|
export interface TransferOperationProps {
|
||||||
|
class?: any;
|
||||||
|
leftArrowText?: string;
|
||||||
|
rightArrowText?: string;
|
||||||
|
moveToLeft?: (e: MouseEvent) => void;
|
||||||
|
moveToRight?: (e: MouseEvent) => void;
|
||||||
|
leftActive?: boolean;
|
||||||
|
rightActive?: boolean;
|
||||||
|
style?: CSSProperties | string;
|
||||||
|
disabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Operation: FunctionalComponent<TransferOperationProps> = props => {
|
||||||
const {
|
const {
|
||||||
disabled,
|
disabled,
|
||||||
moveToLeft = noop,
|
moveToLeft = noop,
|
||||||
|
@ -15,7 +28,7 @@ const Operation = (_, { attrs }) => {
|
||||||
rightActive,
|
rightActive,
|
||||||
class: className,
|
class: className,
|
||||||
style,
|
style,
|
||||||
} = attrs;
|
} = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={className} style={style}>
|
<div class={className} style={style}>
|
||||||
|
@ -40,6 +53,7 @@ const Operation = (_, { attrs }) => {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Operation.inheritAttrs = false;
|
Operation.inheritAttrs = false;
|
||||||
|
|
||||||
export default Operation;
|
export default Operation;
|
|
@ -1,11 +1,11 @@
|
||||||
import { TransitionGroup } from 'vue';
|
import { defineComponent, TransitionGroup } from 'vue';
|
||||||
import raf from '../_util/raf';
|
import raf from '../_util/raf';
|
||||||
import ListItem from './ListItem';
|
import ListItem from './ListItem';
|
||||||
import PropTypes, { withUndefined } from '../_util/vue-types';
|
import PropTypes, { withUndefined } from '../_util/vue-types';
|
||||||
import getTransitionProps from '../_util/getTransitionProps';
|
import getTransitionProps from '../_util/getTransitionProps';
|
||||||
import { findDOMNode } from '../_util/props-util';
|
import { findDOMNode } from '../_util/props-util';
|
||||||
function noop() {}
|
function noop() {}
|
||||||
const ListBody = {
|
const ListBody = defineComponent({
|
||||||
name: 'ListBody',
|
name: 'ListBody',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
|
@ -18,13 +18,19 @@ const ListBody = {
|
||||||
onItemSelectAll: PropTypes.func,
|
onItemSelectAll: PropTypes.func,
|
||||||
onScroll: PropTypes.func,
|
onScroll: PropTypes.func,
|
||||||
},
|
},
|
||||||
|
setup() {
|
||||||
|
return {
|
||||||
|
mountId: null,
|
||||||
|
lazyId: null,
|
||||||
|
};
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
mounted: false,
|
mounted: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
itemsLength() {
|
itemsLength(): number {
|
||||||
return this.filteredRenderItems ? this.filteredRenderItems.length : 0;
|
return this.filteredRenderItems ? this.filteredRenderItems.length : 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -74,7 +80,7 @@ const ListBody = {
|
||||||
selectedKeys,
|
selectedKeys,
|
||||||
disabled: globalDisabled,
|
disabled: globalDisabled,
|
||||||
} = this.$props;
|
} = this.$props;
|
||||||
const items = filteredRenderItems.map(({ renderedEl, renderedText, item }) => {
|
const items = filteredRenderItems.map(({ renderedEl, renderedText, item }: any) => {
|
||||||
const { disabled } = item;
|
const { disabled } = item;
|
||||||
const checked = selectedKeys.indexOf(item.key) >= 0;
|
const checked = selectedKeys.indexOf(item.key) >= 0;
|
||||||
|
|
||||||
|
@ -101,11 +107,11 @@ const ListBody = {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<TransitionGroup class={`${prefixCls}-content`} {...transitionProps}>
|
<TransitionGroup moveClass={`${prefixCls}-content`} {...transitionProps}>
|
||||||
{items}
|
{items}
|
||||||
</TransitionGroup>
|
</TransitionGroup>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
export default props => <ListBody {...props} />;
|
export default props => <ListBody {...props} />;
|
|
@ -1,8 +1,10 @@
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { initDefaultProps, getOptionProps } from '../_util/props-util';
|
import { getOptionProps } from '../_util/props-util';
|
||||||
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
||||||
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
|
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
|
||||||
import SearchOutlined from '@ant-design/icons-vue/SearchOutlined';
|
import SearchOutlined from '@ant-design/icons-vue/SearchOutlined';
|
||||||
import Input from '../input';
|
import Input from '../input';
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
|
||||||
export const TransferSearchProps = {
|
export const TransferSearchProps = {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
|
@ -13,7 +15,7 @@ export const TransferSearchProps = {
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
name: 'Search',
|
name: 'Search',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: initDefaultProps(TransferSearchProps, {
|
props: initDefaultProps(TransferSearchProps, {
|
||||||
|
@ -45,7 +47,7 @@ export default {
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<>
|
||||||
<Input
|
<Input
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
class={prefixCls}
|
class={prefixCls}
|
||||||
|
@ -54,7 +56,7 @@ export default {
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
{icon}
|
{icon}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
});
|
|
@ -0,0 +1,8 @@
|
||||||
|
import '../../style/index.less';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
|
// style dependencies
|
||||||
|
import '../../empty/style';
|
||||||
|
import '../../checkbox/style';
|
||||||
|
import '../../button/style';
|
||||||
|
import '../../input/style';
|
Loading…
Reference in New Issue