/* eslint-disable max-len */ import React, { ReactNode, MutableRefObject } from 'react'; import { BaseProps } from '../_base/baseComponent'; import { PaginationProps } from '../pagination'; import { CheckboxProps } from '../checkbox'; import { DropdownProps } from '../dropdown'; import { Locale } from '../locale/interface'; import { ArrayElement } from '../_base/base'; import { strings } from '@douyinfe/semi-foundation/table/constants'; import { BaseRowKeyType, BaseSortOrder, BaseGroupBy, BaseGroupByFn, BaseFixed, BaseAlign, BaseChangeInfoSorter, BaseSorter, BaseFilter, BaseChangeInfoFilter, BaseIncludeGroupRecord, BaseEllipsis } from '@douyinfe/semi-foundation/table/foundation'; import { ScrollDirection, CSSDirection } from 'react-window'; import { TableCellProps } from './TableCell'; export interface TableProps = any> extends BaseProps { bordered?: boolean; children?: ReactNode; childrenRecordName?: string; className?: string; clickGroupedRowToExpand?: boolean; columns?: ColumnProps[]; components?: TableComponents; dataSource?: RecordType[]; defaultExpandAllGroupRows?: boolean; defaultExpandAllRows?: boolean; defaultExpandedRowKeys?: (string | number)[]; empty?: ReactNode; expandAllGroupRows?: boolean; expandAllRows?: boolean; expandCellFixed?: Fixed; expandIcon?: ExpandIcon; expandedRowKeys?: (string | number)[]; expandedRowRender?: ExpandedRowRender; expandRowByClick?: boolean; footer?: Footer; getVirtualizedListRef?: GetVirtualizedListRef; groupBy?: GroupBy; hideExpandedColumn?: boolean; id?: string; indentSize?: number; loading?: boolean; pagination?: TablePagination; prefixCls?: string; renderGroupSection?: RenderGroupSection; renderPagination?: RenderPagination; resizable?: Resizable; rowExpandable?: RowExpandable; rowKey?: RowKey; rowSelection?: RowSelection; scroll?: Scroll; showHeader?: boolean; size?: Size; style?: React.CSSProperties; title?: Title; virtualized?: Virtualized; onChange?: OnChange; onExpand?: OnExpand; onExpandedRowsChange?: OnExpandedRowsChange; onGroupedRow?: OnGroupedRow; onHeaderRow?: OnHeaderRow; onRow?: OnRow; sticky?: Sticky; direction?: Direction } export interface ColumnProps = any> { [x: string]: any; align?: Align; children?: Array>; className?: string; colSpan?: number; dataIndex?: string; defaultFilteredValue?: any[]; defaultSortOrder?: SortOrder; filterChildrenRecord?: boolean; filterDropdown?: React.ReactNode; filterDropdownProps?: DropdownProps; filterDropdownVisible?: boolean; filterIcon?: FilterIcon; filterMultiple?: boolean; filteredValue?: any[]; filters?: Filter[]; fixed?: Fixed; key?: string | number; render?: ColumnRender; renderFilterDropdownItem?: RenderFilterDropdownItem; sortChildrenRecord?: boolean; sortOrder?: SortOrder; sorter?: Sorter; title?: ColumnTitle; useFullRender?: boolean; width?: string | number; onCell?: OnCell; onFilter?: OnFilter; onFilterDropdownVisibleChange?: OnFilterDropdownVisibleChange; onHeaderCell?: OnHeaderCell; ellipsis?: BaseEllipsis; /** * self control whether to update cell for performance reasons */ shouldCellUpdate?: (props: TableCellProps, prevProps: TableCellProps) => boolean } export type Align = BaseAlign; export type SortOrder = BaseSortOrder; export type FilterIcon = boolean | React.ReactNode | FilterIconRenderFunction; export interface Filter extends BaseFilter { value?: any; text?: React.ReactNode; children?: Filter[] } export type Fixed = BaseFixed; export type OnCell = (record?: RecordType, rowIndex?: number) => OnCellReturnObject; export type OnFilter = (filteredValue?: any, record?: RecordType) => boolean; export type OnFilterDropdownVisibleChange = (visible?: boolean) => void; export type OnHeaderCell = (record?: RecordType, columnIndex?: number) => OnHeaderCellReturnObject; export type ColumnRender = (text: any, record: RecordType, index: number, options?: RenderOptions) => ColumnRenderReturnType; export type RenderFilterDropdownItem = (itemInfo?: FilterDropdownItem) => ReactNode; export type Sorter = BaseSorter; export type ColumnTitle = React.ReactNode | ((ColumnTitleProps?: ColumnTitleProps) => React.ReactNode); export type FilterIconRenderFunction = (filtered: boolean) => React.ReactNode; export type ColumnTitleProps = { sorter?: React.ReactNode; filter?: React.ReactNode; selection?: React.ReactNode }; export type ColumnRenderReturnType = React.ReactNode | RenderReturnObject; export interface RenderReturnObject { [x: string]: any; children: React.ReactNode; props: { [x: string]: any; colSpan?: number; rowSpan?: number } } export interface FilterDropdownItem { [x: string]: any; value?: any; text?: React.ReactNode; onChange?: React.MouseEventHandler; level?: number; filterMultiple?: boolean; checked?: boolean } export interface RenderOptions { expandIcon?: React.ReactNode; selection?: React.ReactNode; indentText?: React.ReactNode } export interface OnCellReturnObject extends React.TdHTMLAttributes { [x: string]: any; style?: React.CSSProperties; className?: string; onClick?: (e: React.MouseEvent) => void } export interface OnHeaderCellReturnObject extends React.ThHTMLAttributes { [x: string]: any; style?: React.CSSProperties; className?: string; onClick?: (e: React.MouseEvent) => void } interface OnRowReturnOmit { ref?: React.RefObject } export interface OnRowReturnObject extends Omit, HTMLTableRowElement>, keyof OnRowReturnOmit> { [x: string]: any; className?: string; style?: React.CSSProperties; onClick?: (e: React.MouseEvent) => void } export interface OnGroupedRowReturnObject extends Omit, 'className'> { [x: string]: any; style?: React.CSSProperties; onClick?: (e: React.MouseEvent) => void } export type OnHeaderRowReturnObject = Omit, 'ref' | 'style'>; export interface Scroll { x?: number | string; y?: number | string; scrollToFirstRowOnChange?: boolean } export interface Data { [x: string]: any; key?: string | number } export interface TableComponents { table?: ReactNode; header?: { outer?: ReactNode; wrapper?: ReactNode; row?: ReactNode; cell?: ReactNode }; body?: { outer?: ReactNode; wrapper?: ReactNode; row?: ReactNode; cell?: ReactNode; colgroup?: { wrapper?: ReactNode; col?: ReactNode } }; footer?: { wrapper?: ReactNode; row?: ReactNode; cell?: ReactNode; outer?: ReactNode } } export interface RowSelectionProps { className?: string; disabled?: boolean; fixed?: Fixed; getCheckboxProps?: GetCheckboxProps; hidden?: boolean; selectedRowKeys?: (string | number)[]; title?: ReactNode; width?: string | number; onChange?: RowSelectionOnChange; onSelect?: RowSelectionOnSelect; onSelectAll?: RowSelectionOnSelectAll } export type GetCheckboxProps = (record: RecordType) => CheckboxProps; export type RowSelectionOnChange = (selectedRowKeys?: (string | number)[], selectedRows?: RecordType[]) => void; export type RowSelectionOnSelect = ( record?: RecordType, selected?: boolean, selectedRows?: RecordType[], nativeEvent?: React.MouseEvent ) => void; export type RowSelectionOnSelectAll = (selected?: boolean, selectedRows?: RecordType[], changedRows?: RecordType[]) => void; export type ExpandIcon = ((expanded?: boolean) => React.ReactNode) | React.ReactNode; export type ExpandedRowRender = (record?: RecordType, index?: number, expanded?: boolean) => React.ReactNode; export type Footer = ReactNode | ((pageData?: RecordType[]) => React.ReactNode); export type FormatPageText = ((pageInfo?: { currentStart?: number; currentEnd?: number; total?: number }) => React.ReactNode) | boolean; export type GetVirtualizedListRef = (ref: MutableRefObject) => void; export type GroupByFunction = BaseGroupByFn; export type GroupBy = BaseGroupBy; export type Size = ArrayElement; export type Title = React.ReactNode | ((pageData?: RecordType[]) => React.ReactNode); export type PaginationPosition = ArrayElement; export type Pagination = TablePaginationProps | boolean; export type TablePagination = Pagination; export interface ChangeInfoFilter extends BaseChangeInfoFilter { filters?: Filter[]; onFilter?: OnFilter } export type ChangeInfoSorter = BaseChangeInfoSorter; export interface ChangeInfo { pagination?: TablePaginationProps; filters?: ChangeInfoFilter[]; sorter?: ChangeInfoSorter; extra?: Record } export type OnChange = (changeInfo: ChangeInfo) => void; export type OnRow = (record?: RecordType, index?: number) => OnRowReturnObject; export type OnGroupedRow = (record?: RecordType, index?: number) => OnGroupedRowReturnObject; export type OnHeaderRow = (columns?: ColumnProps[], index?: number) => OnHeaderRowReturnObject; export type OnExpandedRowsChange = (expandedRows?: IncludeGroupRecord[]) => void; export type OnExpand = (expanded?: boolean, record?: IncludeGroupRecord, mouseEvent?: React.MouseEvent) => void; export type RenderGroupSection = (groupKey?: string | number, group?: (string | number)[]) => ReactNode | { [x: string]: any; children: ReactNode }; export type RenderPagination = (paginationProps: TablePaginationProps) => ReactNode; export type RowExpandable = (record?: RecordType) => boolean; export type RowKey = BaseRowKeyType | ((record?: RecordType) => string); export type RowSelection = RowSelectionProps | boolean; export type VirtualizedOnScrollArgs = { scrollDirection?: ScrollDirection; scrollOffset?: number; scrollUpdateWasRequested?: boolean }; export type VirtualizeItemSizeRow = { sectionRow?: boolean; expandedRow?: boolean }; export type VirtualizedMode = 'list' | 'grid'; export type VirtualizedItemSizeFn = (index?: number, row?: VirtualizeItemSizeRow) => number; export type VirtualizedItemSize = number | VirtualizedItemSizeFn; export type VirtualizedOnScroll = (object: VirtualizedOnScrollArgs) => void; export interface VirtualizedProps { [x: string]: any; mode?: VirtualizedMode; itemSize?: VirtualizedItemSize; onScroll?: VirtualizedOnScroll } export type Virtualized = boolean | VirtualizedProps; export interface TablePaginationProps extends BaseProps, PaginationProps { position?: PaginationPosition; formatPageText?: FormatPageText } export type Resizable = ResizableProps | boolean; export interface ResizableProps { onResize?: ResizeFn; onResizeStart?: ResizeFn; onResizeStop?: ResizeFn } export type ResizeFn = (column: RecordType) => RecordType; export interface BodyScrollEvent extends React.UIEvent { [x: string]: any; currentTarget: any; target: any } export type BodyScrollPosition = 'both' | 'middle' | 'left' | 'right'; export type TableLocale = Locale['Table']; export type Direction = CSSDirection; export type IncludeGroupRecord = BaseIncludeGroupRecord; export type Sticky = boolean | { top?: number }