index.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React, { useState } from 'react';
  2. import { Table, Avatar, Button, Space } from '@douyinfe/semi-ui';
  3. import { IconMore } from '@douyinfe/semi-icons';
  4. const columns = [
  5. {
  6. title: '标题',
  7. dataIndex: 'name',
  8. width: 300,
  9. key: 'name',
  10. render: (text, record, index) => {
  11. return (
  12. <div>
  13. <Avatar size="small" shape="square" src={record.nameIconSrc} style={{ marginRight: 12 }}></Avatar>
  14. {text}
  15. </div>
  16. );
  17. },
  18. },
  19. {
  20. title: '大小',
  21. dataIndex: 'size',
  22. key: 'size',
  23. width: 200,
  24. },
  25. {
  26. title: '所有者',
  27. dataIndex: 'owner',
  28. key: 'owner',
  29. width: 200,
  30. render: (text, record, index) => {
  31. return (
  32. <div>
  33. <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>
  34. {typeof text === 'string' && text.slice(0, 1)}
  35. </Avatar>
  36. {text}
  37. </div>
  38. );
  39. },
  40. },
  41. {
  42. title: '更新日期',
  43. dataIndex: 'updateTime',
  44. key: 'updateTime',
  45. width: 200,
  46. },
  47. {
  48. title: '',
  49. dataIndex: 'operate',
  50. key: 'operate',
  51. render: () => {
  52. return <IconMore />;
  53. },
  54. },
  55. ];
  56. /**
  57. * fix https://github.com/DouyinFE/semi-design/issues/650
  58. */
  59. App.storyName = 'fixed resizable column width bug';
  60. App.parameters = { chromatic: { disableSnapshot: true } };
  61. function App() {
  62. const [cols, setCols] = useState(columns);
  63. const onClickHandle = () => {
  64. const localCols = [...cols].filter((i, index) => index !== 1);
  65. setCols(localCols);
  66. };
  67. const data = [
  68. {
  69. key: '1',
  70. name: 'Semi Design 设计稿.fig',
  71. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
  72. size: '2M',
  73. owner: '姜鹏志',
  74. updateTime: '2020-02-02 05:13',
  75. avatarBg: 'grey',
  76. },
  77. {
  78. key: '2',
  79. name: 'Semi Design 分享演示文稿',
  80. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  81. size: '2M',
  82. owner: '郝宣',
  83. updateTime: '2020-01-17 05:31',
  84. avatarBg: 'red',
  85. },
  86. {
  87. key: '3',
  88. name: '设计文档',
  89. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  90. size: '34KB',
  91. owner: 'Zoey Edwards',
  92. updateTime: '2020-01-26 11:01',
  93. avatarBg: 'light-blue',
  94. },
  95. ];
  96. return (
  97. <>
  98. <Space>
  99. <Button onClick={onClickHandle}>减少一列</Button>
  100. <Button theme="solid" onClick={() => setCols(columns)}>
  101. reset
  102. </Button>
  103. </Space>
  104. <Table columns={cols} dataSource={data} pagination={false} resizable />
  105. </>
  106. );
  107. }
  108. export default App;