index.jsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React, { useMemo, useState, useRef } from 'react';
  2. import { Resizable } from 'react-resizable';
  3. // import classnames from 'classnames';
  4. import { addClass, removeClass } from '@douyinfe/semi-foundation/utils/classnames';
  5. import Table from '../..';
  6. import ResizableTable from '../../ResizableTable';
  7. import './index.scss';
  8. export default function ResizableDemo() {
  9. const { current: ResizableTitle } = useRef(props => {
  10. const { onResize, onResizeStart, onResizeStop, width, ...restProps } = props;
  11. if (typeof width !== 'number') {
  12. return <th {...restProps} />;
  13. }
  14. return (
  15. <Resizable
  16. width={width}
  17. height={0}
  18. onResize={onResize}
  19. onResizeStart={onResizeStart}
  20. onResizeStop={onResizeStop}
  21. draggableOpts={{ enableUserSelectHack: false }}
  22. >
  23. <th {...restProps} />
  24. </Resizable>
  25. );
  26. });
  27. const components = {
  28. header: {
  29. cell: ResizableTitle,
  30. },
  31. };
  32. const [columns, setColumns] = useState([
  33. {
  34. title: 'Date',
  35. dataIndex: 'date',
  36. width: 200,
  37. },
  38. {
  39. title: 'Amount',
  40. dataIndex: 'amount',
  41. width: 100,
  42. },
  43. {
  44. title: 'Type',
  45. dataIndex: 'type',
  46. width: 100,
  47. },
  48. {
  49. title: 'Note',
  50. dataIndex: 'note',
  51. width: 100,
  52. },
  53. {
  54. title: 'Action',
  55. key: 'action',
  56. render: () => <a>Delete</a>,
  57. },
  58. ]);
  59. const data = [
  60. {
  61. key: 0,
  62. date: '2018-02-11',
  63. amount: 120,
  64. type: 'income',
  65. note: 'transfer',
  66. },
  67. {
  68. key: 1,
  69. date: '2018-03-11',
  70. amount: 243,
  71. type: 'income',
  72. note: 'transfer',
  73. },
  74. {
  75. key: 2,
  76. date: '2018-04-11',
  77. amount: 98,
  78. type: 'income',
  79. note: 'transfer',
  80. },
  81. ];
  82. return (
  83. <div id="components-table-demo-resizable-column">
  84. {/* <Table bordered components={components} columns={finalColumns} dataSource={data} /> */}
  85. <ResizableTable columns={columns} dataSource={data} />
  86. </div>
  87. );
  88. }