ant-design/components/table/interface.tsx

224 lines
6.7 KiB
TypeScript
Raw Normal View History

2017-11-21 13:48:37 +08:00
import * as React from 'react';
import { SpinProps } from '../spin';
import { Store } from './createStore';
import { RadioChangeEvent } from '../radio';
import { CheckboxChangeEvent } from '../checkbox';
import { PaginationConfig } from '../pagination';
export { PaginationConfig } from '../pagination';
2017-11-21 13:48:37 +08:00
export type CompareFn<T> = ((a: T, b: T, sortOrder?: SortOrder) => number);
2017-11-21 13:48:37 +08:00
export type ColumnFilterItem = { text: string; value: string, children?: ColumnFilterItem[] };
export interface ColumnProps<T> {
title?: React.ReactNode | ((options: {
filters: TableStateFilters,
sortOrder?: SortOrder,
}) => React.ReactNode);
2017-11-21 13:48:37 +08:00
key?: React.Key;
dataIndex?: string;
2017-11-21 13:48:37 +08:00
render?: (text: any, record: T, index: number) => React.ReactNode;
align?: 'left' | 'right' | 'center';
2017-11-21 13:48:37 +08:00
filters?: ColumnFilterItem[];
onFilter?: (value: any, record: T) => boolean;
filterMultiple?: boolean;
filterDropdown?: React.ReactNode | ((props: Object) => React.ReactNode);
2017-11-21 13:48:37 +08:00
filterDropdownVisible?: boolean;
onFilterDropdownVisibleChange?: (visible: boolean) => void;
sorter?: boolean | CompareFn<T>;
defaultSortOrder?: SortOrder;
2017-11-21 13:48:37 +08:00
colSpan?: number;
width?: string | number;
className?: string;
fixed?: boolean | ('left' | 'right');
filterIcon?: React.ReactNode | ((filtered: boolean) => React.ReactNode);
2017-11-21 13:48:37 +08:00
filteredValue?: any[];
sortOrder?: SortOrder;
2017-11-21 13:48:37 +08:00
children?: ColumnProps<T>[];
onCellClick?: (record: T, event: any) => void;
onCell?: (record: T) => any;
onHeaderCell?: (props: ColumnProps<T>) => any;
2017-11-21 13:48:37 +08:00
}
export interface TableComponents {
table?: React.ReactType;
2017-11-21 13:48:37 +08:00
header?: {
wrapper?: React.ReactType;
row?: React.ReactType;
cell?: React.ReactType;
2017-11-21 13:48:37 +08:00
};
body?: {
wrapper?: React.ReactType;
row?: React.ReactType;
cell?: React.ReactType;
2017-11-21 13:48:37 +08:00
};
}
export interface TableLocale {
filterTitle?: string;
filterConfirm?: React.ReactNode;
filterReset?: React.ReactNode;
emptyText?: React.ReactNode | (() => React.ReactNode);
selectAll?: React.ReactNode;
selectInvert?: React.ReactNode;
2018-09-17 17:57:01 +08:00
sortTitle?: string;
2017-11-21 13:48:37 +08:00
}
export type RowSelectionType = 'checkbox' | 'radio';
2018-05-07 12:32:26 +08:00
export type SelectionSelectFn<T> = (record: T, selected: boolean, selectedRows: Object[], nativeEvent: Event) => any;
2017-11-21 13:48:37 +08:00
export type TableSelectWay = 'onSelect' | 'onSelectMultiple' | 'onSelectAll' | 'onSelectInvert';
2018-05-07 12:32:26 +08:00
2017-11-21 13:48:37 +08:00
export interface TableRowSelection<T> {
type?: RowSelectionType;
selectedRowKeys?: string[] | number[];
onChange?: (selectedRowKeys: string[] | number[], selectedRows: Object[]) => void;
2017-11-21 13:48:37 +08:00
getCheckboxProps?: (record: T) => Object;
onSelect?: SelectionSelectFn<T>;
onSelectMultiple?: (selected: boolean, selectedRows: Object[], changeRows: Object[]) => void;
onSelectAll?: (selected: boolean, selectedRows: Object[], changeRows: Object[]) => void;
onSelectInvert?: (selectedRows: Object[]) => void;
2017-11-21 13:48:37 +08:00
selections?: SelectionItem[] | boolean;
hideDefaultSelections?: boolean;
fixed?: boolean;
columnWidth?: string | number;
selectWay?: TableSelectWay;
columnTitle?: string | React.ReactNode;
2017-11-21 13:48:37 +08:00
}
export type SortOrder = 'descend' | 'ascend';
export interface SorterResult<T> {
column: ColumnProps<T>;
order: SortOrder;
field: string;
columnKey: string;
}
export type TableSize = 'default' | 'middle' | 'small';
2017-11-21 13:48:37 +08:00
export interface TableProps<T> {
prefixCls?: string;
dropdownPrefixCls?: string;
rowSelection?: TableRowSelection<T>;
pagination?: PaginationConfig | false;
size?: TableSize;
2017-11-21 13:48:37 +08:00
dataSource?: T[];
components?: TableComponents;
columns?: ColumnProps<T>[];
rowKey?: string | ((record: T, index: number) => string);
rowClassName?: (record: T, index: number) => string;
expandedRowRender?: (record: T, index: number, indent: number, expanded: boolean) => React.ReactNode;
2017-12-08 15:36:32 +08:00
defaultExpandAllRows?: boolean;
2017-11-21 13:48:37 +08:00
defaultExpandedRowKeys?: string[] | number[];
expandedRowKeys?: string[] | number[];
expandIconAsCell?: boolean;
expandIconColumnIndex?: number;
2017-12-08 15:36:32 +08:00
expandRowByClick?: boolean;
2017-11-21 13:48:37 +08:00
onExpandedRowsChange?: (expandedRowKeys: string[] | number[]) => void;
onExpand?: (expanded: boolean, record: T) => void;
onChange?: (
pagination: PaginationConfig,
filters: Record<keyof T, string[]>,
sorter: SorterResult<T>,
) => void;
2017-11-21 13:48:37 +08:00
loading?: boolean | SpinProps;
locale?: Object;
indentSize?: number;
onRowClick?: (record: T, index: number, event: Event) => void;
2017-11-21 13:48:37 +08:00
onRow?: (record: T, index: number) => any;
onHeaderRow?: (columns: ColumnProps<T>[], index: number) => any;
2017-11-21 13:48:37 +08:00
useFixedHeader?: boolean;
bordered?: boolean;
showHeader?: boolean;
footer?: (currentPageData: Object[]) => React.ReactNode;
title?: (currentPageData: Object[]) => React.ReactNode;
scroll?: { x?: boolean | number | string, y?: boolean | number | string };
childrenColumnName?: string;
bodyStyle?: React.CSSProperties;
className?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
2017-11-21 13:48:37 +08:00
}
export interface TableStateFilters {
[key: string]: string[];
}
export interface TableState<T> {
pagination: PaginationConfig;
2017-11-21 13:48:37 +08:00
filters: TableStateFilters;
sortColumn: ColumnProps<T> | null;
sortOrder?: SortOrder;
pivot?: number;
2017-11-21 13:48:37 +08:00
}
export type SelectionItemSelectFn = (key: string[]) => any;
export interface SelectionItem {
key: string;
text: React.ReactNode;
onSelect: SelectionItemSelectFn;
}
export interface SelectionCheckboxAllProps<T> {
store: Store;
locale: any;
disabled: boolean;
getCheckboxPropsByItem: (item: any, index: number) => any;
getRecordKey: (record: any, index?: number) => string;
data: T[];
prefixCls: string | undefined;
onSelect: (key: string, index: number, selectFunc: any) => void;
hideDefaultSelections?: boolean;
selections?: SelectionItem[] | boolean;
getPopupContainer: (triggerNode?: Element) => HTMLElement;
}
export interface SelectionCheckboxAllState {
checked?: boolean;
indeterminate?: boolean;
2017-11-21 13:48:37 +08:00
}
export interface SelectionBoxProps {
store: Store;
type?: RowSelectionType;
defaultSelection: string[];
rowIndex: string;
name?: string;
2017-11-21 13:48:37 +08:00
disabled?: boolean;
onChange: (e: RadioChangeEvent | CheckboxChangeEvent) => void;
2017-11-21 13:48:37 +08:00
}
export interface SelectionBoxState {
checked?: boolean;
}
2018-05-07 12:32:26 +08:00
export interface SelectionInfo<T> {
selectWay: TableSelectWay;
record?: T;
checked?: boolean;
changeRowKeys?: React.Key[];
nativeEvent?: Event;
}
2017-11-21 13:48:37 +08:00
export interface FilterMenuProps<T> {
locale: TableLocale;
selectedKeys: string[];
column: ColumnProps<T>;
confirmFilter: (column: ColumnProps<T>, selectedKeys: string[]) => any;
prefixCls: string;
dropdownPrefixCls: string;
getPopupContainer: (triggerNode?: Element) => HTMLElement;
}
export interface FilterMenuState {
selectedKeys: string[];
keyPathOfSelectedItem: { [key: string]: string };
2017-11-21 13:48:37 +08:00
visible?: boolean;
}
export type PrepareParamsArgumentsReturn<T> = [
any,
string[],
Object,
{
currentDataSource: T[],
}
];