chore: update table, list types (#2694)

* fix: table typo

* fix: list typo

* fix: update table, list return JSX.Element typo

* fix: xxxRender merge params

* fix: change table event return type `void`
This commit is contained in:
言肆 2020-08-17 21:12:17 +08:00 committed by GitHub
parent 17456b68fc
commit 54d2418249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 516 additions and 470 deletions

View File

@ -4,21 +4,24 @@
import { AntdComponent } from '../component'; import { AntdComponent } from '../component';
import { Meta } from '../meta'; import { Meta } from '../meta';
import { VNodeChild } from 'vue';
export declare class ListItem extends AntdComponent { export declare class ListItem extends AntdComponent {
static Meta: typeof Meta; static Meta: typeof Meta;
$props: {
/** /**
* The actions content of list item. If itemLayout is vertical, shows the content on bottom, * The actions content of list item. If itemLayout is vertical, shows the content on bottom,
* otherwise shows content on the far right. * otherwise shows content on the far right.
* @type any (VNode[] | slot) * @type any (VNode[] | slot)
*/ */
actions: any; actions?: VNodeChild | JSX.Element;
/** /**
* The extra content of list item. If itemLayout is vertical, shows the content on right, * The extra content of list item. If itemLayout is vertical, shows the content on right,
* otherwise shows content on the far right. * otherwise shows content on the far right.
* @type any (string | slot) * @type any (string | slot)
*/ */
extra: any; extra?: VNodeChild | JSX.Element;
};
} }

66
types/list/list.d.ts vendored
View File

@ -3,104 +3,118 @@
// Definitions: https://github.com/vueComponent/ant-design-vue/types // Definitions: https://github.com/vueComponent/ant-design-vue/types
import { AntdComponent } from '../component'; import { AntdComponent } from '../component';
import { VNode } from 'vue'; import { VNodeChild } from 'vue';
import { Pagination } from '../pagination'; import { Pagination } from '../pagination';
import { ListItem } from './list-item'; import { ListItem } from './list-item';
export declare type ColumnCount = '' | 1 | 2 | 3 | 4 | 6 | 8 | 12 | 24; export declare type ColumnCount = '' | 1 | 2 | 3 | 4 | 6 | 8 | 12 | 24;
export declare class PaginationConfig extends Pagination { export declare class PaginationConfig extends Pagination {
position: 'top' | 'bottom' | 'both'; position?: 'top' | 'bottom' | 'both';
}
export interface Item {
item?: any;
index?: number;
} }
export class List extends AntdComponent { export class List extends AntdComponent {
static Item: typeof ListItem; static Item: typeof ListItem;
$props: {
/** /**
* Toggles rendering of the border around the list * Toggles rendering of the border around the list
* @default false * @default false
* @type boolean * @type boolean
*/ */
bordered: boolean; bordered?: boolean;
/** /**
* List footer renderer * List footer renderer
* @type any (string | slot) * @type any (string | slot)
*/ */
footer: any; footer?: VNodeChild | JSX.Element;
/** /**
* The grid type of list. You can set grid to something like {gutter: 16, column: 4} * The grid type of list. You can set grid to something like {gutter: 16, column: 4}
* @type object * @type object
*/ */
grid: { grid?: {
gutter: number; gutter?: number;
column: ColumnCount; column?: ColumnCount;
xs: ColumnCount; xs?: ColumnCount;
sm: ColumnCount; sm?: ColumnCount;
md: ColumnCount; md?: ColumnCount;
lg: ColumnCount; lg?: ColumnCount;
xl: ColumnCount; xl?: ColumnCount;
xxl: ColumnCount; xxl?: ColumnCount;
}; };
/** /**
* List header renderer * List header renderer
* @type any (string | slot) * @type any (string | slot)
*/ */
header: any; header?: VNodeChild | JSX.Element;
/** /**
* The layout of list, default is horizontal, If a vertical list is desired, set the itemLayout property to vertical * The layout of list, default is horizontal,
* If a vertical list is desired, set the itemLayout property to vertical
*
* @type string * @type string
*/ */
itemLayout: string; itemLayout?: string | 'horizontal' | 'vertical';
/** /**
* Shows a loading indicator while the contents of the list are being fetched * Shows a loading indicator while the contents of the list are being fetched
* @default false * @default false
* @type boolean | object * @type boolean | object
*/ */
loading: boolean | object; loading?: boolean | object;
/** /**
* Shows a load more content * Shows a load more content
* @type any (string | slot) * @type any (string | slot)
*/ */
loadMore: any; loadMore?: VNodeChild | JSX.Element;
/** /**
* i18n text including empty text * i18n text including empty text
* @default emptyText: 'No Data' * @default emptyText: 'No Data'
* @type object * @type object
*/ */
locale: object; locale?: object;
/** /**
* Pagination config, hide it by setting it to false * Pagination config, hide it by setting it to false
* @default false * @default false
* @type boolean | object * @type boolean | object
*/ */
pagination: boolean | PaginationConfig; pagination?: boolean | PaginationConfig;
/** /**
* Toggles rendering of the split under the list item * Toggles rendering of the split under the list item
* @default true * @default true
* @type boolean * @type boolean
*/ */
split: boolean; split?: boolean;
/** /**
* Custom item renderer, slot="renderItem" and slot-scope="item, index" * dataSource array for list
* @default null
* @type Function
*/ */
renderItem: (item: any, index: number) => VNode; dataSource?: any[];
/**
* Custom item renderer, slot="renderItem" and slot-scope="{ item, index }"
* @default null
* @type Function()
*/
renderItem?: (item?: Item) => VNodeChild | JSX.Element;
/** /**
* Specify the key that will be used for uniquely identify each element * Specify the key that will be used for uniquely identify each element
* @default null * @default null
* @type Function * @type Function
*/ */
rowKey: (item: any) => string | number; rowKey?: (item: any) => string | number;
};
} }

8
types/meta.d.ts vendored
View File

@ -2,7 +2,7 @@
// Definitions by: akki-jat <https://github.com/akki-jat> // Definitions by: akki-jat <https://github.com/akki-jat>
// Definitions: https://github.com/vueComponent/ant-design-vue/types // Definitions: https://github.com/vueComponent/ant-design-vue/types
import { AntdComponent } from './component'; import { VNodeChild } from 'vue';
export declare class Meta { export declare class Meta {
$props: { $props: {
@ -10,18 +10,18 @@ export declare class Meta {
* The avatar of list item * The avatar of list item
* @type any (slot) * @type any (slot)
*/ */
avatar: any; avatar?: VNodeChild;
/** /**
* The description of list item * The description of list item
* @type any (string | slot) * @type any (string | slot)
*/ */
description: any; description?: string | VNodeChild;
/** /**
* The title of list item * The title of list item
* @type any (string | slot) * @type any (string | slot)
*/ */
title: any; title?: string | VNodeChild;
}; };
} }

View File

@ -3,18 +3,21 @@
// Definitions: https://github.com/vueComponent/ant-design-vue/types // Definitions: https://github.com/vueComponent/ant-design-vue/types
import { AntdComponent } from '../component'; import { AntdComponent } from '../component';
import { VNodeChild } from 'vue';
export declare class ColumnGroup extends AntdComponent { export declare class ColumnGroup extends AntdComponent {
$props: {
/** /**
* Title of the column group * Title of the column group
* @type any * @type any
*/ */
title: any; title?: VNodeChild | JSX.Element;
/** /**
* When using columns, you can use this property to configure the properties that support the slot, * When using columns, you can use this property to configure the properties that support the slot,
* such as slots: { title: 'XXX'} * such as slots: { title: 'XXX'}
* @type object * @type object
*/ */
slots: object; slots?: object;
};
} }

View File

@ -3,8 +3,7 @@
// Definitions: https://github.com/vueComponent/ant-design-vue/types // Definitions: https://github.com/vueComponent/ant-design-vue/types
import { AntdComponent } from '../component'; import { AntdComponent } from '../component';
import { VNode } from 'vue'; import { VNodeChild } from 'vue';
import { ScopedSlot } from 'vue/types/vnode';
export interface ColumnFilterItem { export interface ColumnFilterItem {
text?: string; text?: string;
@ -14,7 +13,16 @@ export interface ColumnFilterItem {
export declare type SortOrder = 'ascend' | 'descend'; export declare type SortOrder = 'ascend' | 'descend';
export interface Record {
text?: any;
record?: object;
index?: number;
}
export declare type CustomRenderFunction = (record: Record) => VNodeChild | JSX.Element;
export declare class Column extends AntdComponent { export declare class Column extends AntdComponent {
$props: {
/** /**
* specify how content is aligned * specify how content is aligned
* @default 'left' * @default 'left'
@ -30,7 +38,6 @@ export declare class Column extends AntdComponent {
*/ */
ellipsis?: boolean; ellipsis?: boolean;
/** /**
* Span of this column's title * Span of this column's title
* @type number * @type number
@ -117,7 +124,7 @@ export declare class Column extends AntdComponent {
* Renderer of the table cell. The return value should be a VNode, or an object for colSpan/rowSpan config * Renderer of the table cell. The return value should be a VNode, or an object for colSpan/rowSpan config
* @type Function | ScopedSlot * @type Function | ScopedSlot
*/ */
customRender?: Function | ScopedSlot; customRender?: CustomRenderFunction | VNodeChild | JSX.Element;
/** /**
* Sort function for local sort, see Array.sort's compareFunction. If you need sort buttons only, set to true * Sort function for local sort, see Array.sort's compareFunction. If you need sort buttons only, set to true
@ -142,7 +149,7 @@ export declare class Column extends AntdComponent {
* Title of this column * Title of this column
* @type any (string | slot) * @type any (string | slot)
*/ */
title?: any; title?: VNodeChild | JSX.Element;
/** /**
* Width of this column * Width of this column
@ -154,32 +161,13 @@ export declare class Column extends AntdComponent {
* Set props on per cell * Set props on per cell
* @type Function * @type Function
*/ */
customCell?: ( customCell?: (record: any, rowIndex: number) => object;
record: any,
rowIndex: number,
) => {
props: object;
attrs: object;
on: object;
class: object;
style: object;
nativeOn: object;
};
/** /**
* Set props on per header cell * Set props on per header cell
* @type * @type object
*/ */
customHeaderCell?: ( customHeaderCell?: (column: any) => object;
column: any,
) => {
props: object;
attrs: object;
on: object;
class: object;
style: object;
nativeOn: object;
};
/** /**
* Callback executed when the confirm filter button is clicked, Use as a filter event when using template or jsx * Callback executed when the confirm filter button is clicked, Use as a filter event when using template or jsx
@ -199,11 +187,5 @@ export declare class Column extends AntdComponent {
* @type object * @type object
*/ */
slots?: object; slots?: object;
};
/**
* When using columns, you can use this property to configure the properties that support the slot-scope,
* such as scopedSlots: { customRender: 'XXX'}
* @type object
*/
scopedSlots?: object;
} }

150
types/table/table.d.ts vendored
View File

@ -4,13 +4,13 @@
import { AntdComponent } from '../component'; import { AntdComponent } from '../component';
import { Spin } from '../spin'; import { Spin } from '../spin';
import { ScopedSlot, VNode } from 'vue/types/vnode';
import { Pagination } from '../pagination'; import { Pagination } from '../pagination';
import { Column } from './column'; import { Column } from './column';
import { ColumnGroup } from './column-group'; import { ColumnGroup } from './column-group';
import { VNodeChild } from 'vue';
export declare class PaginationConfig extends Pagination { export declare class PaginationConfig extends Pagination {
position: 'top' | 'bottom' | 'both'; position?: 'top' | 'bottom' | 'both';
} }
export interface customSelection { export interface customSelection {
@ -28,7 +28,7 @@ export interface customSelection {
* @default undefined * @default undefined
* @type string | VNode * @type string | VNode
*/ */
text?: string | VNode; text?: string | VNodeChild | JSX.Element;
/** /**
* On Select * On Select
@ -36,7 +36,7 @@ export interface customSelection {
* @default undefined * @default undefined
* @type Function * @type Function
*/ */
onSelect?: (changeableRowKeys?: any) => any; onSelect?: (changeableRowKeys?: any[]) => any;
} }
export interface TableRowSelection { export interface TableRowSelection {
@ -88,7 +88,7 @@ export interface TableRowSelection {
* Set the title of the selection column * Set the title of the selection column
* @type string | VNode * @type string | VNode
*/ */
columnTitle?: string | VNode; columnTitle?: VNodeChild | JSX.Element;
/** /**
* Callback executed when selected rows change * Callback executed when selected rows change
@ -115,39 +115,50 @@ export interface TableRowSelection {
onSelectInvert?: (selectedRows: Object[]) => any; onSelectInvert?: (selectedRows: Object[]) => any;
} }
export interface TableCustomRecord {
record?: any;
index?: number;
}
export interface ExpandedRowRenderRecord extends TableCustomRecord {
indent?: number;
expanded?: boolean;
}
export declare class Table extends AntdComponent { export declare class Table extends AntdComponent {
static Column: typeof Column; static Column: typeof Column;
static ColumnGroup: typeof ColumnGroup; static ColumnGroup: typeof ColumnGroup;
$props: {
/** /**
* Whether to show all table borders * Whether to show all table borders
* @default false * @default false
* @type boolean * @type boolean
*/ */
bordered: boolean; bordered?: boolean;
/** /**
* The column contains children to display * The column contains children to display
* @default 'children' * @default 'children'
* @type string | string[] * @type string | string[]
*/ */
childrenColumnName: string | string[]; childrenColumnName?: string | string[];
/** /**
* Columns of table * Columns of table
* @type any * @type array
*/ */
columns: any; columns: any[];
/** /**
* Override default table elements * Override default table elements
* @type object * @type object
*/ */
components: object; components?: object;
/** /**
* Data record array to be displayed * Data record array to be displayed
* @type any * @type array
*/ */
dataSource: any; dataSource: any;
@ -156,90 +167,95 @@ export declare class Table extends AntdComponent {
* @default false * @default false
* @type boolean * @type boolean
*/ */
defaultExpandAllRows: boolean; defaultExpandAllRows?: boolean;
/** /**
* Initial expanded row keys * Initial expanded row keys
* @type string[] * @type string[]
*/ */
defaultExpandedRowKeys: string[]; defaultExpandedRowKeys?: string[];
/** /**
* Current expanded row keys * Current expanded row keys
* @type string[] * @type string[]
*/ */
expandedRowKeys: string[]; expandedRowKeys?: string[];
/** /**
* Expanded container render for each row * Expanded container render for each row
* @type Function * @type Function
*/ */
expandedRowRender: (record: any, index: number, indent: number, expanded: boolean) => any; expandedRowRender?: (record?: ExpandedRowRenderRecord) => any;
/** /**
* Customize row expand Icon. * Customize row expand Icon.
* @type Function | ScopedSlot * @type Function | VNodeChild
*/ */
expandIcon: Function | ScopedSlot; expandIcon?: Function | VNodeChild | JSX.Element;
/** /**
* Whether to expand row by clicking anywhere in the whole row * Whether to expand row by clicking anywhere in the whole row
* @default false * @default false
* @type boolean * @type boolean
*/ */
expandRowByClick: boolean; expandRowByClick?: boolean;
/**
* The index of `expandIcon` which column will be inserted when `expandIconAsCell` is false. default 0
*/
expandIconColumnIndex?: number;
/** /**
* Table footer renderer * Table footer renderer
* @type Function | ScopedSlot * @type Function | VNodeChild
*/ */
footer: Function | ScopedSlot; footer?: Function | VNodeChild | JSX.Element;
/** /**
* Indent size in pixels of tree data * Indent size in pixels of tree data
* @default 15 * @default 15
* @type number * @type number
*/ */
indentSize: number; indentSize?: number;
/** /**
* Loading status of table * Loading status of table
* @default false * @default false
* @type boolean | object * @type boolean | object
*/ */
loading: boolean | Spin; loading?: boolean | Spin | VNodeChild | JSX.Element;
/** /**
* i18n text including filter, sort, empty text, etc * i18n text including filter, sort, empty text, etc
* @default { filterConfirm: 'Ok', filterReset: 'Reset', emptyText: 'No Data' } * @default { filterConfirm: 'Ok', filterReset: 'Reset', emptyText: 'No Data' }
* @type object * @type object
*/ */
locale: object; locale?: object;
/** /**
* Pagination config or [Pagination] (/components/pagination/), hide it by setting it to false * Pagination config or [Pagination] (/components/pagination/), hide it by setting it to false
* @type boolean | PaginationConfig * @type boolean | PaginationConfig
*/ */
pagination: boolean | PaginationConfig; pagination?: boolean | PaginationConfig;
/** /**
* Row's className * Row's className
* @type Function * @type Function
*/ */
rowClassName: (record: any, index: number) => string; rowClassName?: (record?: TableCustomRecord) => string;
/** /**
* Row's unique key, could be a string or function that returns a string * Row's unique key, could be a string or function that returns a string
* @default 'key' * @default 'key'
* @type string | Function * @type string | Function
*/ */
rowKey: string | Function; rowKey?: string | Function;
/** /**
* Row selection config * Row selection config
* @type object * @type object
*/ */
rowSelection: TableRowSelection; rowSelection?: TableRowSelection;
/** /**
* Set horizontal or vertical scrolling, can also be used to specify the width and height of the scroll area. * Set horizontal or vertical scrolling, can also be used to specify the width and height of the scroll area.
@ -247,58 +263,86 @@ export declare class Table extends AntdComponent {
* you need to add style .ant-table td { white-space: nowrap; }. * you need to add style .ant-table td { white-space: nowrap; }.
* @type object * @type object
*/ */
scroll: { x: number | true; y: number }; scroll?: { x: number | true; y: number };
/** /**
* Whether to show table header * Whether to show table header
* @default true * @default true
* @type boolean * @type boolean
*/ */
showHeader: boolean; showHeader?: boolean;
/** /**
* Size of table * Size of table
* @default 'default' * @default 'default'
* @type string * @type string
*/ */
size: 'default' | 'middle' | 'small' | 'large'; size?: 'default' | 'middle' | 'small' | 'large';
/** /**
* Table title renderer * Table title renderer
* @type Function | ScopedSlot * @type Function | ScopedSlot
*/ */
title: Function | ScopedSlot; title?: Function | VNodeChild | JSX.Element;
/** /**
* Set props on per header row * Set props on per header row
* @type Function * @type Function
*/ */
customHeaderRow: ( customHeaderRow?: (column: any, index: number) => object;
column: any,
index: number,
) => {
props: object;
attrs: object;
on: object;
class: object;
style: object;
nativeOn: object;
};
/** /**
* Set props on per row * Set props on per row
* @type Function * @type Function
*/ */
customRow: ( customRow?: (record: any, index: number) => object;
record: any,
index: number, /**
) => { * `table-layout` attribute of table element
props: object; * `fixed` when header/columns are fixed, or using `column.ellipsis`
attrs: object; *
on: object; * @see https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout
class: object; * @version 1.5.0
style: object; */
nativeOn: object; tableLayout?: 'auto' | 'fixed' | string;
/**
* the render container of dropdowns in table
* @param triggerNode
* @version 1.5.0
*/
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement;
/**
* Data can be changed again before rendering.
* The default configuration of general user empty data.
* You can configured globally through [ConfigProvider](https://antdv.com/components/config-provider-cn/)
*
* @version 1.5.4
*/
transformCellText?: Function;
/**
* Callback executed when pagination, filters or sorter is changed
* @param pagination
* @param filters
* @param sorter
* @param currentDataSource
*/
onChange?: (pagination: object, filters, sorter, { currentDataSource }) => void;
/**
* Callback executed when the row expand icon is clicked
*
* @param expanded
* @param record
*/
onExpand: (expanded, record) => void;
/**
* Callback executed when the expanded rows change
* @param expandedRows
*/
onExpandedRowsChange: (expandedRows: any) => void;
}; };
transformCellText: Function;
} }