tdesign-mobile-vue
Version:
tdesign-mobile-vue
101 lines (100 loc) • 3.26 kB
TypeScript
import { LoadingProps } from '../loading';
import type { TNode, ClassName, HTMLElementAttributes } from '../common';
export interface TdBaseTableProps<T extends TableRowData = TableRowData> {
bordered?: boolean;
cellEmptyContent?: string | TNode<BaseTableCellParams<T>>;
columns?: Array<BaseTableCol<T>>;
data?: Array<T>;
empty?: string | TNode;
fixedRows?: Array<number>;
footerSummary?: string | TNode;
height?: string | number;
loading?: boolean | TNode;
loadingProps?: Partial<LoadingProps>;
maxHeight?: string | number;
rowAttributes?: TableRowAttributes<T>;
rowClassName?: ClassName | ((params: RowClassNameParams<T>) => ClassName);
rowKey: string;
rowspanAndColspan?: TableRowspanAndColspanFunc<T>;
showHeader?: boolean;
stripe?: boolean;
tableContentWidth?: string;
tableLayout?: 'auto' | 'fixed';
verticalAlign?: 'top' | 'middle' | 'bottom';
onCellClick?: (context: BaseTableCellEventContext<T>) => void;
onRowClick?: (context: RowEventContext<T>) => void;
onScroll?: (params: {
e: Event;
}) => void;
onScrollToBottom?: () => void;
}
export interface BaseTableInstanceFunctions<T extends TableRowData = TableRowData> {
refreshTable: () => void;
}
export interface BaseTableCol<T extends TableRowData = TableRowData> {
align?: 'left' | 'right' | 'center';
cell?: string | TNode<BaseTableCellParams<T>>;
className?: TableColumnClassName<T> | TableColumnClassName<T>[];
colKey?: string;
ellipsis?: boolean | TNode<BaseTableCellParams<T>>;
ellipsisTitle?: boolean | TNode<BaseTableColParams<T>>;
fixed?: 'left' | 'right';
minWidth?: string | number;
render?: TNode<BaseTableRenderParams<T>>;
title?: string | TNode<{
col: BaseTableCol;
colIndex: number;
}>;
width?: string | number;
}
export type TableRowAttributes<T> = HTMLElementAttributes | ((params: {
row: T;
rowIndex: number;
type: 'body' | 'foot';
}) => HTMLElementAttributes) | Array<TableRowAttributes<T>>;
export interface RowClassNameParams<T> {
row: T;
rowIndex: number;
rowKey?: string;
type?: 'body' | 'foot';
}
export type TableRowspanAndColspanFunc<T> = (params: BaseTableCellParams<T>) => RowspanColspan;
export interface RowspanColspan {
colspan?: number;
rowspan?: number;
}
export interface BaseTableCellEventContext<T> {
row: T;
col: BaseTableCol;
rowIndex: number;
colIndex: number;
e: MouseEvent;
}
export interface RowEventContext<T> {
row: T;
index: number;
e: MouseEvent;
}
export interface TableRowData {
[key: string]: any;
children?: TableRowData[];
}
export interface BaseTableCellParams<T> {
row: T;
rowIndex: number;
col: BaseTableCol<T>;
colIndex: number;
}
export type TableColumnClassName<T> = ClassName | ((context: CellData<T>) => ClassName);
export interface CellData<T> extends BaseTableCellParams<T> {
type: 'th' | 'td';
}
export interface BaseTableColParams<T> {
col: BaseTableCol<T>;
colIndex: number;
}
export interface BaseTableRenderParams<T> extends BaseTableCellParams<T> {
type: RenderType;
}
export type RenderType = 'cell' | 'title';
export type DataType = TableRowData;