es-grid-template
Version:
es-grid-template
183 lines (182 loc) • 7.06 kB
TypeScript
import type { CSSProperties, Key, ReactNode } from 'react';
import React from 'react';
import { noop } from 'rxjs';
import type { ArtColumn } from '../interfaces';
import { TableDOMHelper } from './helpers/TableDOMUtils';
import type { ResolvedUseVirtual, VerticalRenderRange, VirtualEnum } from './interfaces';
import type { LoadingContentWrapperProps } from './loading';
import type { BaseTableCSSVariables } from './styles';
import type { CommandClick, ExpandedRowRender, IFormat, IFTheme, RenderExpandIcon, RowClassName } from '../../grid-component/type';
export type PrimaryKey = string | ((row: any) => string);
export type ColumnResizeMode = 'onChange' | 'onEnd';
export type ExpandableConfig<RecordType> = {
expandedRowKeys?: readonly Key[];
defaultExpandedRowKeys?: readonly Key[];
expandedRowRender?: ExpandedRowRender<RecordType>;
columnTitle?: React.ReactNode;
expandRowByClick?: boolean;
expandIcon?: RenderExpandIcon<RecordType>;
onExpand?: (expanded: boolean, rowData: RecordType) => void;
onExpandedRowsChange?: (expandedKeys: readonly Key[]) => void;
defaultExpandAllRows?: boolean;
expandIconColumnIndex?: number;
showExpandAll?: boolean;
showExpandColumn?: boolean;
expandedRowClassName?: string | RowClassName<RecordType>;
childrenColumnName?: string;
rowExpandable?: (rowData: RecordType) => boolean;
};
export type BaseTableProps = {
id?: string;
commandClick?: (args: CommandClick<any>) => void;
/** Primary key */
primaryKey?: PrimaryKey;
/** Data source for table body */
dataSource: any[];
originData?: any[];
format?: IFormat;
/** Data source for table footer */
footerDataSource?: any[];
/** Column definitions */
columns: ArtColumn[];
/** Enable virtual scrolling */
useVirtual?: VirtualEnum | {
horizontal?: VirtualEnum;
vertical?: VirtualEnum;
header?: VirtualEnum;
};
/** Estimated height for each row when virtual scrolling is enabled */
estimatedRowHeight?: number;
/** Whether table header is sticky, default is true */
isStickyHeader?: boolean;
/** Distance from the top when header is sticky */
stickyTop?: number;
/** Whether table footer is sticky, default is true */
isStickyFooter?: boolean;
/** Distance from the bottom when footer is sticky */
stickyBottom?: number;
/** Custom class name */
className?: string;
/** Custom inline styles */
style?: CSSProperties & BaseTableCSSVariables;
/** Whether the table has a header */
showHeader?: boolean;
theme?: IFTheme;
/** Whether table has a horizontal sticky scrollbar */
hasStickyScroll?: boolean;
/** Height of the sticky horizontal scrollbar */
stickyScrollHeight?: 'auto' | number;
/** Use outer border instead of cell borders */
useOuterBorder?: boolean;
/** Table loading state */
isLoading?: boolean;
/** Cell height when data source is empty */
emptyCellHeight?: number;
/** @deprecated Content shown when data is empty. Use components.EmptyContent instead */
emptyContent?: ReactNode;
/** Override internal table components */
components?: {
/** Wrapper component for table content while loading */
LoadingContentWrapper?: React.ComponentType<LoadingContentWrapperProps>;
/** Loading icon component */
LoadingIcon?: React.ComponentType;
/** Component rendered when data is empty */
EmptyContent?: React.ComponentType;
/** Override tbody > tr component */
Row?: React.ComponentType<{
row: any;
rowIndex: number;
trProps: unknown;
}>;
/** Override tbody > td component */
Cell?: React.ComponentType<{
row: any;
rowIndex: number;
colIndex: number;
tdProps: unknown;
column: ArtColumn;
}>;
/** Override tbody component */
TableBody?: React.ComponentType<{
tbodyProps: unknown;
}>;
};
/** Default column width */
defaultColumnWidth?: number;
/** Virtual scroll debug label (for internal debugging) */
virtualDebugLabel?: string;
columnResizeMode?: ColumnResizeMode;
onResizeEnd?: (columns: ArtColumn[]) => void;
getRowProps?: (row: any, rowIndex: number) => React.HTMLAttributes<HTMLTableRowElement>;
expandable?: ExpandableConfig<any>;
};
interface BaseTableState {
/** Whether to show sticky scrollbar */
hasScroll: boolean;
/**
* Whether lock sections need to be rendered.
* When table width is smaller than total column width, lock sections are required.
*/
needRenderLock: boolean;
/** Vertical virtual scroll offset */
offsetY: number;
/** Max vertical render height */
maxRenderHeight: number;
/** Horizontal virtual scroll offset */
offsetX: number;
/** Max horizontal render width */
maxRenderWidth: number;
}
export declare class BaseTable extends React.Component<BaseTableProps, BaseTableState> {
static defaultProps: {
showHeader: boolean;
isStickyHeader: boolean;
stickyTop: number;
footerDataSource: any[];
isStickyFooter: boolean;
stickyBottom: number;
hasStickyScroll: boolean;
stickyScrollHeight: string;
useVirtual: string;
estimatedRowHeight: number;
isLoading: boolean;
components: {};
getRowProps: typeof noop;
dataSource: any[];
originData: any[];
};
private rowHeightManager;
private artTableWrapperRef;
private domHelper;
private rootSubscription;
private lastInfo;
private props$;
/** @deprecated `BaseTable.getDoms()` is deprecated. Please do not call it. */
getDoms(): TableDOMHelper;
constructor(props: Readonly<BaseTableProps>);
/** Customize the scrollbar width to match the table width, ensuring the scrollbar thumb has the same width */
private updateStickyScroll;
private renderTableHeader;
private updateOffsetX;
private syncHorizontalScrollFromTableBody;
/** Synchronize horizontal scroll offset */
private syncHorizontalScroll;
getVerticalRenderRange(useVirtual: ResolvedUseVirtual): VerticalRenderRange;
private renderTableBody;
private renderTableFooter;
private renderLockShadows;
private renderStickyScroll;
render(): JSX.Element;
componentDidMount(): void;
componentDidUpdate(prevProps: Readonly<BaseTableProps>, prevState: Readonly<BaseTableState>): void;
private didMountOrUpdate;
private updateScrollLeftWhenLayoutChanged;
private initSubscriptions;
componentWillUnmount(): void;
/** Update references to DOM nodes to allow other methods to access them */
private updateDOMHelper;
private updateRowHeightManager;
/** Calculate the total rendered width of all columns and determine whether lock sections need rendering */
private adjustNeedRenderLock;
}
export {};