Skip to content

Commit a4b6c0a

Browse files
committed
feat: transfer add status
1 parent 03f559a commit a4b6c0a

File tree

11 files changed

+101
-10
lines changed

11 files changed

+101
-10
lines changed

components/transfer/ListBody.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function parsePagination(pagination) {
2727

2828
const defaultPagination = {
2929
pageSize: 10,
30+
simple: true,
31+
showSizeChanger: false,
32+
showLessItems: false,
3033
};
3134

3235
if (typeof pagination === 'object') {
@@ -114,7 +117,9 @@ const ListBody = defineComponent({
114117
if (mergedPagination.value) {
115118
paginationNode = (
116119
<Pagination
117-
simple
120+
simple={mergedPagination.value.simple}
121+
showSizeChanger={mergedPagination.value.showSizeChanger}
122+
showLessItems={mergedPagination.value.showLessItems}
118123
size="small"
119124
disabled={globalDisabled}
120125
class={`${prefixCls}-pagination`}

components/transfer/demo/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<pagination />
99
<table-transfer />
1010
<tree-transfer />
11+
<statusVue />
1112
</demo-sort>
1213
</template>
1314
<script lang="ts">
@@ -19,6 +20,7 @@ import CustomItem from './custom-item.vue';
1920
import TableTransfer from './table-transfer.vue';
2021
import TreeTransfer from './tree-transfer.vue';
2122
import Pagination from './pagination.vue';
23+
import statusVue from './status.vue';
2224
import CN from '../index.zh-CN.md';
2325
import US from '../index.en-US.md';
2426
import { defineComponent } from 'vue';
@@ -27,6 +29,7 @@ export default defineComponent({
2729
CN,
2830
US,
2931
components: {
32+
statusVue,
3033
Basic,
3134
Oneway,
3235
Search,

components/transfer/demo/status.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<docs>
2+
---
3+
order: 19
4+
version: 3.3.0
5+
title:
6+
zh-CN: 自定义状态
7+
en-US: Status
8+
---
9+
10+
## zh-CN
11+
12+
使用 `status` 为 DatePicker 添加状态,可选 `error` 或者 `warning`。
13+
14+
## en-US
15+
16+
Add status to DatePicker with `status`, which could be `error` or `warning`.
17+
18+
</docs>
19+
20+
<template>
21+
<a-space direction="vertical">
22+
<a-transfer status="error" />
23+
<a-transfer status="warning" show-search />
24+
</a-space>
25+
</template>
26+
<script lang="ts">
27+
import { defineComponent } from 'vue';
28+
export default defineComponent({
29+
setup() {
30+
return {};
31+
},
32+
});
33+
</script>

components/transfer/index.en-US.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ One or more elements can be selected from either column, one click on the proper
2929
| oneWay | Display as single direction style | boolean | false | 3.0.0 |
3030
| operations | A set of operations that are sorted from top to bottom. | string\[] | \['>', '&lt;'] | |
3131
| operationStyle | A custom CSS style used for rendering the operations column | CSSProperties | - | 3.0.0 |
32-
| pagination | Use pagination. Not work in render props | boolean \| { pageSize: number } | false | 3.0.0 |
32+
| pagination | Use pagination. Not work in render props | boolean \| { pageSize: number, simple: boolean, showSizeChanger?: boolean, showLessItems?: boolean } | false | 3.0.0 |
3333
| render | The function to generate the item shown on a column. Based on an record (element of the dataSource array), this function should return a element which is generated from that record. Also, it can return a plain object with `value` and `label`, `label` is a element and `value` is for title | Function(record) \| slot | | |
3434
| selectedKeys(v-model) | A set of keys of selected items. | string\[] | \[] | |
3535
| showSearch | If included, a search box is shown on each column. | boolean | false | |
3636
| showSelectAll | Show select all checkbox on the header | boolean | true | |
37+
| status | Set validation status | 'error' \| 'warning' | - | 3.3.0 |
3738
| targetKeys(v-model) | A set of keys of elements that are listed on the right column. | string\[] | \[] | |
3839
| titles | A set of titles that are sorted from left to right. | string\[] | - | |
3940

components/transfer/index.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CSSProperties, ExtractPropTypes, PropType } from 'vue';
2-
import { watchEffect, defineComponent, ref, watch, toRaw } from 'vue';
2+
import { computed, watchEffect, defineComponent, ref, watch, toRaw } from 'vue';
33
import PropTypes from '../_util/vue-types';
44
import { getPropsSlot } from '../_util/props-util';
55
import classNames from '../_util/classNames';
@@ -12,8 +12,10 @@ import { withInstall } from '../_util/type';
1212
import useConfigInject from '../_util/hooks/useConfigInject';
1313
import type { TransferListBodyProps } from './ListBody';
1414
import type { PaginationType } from './interface';
15-
import { useInjectFormItemContext } from '../form/FormItemContext';
15+
import { FormItemInputContext, useInjectFormItemContext } from '../form/FormItemContext';
1616
import type { RenderEmptyHandler } from '../config-provider/renderEmpty';
17+
import type { InputStatus } from '../_util/statusUtils';
18+
import { getStatusClassNames, getMergedStatus } from '../_util/statusUtils';
1719

1820
export type { TransferListProps } from './list';
1921
export type { TransferOperationProps } from './operation';
@@ -90,6 +92,7 @@ export const transferProps = () => ({
9092
children: { type: Function as PropType<(props: TransferListBodyProps) => VueNode> },
9193
oneWay: { type: Boolean, default: undefined },
9294
pagination: { type: [Object, Boolean] as PropType<PaginationType>, default: undefined },
95+
status: String as PropType<InputStatus>,
9396
onChange: Function as PropType<
9497
(targetKeys: string[], direction: TransferDirection, moveKeys: string[]) => void
9598
>,
@@ -125,6 +128,8 @@ const Transfer = defineComponent({
125128
const targetSelectedKeys = ref([]);
126129

127130
const formItemContext = useInjectFormItemContext();
131+
const formItemInputContext = FormItemInputContext.useInject();
132+
const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status));
128133
watch(
129134
() => props.selectedKeys,
130135
() => {
@@ -334,10 +339,16 @@ const Transfer = defineComponent({
334339
const leftActive = targetSelectedKeys.value.length > 0;
335340
const rightActive = sourceSelectedKeys.value.length > 0;
336341

337-
const cls = classNames(prefixCls.value, className, {
338-
[`${prefixCls.value}-disabled`]: disabled,
339-
[`${prefixCls.value}-customize-list`]: !!children,
340-
});
342+
const cls = classNames(
343+
prefixCls.value,
344+
className,
345+
{
346+
[`${prefixCls.value}-disabled`]: disabled,
347+
[`${prefixCls.value}-customize-list`]: !!children,
348+
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
349+
},
350+
getStatusClassNames(prefixCls.value, mergedStatus.value, formItemInputContext.hasFeedback),
351+
);
341352
const titles = props.titles;
342353
const leftTitle =
343354
(titles && titles[0]) ?? slots.leftTitle?.() ?? (locale.titles || ['', ''])[0];

components/transfer/index.zh-CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QAXskNI4G/Transfer.svg
3030
| oneWay | 展示为单向样式 | boolean | false | 3.0.0 |
3131
| operations | 操作文案集合,顺序从上至下 | string\[] | \['>', '&lt;'] | |
3232
| operationStyle | 操作栏的自定义样式 | CSSProperties | - | 3.0.0 |
33-
| pagination | 使用分页样式,自定义渲染列表下无效 | boolean \| { pageSize: number } | flase | 3.0.0 |
33+
| pagination | 使用分页样式,自定义渲染列表下无效 | boolean \| { pageSize: number, simple: boolean, showSizeChanger?: boolean, showLessItems?: boolean } | flase | 3.0.0 |
3434
| render | 每行数据渲染函数,该函数的入参为 `dataSource` 中的项,返回值为 element。或者返回一个普通对象,其中 `label` 字段为 element,`value` 字段为 title | Function(record)\| slot | | |
3535
| selectedKeys(v-model) | 设置哪些项应该被选中 | string\[] | \[] | |
3636
| showSearch | 是否显示搜索框 | boolean | false | |
3737
| showSelectAll | 是否展示全选勾选框 | boolean | true | |
38+
| status | 设置校验状态 | 'error' \| 'warning' | - | 3.3.0 |
3839
| targetKeys(v-model) | 显示在右侧框数据的 key 集合 | string\[] | \[] | |
3940
| titles | 标题集合,顺序从左至右 | string\[] | \['', ''] | |
4041

components/transfer/interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ export type PaginationType =
22
| boolean
33
| {
44
pageSize?: number;
5+
simple?: boolean;
6+
showSizeChanger?: boolean;
7+
showLessItems?: boolean;
58
};

components/transfer/list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { TransferDirection, TransferItem } from './index';
1515
const defaultRender = () => null;
1616

1717
function isRenderResultPlainObject(result: VNode) {
18-
return (
18+
return !!(
1919
result &&
2020
!isValidElement(result) &&
2121
Object.prototype.toString.call(result) === '[object Object]'

components/transfer/style/index.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import '../../style/mixins/index';
33
@import '../../checkbox/style/mixin';
44
@import './customize';
5+
@import './status';
56

67
@transfer-prefix-cls: ~'@{ant-prefix}-transfer';
78

components/transfer/style/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ import '../../input/style';
99
import '../../menu/style';
1010
import '../../dropdown/style';
1111
import '../../pagination/style';
12+
13+
// deps-lint-skip: form

0 commit comments

Comments
 (0)