index.tsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, { useState, useEffect, useMemo } from 'react';
  2. // eslint-disable-next-line semi-design/no-import
  3. import { Table, Avatar } from '@douyinfe/semi-ui';
  4. // eslint-disable-next-line semi-design/no-import
  5. import { ColumnProps } from '@douyinfe/semi-ui/table';
  6. const figmaIconUrl = 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png';
  7. App.storyName = 'fixed github 1188';
  8. /**
  9. * fix https://github.com/DouyinFE/semi-design/issues/1188
  10. */
  11. function App() {
  12. const [dataSource, setData] = useState([]);
  13. const [filteredValue, setFilteredValue] = useState(['Semi Pro 设计稿']);
  14. const columns: ColumnProps[] = [
  15. {
  16. title: '标题',
  17. dataIndex: 'name',
  18. width: 400,
  19. render: (text, record, index) => {
  20. return (
  21. <div>
  22. <Avatar size="small" shape="square" src={figmaIconUrl} style={{ marginRight: 12 }}></Avatar>
  23. {text}
  24. </div>
  25. );
  26. },
  27. filters: [
  28. {
  29. text: 'Semi Design 设计稿',
  30. value: 'Semi Design 设计稿',
  31. },
  32. {
  33. text: 'Semi Pro 设计稿',
  34. value: 'Semi Pro 设计稿',
  35. },
  36. ],
  37. onFilter: (value, record) => record.name.includes(value),
  38. defaultFilteredValue: filteredValue,
  39. },
  40. {
  41. title: '大小',
  42. dataIndex: 'size',
  43. sorter: (a, b) => a.size - b.size > 0 ? 1 : -1,
  44. defaultSortOrder: 'ascend',
  45. render: (text) => `${text} KB`
  46. },
  47. {
  48. title: '所有者',
  49. dataIndex: 'owner',
  50. render: (text, record, index) => {
  51. return (
  52. <div>
  53. <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>{typeof text === 'string' && text.slice(0, 1)}</Avatar>
  54. {text}
  55. </div>
  56. );
  57. }
  58. }
  59. ];
  60. const getData = (total) => {
  61. const data = [];
  62. for (let i = 0; i < total; i++) {
  63. const isSemiDesign = i % 2 === 0;
  64. const randomNumber = (i * 1000) % 199;
  65. data.push({
  66. key: '' + i,
  67. name: isSemiDesign ? `Semi Design 设计稿${i}.fig` : `Semi Pro 设计稿${i}.fig`,
  68. owner: isSemiDesign ? '姜鹏志' : '郝宣',
  69. size: randomNumber,
  70. avatarBg: isSemiDesign ? 'grey' : 'red'
  71. });
  72. }
  73. return data;
  74. };
  75. const handleChange = (options) => {
  76. console.log('onChange', options);
  77. };
  78. useEffect(() => {
  79. const data = getData(46);
  80. setData(data);
  81. }, []);
  82. return (
  83. <div>
  84. <Table columns={columns} dataSource={dataSource} onChange={handleChange} />
  85. </div>
  86. );
  87. }
  88. export default App;