index.tsx 4.3 KB

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