From 741ec4c835e9a63128fdb1573963adc59a7df0f7 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 6 Mar 2022 16:59:49 +0800 Subject: [PATCH] feat: select add fieldNames --- components/list/index.tsx | 40 ++++----- .../__tests__/__snapshots__/demo.test.js.snap | 11 +++ components/select/demo/field-names.vue | 81 +++++++++++++++++++ components/select/demo/index.vue | 3 + components/select/index.en-US.md | 1 + components/select/index.tsx | 8 +- components/select/index.zh-CN.md | 1 + package.json | 1 + 8 files changed, 125 insertions(+), 21 deletions(-) create mode 100644 components/select/demo/field-names.vue diff --git a/components/list/index.tsx b/components/list/index.tsx index 97f1ca7f9..52756116b 100644 --- a/components/list/index.tsx +++ b/components/list/index.tsx @@ -1,17 +1,17 @@ -import type { App, Plugin, ExtractPropTypes, PropType } from 'vue'; +import type { App, Plugin, ExtractPropTypes, PropType, HTMLAttributes } from 'vue'; import { provide, defineComponent, ref, watch, computed, toRef } from 'vue'; -import PropTypes, { withUndefined } from '../_util/vue-types'; +import PropTypes from '../_util/vue-types'; +import type { SpinProps } from '../spin'; import Spin from '../spin'; import type { PaginationConfig } from '../pagination'; -import Pagination, { paginationConfig } from '../pagination'; +import Pagination from '../pagination'; import { Row } from '../grid'; import Item from './Item'; import { flattenChildren } from '../_util/props-util'; import initDefaultProps from '../_util/props-util/initDefaultProps'; import type { Key } from '../_util/type'; -import { tuple } from '../_util/type'; import ItemMeta from './ItemMeta'; import useConfigInject from '../_util/hooks/useConfigInject'; import useBreakpoint from '../_util/hooks/useBreakpoint'; @@ -36,41 +36,41 @@ export interface ListGridType { xxxl?: ColumnCount; } -export const ListSize = tuple('small', 'default', 'large'); - +export type ListSize = 'small' | 'default' | 'large'; export type ListItemLayout = 'horizontal' | 'vertical'; -export const listProps = { +export const listProps = () => ({ bordered: PropTypes.looseBool, dataSource: PropTypes.array, extra: PropTypes.any, grid: { type: Object as PropType, default: undefined }, - itemLayout: PropTypes.oneOf(tuple('horizontal', 'vertical')), - loading: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.object])), + itemLayout: String as PropType, + loading: { + type: [Boolean, Object] as PropType, + default: undefined as boolean | (SpinProps & HTMLAttributes), + }, loadMore: PropTypes.any, - pagination: withUndefined( - PropTypes.oneOfType([ - PropTypes.shape(paginationConfig()).loose, - PropTypes.looseBool, - ]), - ), - prefixCls: PropTypes.string, + pagination: { + type: [Boolean, Object] as PropType, + default: undefined as false | PaginationConfig, + }, + prefixCls: String, rowKey: [String, Number, Function] as PropType Key)>, renderItem: PropTypes.any, - size: PropTypes.oneOf(ListSize), + size: String as PropType, split: PropTypes.looseBool, header: PropTypes.any, footer: PropTypes.any, locale: { type: Object as PropType, }, -}; +}); export interface ListLocale { emptyText: any; } -export type ListProps = Partial>; +export type ListProps = Partial>>; import { ListContextKey } from './contextKey'; import type { RenderEmptyHandler } from '../config-provider/renderEmpty'; @@ -78,7 +78,7 @@ import type { RenderEmptyHandler } from '../config-provider/renderEmpty'; const List = defineComponent({ name: 'AList', Item, - props: initDefaultProps(listProps, { + props: initDefaultProps(listProps(), { dataSource: [], bordered: false, split: true, diff --git a/components/select/__tests__/__snapshots__/demo.test.js.snap b/components/select/__tests__/__snapshots__/demo.test.js.snap index 359f4996d..b7c6039cd 100644 --- a/components/select/__tests__/__snapshots__/demo.test.js.snap +++ b/components/select/__tests__/__snapshots__/demo.test.js.snap @@ -153,6 +153,17 @@ exports[`renders ./components/select/demo/custom-dropdown-menu.vue correctly 1`] `; +exports[`renders ./components/select/demo/field-names.vue correctly 1`] = ` +
+ + +
Lucy + +
+ +
+`; + exports[`renders ./components/select/demo/hide-selected.vue correctly 1`] = `