index.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. class Table<RecordType extends Record<string, any> = Data> extends React.PureComponent<TableProps<RecordType>> {
  9. static Column = Column;
  10. static DEFAULT_KEY_COLUMN_SELECTION = strings.DEFAULT_KEY_COLUMN_SELECTION;
  11. static DEFAULT_KEY_COLUMN_EXPAND = strings.DEFAULT_KEY_COLUMN_EXPAND;
  12. static propTypes = {
  13. ...NormalTable.propTypes,
  14. resizable: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
  15. };
  16. static defaultProps = {
  17. hideExpandedColumn: true,
  18. };
  19. tableRef: React.RefObject<NormalTable<RecordType>>;
  20. constructor(props: TableProps) {
  21. super(props);
  22. this.tableRef = React.createRef();
  23. }
  24. getCurrentPageData = () => this.tableRef.current && this.tableRef.current.getCurrentPageData();
  25. render() {
  26. // eslint-disable-next-line prefer-destructuring
  27. const props = this.props;
  28. if (props.resizable) {
  29. return <ResizableTable {...props} ref={this.tableRef} />;
  30. } else {
  31. return <NormalTable<RecordType> {...props} ref={this.tableRef} />;
  32. }
  33. }
  34. }
  35. export * from './interface';
  36. export default Table;