///
import { ReactNode, UIEventHandler, ReactElement, CSSProperties, MouseEventHandler, WheelEventHandler, HTMLAttributes, RefObject } from 'react';
import { ResizeObserver } from '@juggle/resize-observer';
import { EventListenerHandler } from '@befe/brick-utils';
import { ConfiguredComponent } from '@befe/brick-core';
import { ButtonProps } from '@befe/brick-comp-button';
import { CheckboxProps } from '@befe/brick-comp-checkbox';
import { SwitchProps } from '@befe/brick-comp-switch';
import { MenuItemProps } from '@befe/brick-comp-menu';
import { PopoverConfirmProps, PopoverProps } from '@befe/brick-comp-popover';
import { StickyController } from './utils/sticky';
/**
* @public
*/
export interface TdProps {
className?: string;
colSpan?: number;
rowSpan?: number;
}
type OperationPropsBase = ButtonProps & MenuItemProps;
/**
* @public
*/
export interface OperationProps extends OperationPropsBase {
key?: string;
label?: string;
dropList?: Array;
popoverConfirmProps?: PopoverConfirmProps;
popoverProps?: PopoverProps;
}
export declare const TABLE_SIZES: readonly ["sm", "md"];
type TableSize = (typeof TABLE_SIZES)[number];
export declare const TABLE_LINE_SPACINGS: readonly ["compact", "regular"];
type TableLineSpacing = (typeof TABLE_LINE_SPACINGS)[number];
export declare const TABLE_NO_DATA_TYPES: readonly ["empty", "search", "error", "success"];
export type TableNoDataType = (typeof TABLE_NO_DATA_TYPES)[number];
/**
* TableRow extends `Record`
* @public
*/
export interface TableRow extends Record {
/**
* 树状数据.行层级
* @private
*/
_level?: number;
/**
* 树状数据.子行
*/
children?: TableRow[];
}
type CallbackGivesRow = {
bivarianceHack(row: TRow, rowIdx: number): Val;
}['bivarianceHack'];
declare const SORT_ORDER_ASCENT = "ascent";
declare const SORT_ORDER_DESCENT = "descent";
declare const SORT_ORDER_ORIGINAL = "original";
type SortOrder = typeof SORT_ORDER_ORIGINAL | typeof SORT_ORDER_ASCENT | typeof SORT_ORDER_DESCENT;
/**
* @public
*/
export interface TableCol {
/**
* 列的主键
* 可以对应到数据行的字段名
*/
key: string | string[];
/**
* 列头的内容
*/
thContent?: ReactNode;
/**
* 列头的内容的 title tip
* 默认 title tip 与列头的内容一致
*/
thTitle?: string;
/**
* 列的行内容
*
* 如不指定,则默认为 `row => row[key]`
*/
tdContent?: CallbackGivesRow;
/**
* 列的行内容的 title tip
*
* 默认 title tip 与行内容一致
*/
tdTitle?: CallbackGivesRow;
/**
* 此列的 td 的 props
*/
tdProps?: CallbackGivesRow;
/**
* 固定列于左/右
*/
fixed?: 'left' | 'right';
/**
* 作为 “序号列” 的,单元改个
*/
serial?: CallbackGivesRow;
/**
* 作为"选择列"的 checkbox props
*
* **注意** 如果返回的 ReactElement 不是 ``,比如 ``,
* 需要自行控制其中 `` 的 size 等以符合其在 Table 中的样式要求
*/
checkbox?: CallbackGivesRow;
/**
* 作为"开关列"的 switch props
*
* **注意** 如果返回的 ReactElement 不是 ``,比如 ``,
* 需要自行控制其中 `` 的 size 等以符合其在 Table 中的样式要求
*/
switch?: CallbackGivesRow;
/**
* 作为"操作列"的 button 列表
*
* **注意** 如果返回的 ReactElement 不是 ``,比如 ``,
* 需要自行控制其中 `` 的 size, type 等以符合其在 Table 中的样式要求
*/
operations?: CallbackGivesRow>;
/**
* 操作列操作个数超过 N 个时,收起到 "更多"
*
* 如果不需要收起到"更多",设为 Infinity 即可
*
* @default 3
*/
operationsEllipsisMoreThan?: number;
/**
* 操作列 "更多" 下拉的触发方式
*
* @default hover
*/
operationsEllipsisMoreTriggerType?: 'hover' | 'click';
/**
* 横向对齐方式
*/
align?: 'left' | 'center' | 'right';
/**
* 列宽
*/
width?: number;
/**
* 或不需要,暂不支持
*/
maxWidth?: number;
/**
* 或不需要,暂不支持
*/
minWidth?: number;
/**
* 合并列子列
*/
children?: TableCol[];
/**
* 该列千分位字符,如果不定义则默认使用 `props.thousandSeparator`
*
* 如果想不加千分位,设置为 ''
*/
thousandSeparator?: string;
/**
* 表头合并列
*
* 只支持非 fix head 情景(不设置 `props.maxBodyHeight`)下的 root columns 使用
*/
colSpan?: number;
/**
* 排序比较函数, 用于 "Table 内排序"
*
* 比较函数返回值结合当前排序状态得出比较结果
* - ascent 升序时以 `compare(a, b) * 1` 作为比较结果
* - descent 降序时以 `compare(a, b) * -1` 作为比较结果
* - original 不排序,相当于 `compare(a, b) * 0`
*
* 比较结果
* - `result > 0`: 将 b 排在 a 前
* - `result < 0`: 将 a 排在 b 前
* - `result === 0`: 保持原顺序
*
* **注意** 为了区别 "Table 外排序" 与 "Table 内排序" 不混用,
* 只要任意列指定了 "col.sortable",即会判定为 "Table 外排序", `col.compare` 无效
*/
compare?: ((a: TableRow, b: TableRow) => number);
/**
* 是否为排序列,用于 "Table 外排序"
*
* **注意** 为了区别 "Table 外排序" 与 "Table 内排序" 不混用,
* 只要任意列指定了 "col.sortable",即会判定为 "Table 外排序", `col.compare` 无效
*/
sortable?: boolean;
}
interface ColItem extends TableCol {
rowSpan?: number;
preColumns?: ColItem[];
surColumns?: ColItem[];
fixedPoint?: 'left-last' | 'right-first';
}
export interface TableProps {
/**
* 自定义 class
*/
className?: string;
/**
* 尺寸
*/
size?: TableSize;
/**
* 行高空间
*/
lineSpacing?: TableLineSpacing;
/**
* 数据列定义
*/
columns?: TableCol[];
/**
* 数据行的主键字段,用以唯一标识数据行
*/
rowId?: string | ((row: TableRow, idx: number) => string);
/**
* 行 tr 的 props
*/
rowTrProps?: (row: TableRow, idx: number) => HTMLAttributes & Record;
/**
* 源数据
*/
data?: TableRow[];
/**
* 是否处于 loading 状态
*/
loading?: boolean;
/**
* 指定一个 table body 高度以在纵向溢出时,固定列头滚动
*/
maxBodyHeight?: number;
/**
* 表头每一行的所占的文字行数
* - 1 单行,overflow ellipsis
* - n > 1 固定 N 行,overflow ellipsis
*/
headRowLines?: number;
/**
* 表体每一行的所占的文字行数
* - 1 单行,overflow ellipsis
* - n > 1 固定 N 行,overflow ellipsis
* - 0 自由高度,不支持固定列下使用
*/
bodyRowLines?: number;
/**
* 空内容单元格的内容
*/
emptyCellContent?: string;
/**
* 是否显示列表框
*/
bordered?: boolean;
/**
* 所有列对于右对齐的纯数字自动添加的千分位符
*
* - 如果想让Table不自动千分位,可设置为 `''`
* - 然后对于需要加入千分符的数字 column,配置 `column.thousandSeparator: ','`
*/
thousandSeparator?: string;
/**
* 屏幕粘连模式:随页面(或指定滚动容器)滚动时
* - 表头吸附在顶部(head stick to top)
* - 横向滚动条吸附在底部(scrollbar stick to bottom)
*
* - `true`:吸附偏移均为 0,相对页面(window)滚动
* - `{top, bottom}`:分别指定表头吸顶、滚动条吸底的偏移
* - `{scrollTarget}`:表格处于固定高度内层滚动容器时,传入该容器 ref,
* 吸顶/吸底改为相对该容器计算;缺省则相对页面
*/
sticky?: boolean | {
top?: number;
bottom?: number;
scrollTarget?: RefObject;
};
/**
* 无数据类型,用以控制无数据插图
*/
noDataType?: TableNoDataType;
/**
* 无数据提示信息
*/
noDataMessage?: string;
/**
* 插图尺寸
*/
illusSize?: 'md' | 'lg';
/**
* 树状表格展开行的 id 列表控制值
*/
expandedIds?: string[];
/**
* 树状表格展开行的 id 列表默认值
*/
defaultExpandedIds?: string[];
/**
* 树状表格展开行 id 列表 change 回调
*/
onChangeExpandedIds?: (expandedIds: string[]) => void;
/**
* 是否启用 hover 行高亮,默认开启
*
* - 跨行合并单元格情景下一般需要关闭,以避免跨行单元格仅在所夸首行 hover 高亮的情况
* - fixed columns 情况下关闭可稍微提升渲染性能
*/
hover?: boolean;
/**
* 排序是否为多列
*/
sortMultiple?: boolean;
/**
* 可排序列点击排序时的回调
*
* 注意 回调参数中的 sortItem 顺序不是稳定的,最后一项对应的是最后点击的排序列
*/
onSort?: (sorts: SortItem[]) => void;
}
interface SortItem {
key: string;
order: SortOrder;
compare?: ColItem['compare'];
}
interface TableState {
columns: ColItem[];
leafColumns: ColItem[];
scrollX: boolean;
expandedIds: string[];
headTableWidth?: number;
colWidth: Record;
colWidthList: number[];
sorts: SortItem[];
innerSort: boolean;
}
interface CellStyle {
checkboxTypeWidth: number;
paddingLeft: number;
paddingRight: number;
}
export declare class Table extends ConfiguredComponent {
static displayName: string;
static defaultProps: {
className: string;
rowId: string;
lineSpacing: string;
bordered: boolean;
headRowLines: number;
bodyRowLines: number;
thousandSeparator: string;
noDataType: string;
illusSize: string;
hover: boolean;
sortMultiple: boolean;
};
static getDerivedStateFromProps(nextProps: TableProps): Partial;
state: TableState;
componentLocale: import("@befe/brick-core").ComponentLocale<{
en_us: {
loading: string;
no_data_empty: string;
no_data_search: string;
no_data_error: string;
no_data_success: string;
ellipsis_more: string;
};
zh_cn: {
loading: string;
no_data_empty: string;
no_data_search: string;
no_data_error: string;
no_data_success: string;
ellipsis_more: string;
};
}>;
refTable: RefObject;
refMainBodyWrap: RefObject;
refMainBodyTable: RefObject;
refMainHeadWrap: RefObject;
refMainHeadTable: RefObject;
refFixedLeftBodyWrap: RefObject;
refFixedRightBodyWrap: RefObject;
stickyController: StickyController | null;
cellStyleFromCSS: {
normal: CellStyle;
bordered: CellStyle;
};
eventHandler: {
[K in 'windowResize' | 'windowScroll']?: EventListenerHandler | null;
};
resizeObserver: ResizeObserver;
lastScrollLeft: number;
lastScrollTop: number;
bodyWrapWidth: number;
bodyTableWidth: number;
scrollLeftMax: number;
scrollTopMax: number;
scrollBarWidth: number;
scrollXPosition: 'left' | 'right' | 'middle' | 'none';
scrollYPosition: 'top' | 'bottom' | 'middle' | 'none';
get className(): string;
get scrollXPositionClasses(): string[];
get scrollYPositionClasses(): string[];
get striped(): boolean;
get size(): "sm" | "md";
get expandButtonMargin(): number;
get checkboxSize(): 'md';
get iconButtonSize(): "md" | "lg";
get textButtonSize(): "sm" | "md";
get borderWidth(): number;
get emptyCellContent(): string;
get columns(): ColItem[];
get isTreeData(): boolean | undefined;
get flattenData(): TableRow[];
get hasData(): boolean;
get bodyRowLines(): number;
get headRowLines(): number;
get canUseSticky(): boolean;
get stickyOption(): {
top: number;
bottom: number;
scrollTarget?: RefObject;
} | null;
get isScrollableX(): boolean;
get isScrollableY(): boolean;
get cellCSSStyle(): CellStyle;
getColKey(col: ColItem): string;
getRowKey(row: TableRow, index: number): string;
getTdContentByKey(col: ColItem, row: TableRow): TableRow;
getIndentSize(level?: number): number | undefined;
getSwitchSize(size: SwitchProps['size']): "sm" | "md";
getColClass(col: ColItem): string;
getColWidth(col: ColItem): number;
getExplicitColWidth(col: ColItem): number | undefined;
getFixedColWidth(col: ColItem): number;
getFixedColStyle(colIdx: number, columns: ColItem[]): CSSProperties;
getCellContentStyle(col: ColItem): {
width?: undefined;
} | {
width: number | undefined;
};
getHeadRows(columns: ColItem[], currentRow?: number, rows?: ColItem[][], preColumns?: ColItem[], surColumns?: ColItem[]): ColItem[][];
getLeafColumns(fixedType?: 'left' | 'right'): ColItem[];
getFixCellClassName(colIdx: number, columns: ColItem[]): string;
getTdProps(colIdx: number, columns: ColItem[], row: TableRow, rowIdx: number): TdProps;
getTablePartWrapStyle(fixedType?: 'left' | 'right'): {
innerStyle: CSSProperties;
outerStyle: CSSProperties;
};
forceRedraw: import("lodash").DebouncedFunc<() => void>;
handleScroll: UIEventHandler;
handleScrollLeft: UIEventHandler;
handleScrollTop: UIEventHandler;
handleWheel: WheelEventHandler;
handleResize: import("lodash").DebouncedFunc<() => void>;
handleMouseLeaveMainTable: MouseEventHandler;
updateScrollXPosition: import("lodash").DebouncedFuncLeading<() => void>;
updateScrollYPosition: import("lodash").DebouncedFuncLeading<() => void>;
wheelScroll(delta: number, scrollType: 'Left' | 'Top', elemList: Array): boolean;
wheelLeft: import("lodash").DebouncedFunc<(deltaX: number) => void>;
wheelTop: import("lodash").DebouncedFunc<(deltaY: number) => void>;
toggleExpanded: (rowId: string) => void;
toggleExpandedAll: () => void;
sort(rows: TableRow[]): void;
setSort(col: ColItem): void;
updateColWidth(prevState?: Readonly): void;
syncHeadTableWidth(prevState?: Readonly): void;
observeTableResize(): void;
unobserveTableResize(): void;
updateScrollDomState(): void;
updateScrollbarWidthDomState(): void;
updateScrollLeftDomState(): void;
updateWidthDomState(): void;
updateHeightDomState(): void;
resetScrollLeft(): void;
resetScrollTop(): void;
toggleHover(key: string, isHover: boolean): void;
changeExpanded(expandedIds: string[]): void;
renderColGroup(shouldUseAutoColWidth?: boolean, fixedType?: 'left' | 'right'): import("react/jsx-runtime").JSX.Element;
renderSorter(col: ColItem): import("react/jsx-runtime").JSX.Element | null;
renderThContent(col: ColItem, prepend?: ReactNode): import("react/jsx-runtime").JSX.Element;
renderTdContentOperations(col: ColItem, row: TableRow, rowIdx: number): import("react/jsx-runtime").JSX.Element[] | null;
renderTdContent(col: ColItem, row: TableRow, rowIdx: number, prepend: ReactNode): import("react/jsx-runtime").JSX.Element;
renderHeadWrap(columns?: ColItem[], fixedType?: 'left' | 'right'): import("react/jsx-runtime").JSX.Element;
renderThead(columns?: ColItem[], fixedType?: 'right' | 'left'): import("react/jsx-runtime").JSX.Element;
renderTbodyEmpty(): import("react/jsx-runtime").JSX.Element;
renderNoDataIcon(): import("react/jsx-runtime").JSX.Element;
renderNoDataMessage(): "" | import("react/jsx-runtime").JSX.Element;
renderNoDataContent(): import("react/jsx-runtime").JSX.Element | null;
renderTbody(fixedType?: 'right' | 'left'): import("react/jsx-runtime").JSX.Element;
renderFixedTable(type: 'left' | 'right'): import("react/jsx-runtime").JSX.Element | null;
renderMainTable(): import("react/jsx-runtime").JSX.Element;
setupSticky(): void;
teardownSticky(): void;
componentDidMount(): void;
componentWillUnmount(): void;
componentDidUpdate(prevProps: Readonly, prevState: Readonly): void;
render(): import("react/jsx-runtime").JSX.Element;
}
export {};