radioRowSelection.tsx 3.4 KB

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