table-context.ts 1.4 KB

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