index.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import NormalTable from './Table';
  4. import ResizableTable from './ResizableTable';
  5. import Column from './Column';
  6. import { strings } from '@douyinfe/semi-foundation/table/constants';
  7. import { TableProps, Data } from './interface';
  8. import ConfigContext, { ContextValue } from '../configProvider/context';
  9. class Table<RecordType extends Record<string, any> = Data> extends React.PureComponent<TableProps<RecordType>> {
  10. static Column = Column;
  11. static DEFAULT_KEY_COLUMN_SELECTION = strings.DEFAULT_KEY_COLUMN_SELECTION;
  12. static DEFAULT_KEY_COLUMN_EXPAND = strings.DEFAULT_KEY_COLUMN_EXPAND;
  13. static propTypes = {
  14. ...NormalTable.propTypes,
  15. resizable: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
  16. };
  17. static defaultProps = {
  18. hideExpandedColumn: true,
  19. };
  20. static contextType = ConfigContext;
  21. tableRef: React.RefObject<NormalTable<RecordType>>;
  22. context: ContextValue;
  23. constructor(props: TableProps) {
  24. super(props);
  25. this.tableRef = React.createRef();
  26. }
  27. getCurrentPageData = () => this.tableRef.current && this.tableRef.current.getCurrentPageData();
  28. render() {
  29. // eslint-disable-next-line prefer-destructuring
  30. const props = this.props;
  31. const direction = this.props.direction ?? this.context.direction;
  32. if (props.resizable) {
  33. return <ResizableTable {...props} ref={this.tableRef} direction={direction} />;
  34. } else {
  35. return <NormalTable<RecordType> {...props} ref={this.tableRef} direction={direction} />;
  36. }
  37. }
  38. }
  39. export * from './interface';
  40. export default Table;