1
0

zebra.tsx 4.0 KB

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