zent
Version:
一套前端设计语言和基于React的实现
141 lines (140 loc) • 6.43 kB
TypeScript
import { PureComponent } from 'react';
import { II18nLocaleGrid } from '../i18n';
import Store from './Store';
import Header from './Header';
import Footer from './Footer';
import { IGridSelectionAllCheckboxProps } from './SelectionCheckboxAll';
import { IGridColumn, IGridOnChangeConfig, GridScrollPosition, GridSortType, GridRowClassNameType, GridPaginationType, IGridPageInfo, IGridScrollDelta, IGridSelection, IGridExpandation, IGridRowClickHandler, IGridOnExpandHandler, IGridInnerFixedType, IGridColumnBodyRenderFunc, IGridBatchRender } from './types';
import { ICheckboxEvent } from '../checkbox';
import { IRadioEvent } from '../radio';
import { IBlockLoadingProps } from '../loading/props';
export interface IGridProps<Data = any, RowProps = {}, Key = string> {
size?: 'medium' | 'large' | 'small';
columns: IGridColumn[];
datasets: ReadonlyArray<Data>;
rowKey?: string;
tableLayout?: 'auto' | 'fixed';
onChange?: (conf: IGridOnChangeConfig) => any;
scroll?: IGridScrollDelta;
sortBy?: string;
sortType?: GridSortType;
defaultSortType?: GridSortType;
emptyLabel?: React.ReactNode;
selection?: IGridSelection<Data, Key>;
expandation?: IGridExpandation<Data>;
loading?: boolean;
bordered?: boolean;
className?: string;
rowClassName?: GridRowClassNameType<Data>;
pageInfo?: IGridPageInfo;
paginationType?: GridPaginationType;
onRowClick?: IGridRowClickHandler<Data>;
ellipsis?: boolean;
onExpand?: IGridOnExpandHandler<Data>;
components?: {
row?: React.ComponentType<RowProps>;
};
rowProps?: (data: Data, index: number) => RowProps;
batchRender?: IGridBatchRender;
stickyBatch?: boolean;
autoStick?: boolean;
autoStickOffsetTop?: number;
disableHoverHighlight?: boolean;
loadingProps?: Omit<IBlockLoadingProps, 'loading'>;
}
export interface IGridState {
mouseOverRowIndex: number;
fixedColumnsBodyRowsHeight: Array<number | string>;
fixedColumnsHeadRowsHeight: Array<number | string>;
fixedColumnsBodyExpandRowsHeight: Array<number | string>;
expandRowKeys: boolean[];
showStickHead: boolean;
tableWidth?: number;
marginLeft?: string;
}
export interface IGridInnerColumn<Data> extends IGridColumn<Data> {
key?: string;
}
export declare class Grid<Data = any, RowProps = Record<string, unknown>, Key = string> extends PureComponent<IGridProps<Data, RowProps, Key>, IGridState> {
static defaultProps: Partial<IGridProps>;
mounted: boolean;
selectionPropsCache: {
[key: string]: {
disabled?: boolean;
reason?: React.ReactNode;
};
};
store: Store;
gridNode: import("react").RefObject<HTMLDivElement>;
footNode: import("react").RefObject<Footer>;
footEl: Element;
headerEl: Element;
headerNode: import("react").RefObject<Header<Data>>;
bodyTable: import("react").RefObject<HTMLDivElement>;
leftBody: import("react").RefObject<HTMLDivElement>;
rightBody: import("react").RefObject<HTMLDivElement>;
scrollBody: import("react").RefObject<HTMLDivElement>;
scrollHeader: import("react").RefObject<HTMLDivElement>;
scrollPosition: GridScrollPosition;
lastScrollLeft: number;
lastScrollTop: number;
stickyHead: import("react").RefObject<HTMLDivElement>;
constructor(props: IGridProps<Data, RowProps, Key>);
getExpandRowKeys(props: IGridProps<Data, RowProps, Key>): boolean[];
syncFixedTableRowHeight: () => void;
onChange: (conf: IGridOnChangeConfig) => void;
onPaginationChange: (pageSize: number, current: number) => void;
getDataKey: (data: Data, rowIndex: number | string) => any;
isAnyColumnsFixed: () => boolean;
isAnyColumnsLeftFixed: () => boolean;
isAnyColumnsRightFixed: () => boolean;
getLeftColumns: () => any;
getRightColumns: () => any;
handleExpandRow: (clickRow: number, rowData: Data) => (e: React.MouseEvent<HTMLSpanElement>) => void;
getExpandBodyRender: (expandRowKeys: boolean[], expandation: IGridExpandation) => IGridColumnBodyRenderFunc<Data>;
getSelectionColumn(props: IGridProps<Data, RowProps, Key>, columnsArg?: Array<IGridInnerColumn<Data>>): IGridInnerColumn<Data>;
getColumns: (props: IGridProps<Data, RowProps, Key>, columnsArg?: Array<IGridInnerColumn<Data>>, expandRowKeysArg?: boolean[]) => IGridInnerColumn<Data>[];
getBatchFixedStyle(): {
width?: undefined;
} | {
width: number;
};
getBatchComponents: (position: 'header' | 'foot') => JSX.Element;
getLeftFixedTable: () => JSX.Element[];
getRightFixedTable: () => JSX.Element[];
setScrollPosition(position: GridScrollPosition): void;
setScrollPositionClassName(): void;
forceScroll: (target: EventTarget, distance: number, direction: 'Left' | 'Top') => void;
handleBodyScrollRunOnceNextFrame: ((e: React.UIEvent<HTMLDivElement>) => void) & import("../utils/types").ICancelable;
handleBodyScroll: (e: React.UIEvent<HTMLDivElement>) => void;
onResize: () => void;
onRowMouseEnter: (mouseOverRowIndex: number) => void;
getTable: (options?: {
columns?: Array<IGridInnerColumn<Data>>;
fixed?: IGridInnerFixedType;
isStickyHead?: boolean;
headRef?: React.RefObject<HTMLDivElement>;
bodyRef?: React.RefObject<HTMLDivElement>;
}) => JSX.Element[];
getEmpty: (i18n: II18nLocaleGrid) => JSX.Element;
getSelectionPropsByItem: (data: Data, rowIndex: number | string, nextSelection?: IGridSelection<Data, Key>) => {
disabled?: boolean;
reason?: React.ReactNode;
};
isFixedLayout: () => boolean;
onSelectChange: (selectedRowKeys: Key[], data: Data | Data[]) => void;
handleSelect: (data: Data, rowIndex: string, e: ICheckboxEvent<unknown> | IRadioEvent<unknown>) => void;
handleBatchSelect: IGridSelectionAllCheckboxProps<Data>['onSelect'];
renderSelectionCheckbox: () => IGridColumnBodyRenderFunc<Data>;
renderSelectionRadio: () => IGridColumnBodyRenderFunc<Data>;
toggleBatchComponents: () => void;
onScroll: () => void;
getStickyHead: () => JSX.Element;
setStickyHeadWidth: () => void;
componentDidMount(): void;
componentWillUnmount(): void;
componentWillReceiveProps(nextProps: IGridProps<Data, RowProps, Key>): void;
componentDidUpdate(prevProps: any): void;
render(): JSX.Element;
}
export default Grid;