rowSelection.jsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import React, { useMemo } from 'react';
  2. import { Table, Avatar } from '@douyinfe/semi-ui';
  3. import { IconMore } from '@douyinfe/semi-icons';
  4. /**
  5. * test in cypress
  6. */
  7. function App() {
  8. const columns = [
  9. {
  10. title: '标题',
  11. dataIndex: 'name',
  12. width: 400,
  13. render: (text, record, index) => {
  14. return (
  15. <div>
  16. <Avatar size="small" shape="square" src={record.nameIconSrc} style={{ marginRight: 12 }}></Avatar>
  17. {text}
  18. </div>
  19. );
  20. }
  21. },
  22. {
  23. title: '大小',
  24. dataIndex: 'size',
  25. },
  26. {
  27. title: '所有者',
  28. dataIndex: 'owner',
  29. render: (text, record, index) => {
  30. return (
  31. <div>
  32. <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>{typeof text === 'string' && text.slice(0, 1)}</Avatar>
  33. {text}
  34. </div>
  35. );
  36. }
  37. },
  38. {
  39. title: '更新日期',
  40. dataIndex: 'updateTime',
  41. },
  42. {
  43. title: '',
  44. dataIndex: 'operate',
  45. render: () => {
  46. return <IconMore />;
  47. }
  48. },
  49. ];
  50. const data = [
  51. {
  52. key: '1',
  53. name: 'Semi Design 设计稿.fig',
  54. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
  55. size: '2M',
  56. owner: '姜鹏志',
  57. updateTime: '2020-02-02 05:13',
  58. avatarBg: 'grey'
  59. },
  60. {
  61. key: '2',
  62. name: 'Semi Design 分享演示文稿',
  63. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  64. size: '2M',
  65. owner: '郝宣',
  66. updateTime: '2020-01-17 05:31',
  67. avatarBg: 'red'
  68. },
  69. {
  70. key: '3',
  71. name: '设计文档',
  72. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  73. size: '34KB',
  74. owner: 'Zoey Edwards',
  75. updateTime: '2020-01-26 11:01',
  76. avatarBg: 'light-blue'
  77. },
  78. {
  79. key: '4',
  80. name: 'Semi Pro 设计稿.fig',
  81. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
  82. size: '2M',
  83. owner: '姜鹏志',
  84. updateTime: '2020-02-02 05:13',
  85. avatarBg: 'grey'
  86. },
  87. {
  88. key: '5',
  89. name: 'Semi Pro 分享演示文稿',
  90. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  91. size: '2M',
  92. owner: '郝宣',
  93. updateTime: '2020-01-17 05:31',
  94. avatarBg: 'red'
  95. },
  96. {
  97. key: '6',
  98. name: 'Semi Pro 设计文档',
  99. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  100. size: '34KB',
  101. owner: 'Zoey Edwards',
  102. updateTime: '2020-01-26 11:01',
  103. avatarBg: 'light-blue'
  104. },
  105. ];
  106. const rowSelection = {
  107. getCheckboxProps: record => ({
  108. disabled: record.name === '设计文档', // Column configuration not to be checked
  109. name: record.name,
  110. }),
  111. onSelect: (record, selected) => {
  112. console.log(`select row: ${selected}`, record);
  113. },
  114. onSelectAll: (selected, selectedRows) => {
  115. console.log(`select all rows: ${selected}`, selectedRows);
  116. },
  117. onChange: (selectedRowKeys, selectedRows) => {
  118. console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  119. },
  120. };
  121. const pagination = useMemo(() => ({
  122. pageSize: 3
  123. }), []);
  124. return <Table columns={columns} dataSource={data} rowSelection={rowSelection} pagination={pagination} />;
  125. }
  126. App.storyName = 'fixed rowSelection #325';
  127. export default App;