table-context.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. import React from 'react';
  2. import { noop } from 'lodash';
  3. import { ColumnProps, GetVirtualizedListRef, RowKey } from './interface';
  4. import {
  5. BaseRowKeyType,
  6. BaseHeadWidth,
  7. } from '@douyinfe/semi-foundation/table/foundation';
  8. import type { ContextValue } from '../configProvider/context';
  9. export interface TableContextProps {
  10. children?: React.ReactNode;
  11. anyColumnFixed?: boolean;
  12. flattenedColumns?: ColumnProps[];
  13. tableWidth?: number;
  14. headWidths?: BaseHeadWidth[][];
  15. setHeadWidths?: (headWidth?: BaseHeadWidth[], index?: number) => void;
  16. getHeadWidths?: (index?: number) => number[];
  17. getCellWidths?: (flattenColumns: ColumnProps[], flattenedWidths?: number[], ignoreScrollBarKey?: boolean) => number[];
  18. handleRowExpanded?: (expanded: boolean, realKey: RowKey<any>, domEvent: React.MouseEvent<HTMLElement>) => void;
  19. renderExpandIcon?: (record: Record<string, any>, isNested?: boolean, groupKey?: string | number) => React.ReactNode;
  20. renderSelection?: (record?: Record<string, any>, isHeader?: boolean) => React.ReactNode;
  21. getVirtualizedListRef?: GetVirtualizedListRef;
  22. setBodyHasScrollbar?: (bodyHasScrollBar: boolean) => void;
  23. direction?: ContextValue['direction']
  24. }
  25. const TableContext = React.createContext<TableContextProps>({
  26. headWidths: [],
  27. setHeadWidths: noop,
  28. handleRowExpanded: noop,
  29. });
  30. export default TableContext;