expand.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React from 'react';
  2. import { Table, Avatar, Descriptions, Tag } from '@douyinfe/semi-ui';
  3. import { IconMore } from '@douyinfe/semi-icons';
  4. const columns = [
  5. {
  6. title: '标题',
  7. width: 500,
  8. dataIndex: 'name',
  9. render: (text, record, index) => {
  10. return (
  11. <span>
  12. <Avatar size="small" shape="square" src={record.nameIconSrc} style={{ marginRight: 12 }}></Avatar>
  13. {text}
  14. </span>
  15. );
  16. }
  17. },
  18. {
  19. title: '大小',
  20. dataIndex: 'size',
  21. },
  22. {
  23. title: '所有者',
  24. dataIndex: 'owner',
  25. render: (text, record, index) => {
  26. return (
  27. <div>
  28. <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>
  29. {typeof text === 'string' && text.slice(0, 1)}
  30. </Avatar>
  31. {text}
  32. </div>
  33. );
  34. }
  35. },
  36. {
  37. title: '更新日期',
  38. dataIndex: 'updateTime',
  39. },
  40. {
  41. title: '',
  42. dataIndex: 'operate',
  43. render: () => {
  44. return <IconMore />;
  45. }
  46. },
  47. ];
  48. const data = [
  49. {
  50. key: '1',
  51. name: 'Semi Design 设计稿.fig',
  52. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
  53. size: '2M',
  54. owner: '姜鹏志',
  55. updateTime: '2020-02-02 05:13',
  56. avatarBg: 'grey'
  57. },
  58. {
  59. key: '2',
  60. name: 'Semi Design 分享演示文稿',
  61. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  62. size: '2M',
  63. owner: '郝宣',
  64. updateTime: '2020-01-17 05:31',
  65. avatarBg: 'red'
  66. },
  67. {
  68. key: '3',
  69. name: '设计文档',
  70. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  71. size: '34KB',
  72. owner: 'Zoey Edwards',
  73. updateTime: '2020-01-26 11:01',
  74. avatarBg: 'light-blue'
  75. },
  76. ];
  77. const expandData = [
  78. { key: '实际用户数量', value: '1,480,000' },
  79. { key: '7天留存', value: '98%' },
  80. { key: '安全等级', value: '3级' },
  81. { key: '垂类标签', value: <Tag style={{ margin: 0 }}>电商</Tag> },
  82. { key: '认证状态', value: '未认证' },
  83. ];
  84. function App() {
  85. const expandRowRender = (record, index) => {
  86. return <Descriptions align="justify" data={expandData} />;
  87. };
  88. const rowSelection = {
  89. getCheckboxProps: record => ({
  90. disabled: record.name === '设计文档', // Column configuration not to be checked
  91. name: record.name,
  92. }),
  93. onSelect: (record, selected) => {
  94. console.log(`select row: ${selected}`, record);
  95. },
  96. onSelectAll: (selected, selectedRows) => {
  97. console.log(`select all rows: ${selected}`, selectedRows);
  98. },
  99. onChange: (selectedRowKeys, selectedRows) => {
  100. console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  101. },
  102. };
  103. return <Table rowKey="name" columns={columns} dataSource={data} expandedRowRender={expandRowRender} rowSelection={rowSelection} pagination={false} />;
  104. }
  105. render(App);