index.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import React from 'react';
  2. import { Table } from '@douyinfe/semi-ui';
  3. import './index.scss';
  4. const ariticle = `Semi Design 是由互娱社区前端团队与 UED
  5. 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的
  6. Web 应用。`;
  7. const columns = [
  8. {
  9. title: 'Name',
  10. dataIndex: 'name',
  11. render: text => <a href="javascript:;">{text}</a>,
  12. },
  13. {
  14. title: 'Age',
  15. dataIndex: 'age',
  16. },
  17. {
  18. title: 'Address',
  19. dataIndex: 'address',
  20. },
  21. ];
  22. const dataSource = [
  23. {
  24. key: '1',
  25. name: 'John Brown',
  26. age: 32,
  27. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  28. },
  29. {
  30. key: '2',
  31. name: 'Jim Green',
  32. age: 42,
  33. address: 'London No. 1 Lake Park',
  34. },
  35. {
  36. key: '3',
  37. name: 'Joe Black',
  38. age: 32,
  39. address: 'Sidney No. 1 Lake Park',
  40. },
  41. {
  42. key: '4',
  43. name: 'Disabled User',
  44. age: 99,
  45. address: 'Sidney No. 1 Lake Park',
  46. },
  47. ];
  48. const table = (
  49. <table>
  50. <thead>
  51. <tr>
  52. {columns.map((column, idx) => (
  53. <td key={column.dataIndex || idx}>{column.title}</td>
  54. ))}
  55. </tr>
  56. </thead>
  57. <tbody>
  58. {dataSource.map((data, dataIndex) => (
  59. <tr key={data.key || dataIndex}>
  60. {columns.map((column, columnIdx) => (
  61. <td key={column.dataIndex || columnIdx}>{data[column.dataIndex]}</td>
  62. ))}
  63. </tr>
  64. ))}
  65. </tbody>
  66. </table>
  67. );
  68. export default class LinkedScroll extends React.Component {
  69. constructor(props) {
  70. super(props);
  71. this.leftRef = null;
  72. this.ref = null;
  73. this.rightRef = null;
  74. }
  75. handleBodyScrollTop = e => {
  76. const target = e.target;
  77. if (e.currentTarget !== target) {
  78. return;
  79. }
  80. const { leftRef, ref, rightRef } = this;
  81. if (target.scrollTop !== this.lastScrollTop) {
  82. const scrollTop = target.scrollTop;
  83. if (leftRef && target !== leftRef) {
  84. leftRef.scrollTop = scrollTop;
  85. }
  86. if (rightRef && target !== rightRef) {
  87. rightRef.scrollTop = scrollTop;
  88. }
  89. if (ref && target !== ref) {
  90. ref.scrollTop = scrollTop;
  91. }
  92. }
  93. // Remember last scrollTop for scroll direction detecting.
  94. this.lastScrollTop = target.scrollTop;
  95. };
  96. render() {
  97. const content = table;
  98. return (
  99. <div style={{ position: 'relative', display: 'flex', padding: 20 }}>
  100. <div
  101. style={{ width: 200, height: 200, overflow: 'scroll' }}
  102. ref={node => (this.leftRef = node)}
  103. onScroll={this.handleBodyScrollTop}
  104. >
  105. <p>{content}</p>
  106. <p>{content}</p>
  107. </div>
  108. <div
  109. style={{ width: 200, height: 200, overflow: 'scroll' }}
  110. ref={node => (this.ref = node)}
  111. onScroll={this.handleBodyScrollTop}
  112. >
  113. <p>{content}</p>
  114. <p>{content}</p>
  115. </div>
  116. <div
  117. style={{ width: 200, height: 200, overflow: 'scroll' }}
  118. ref={node => (this.rightRef = node)}
  119. onScroll={this.handleBodyScrollTop}
  120. >
  121. <p>{content}</p>
  122. <p>{content}</p>
  123. </div>
  124. </div>
  125. );
  126. }
  127. }