index.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import { Space, Table, Tag } from 'antd';
  3. import type { TableProps } from 'antd';
  4. interface DataType {
  5. key: string;
  6. name: string;
  7. age: number;
  8. address: string;
  9. tags: string[];
  10. }
  11. const columns: TableProps<DataType>['columns'] = [
  12. {
  13. title: 'Name',
  14. dataIndex: 'name',
  15. key: 'name',
  16. render: (text) => <a>{text}</a>,
  17. },
  18. {
  19. title: 'Age',
  20. dataIndex: 'age',
  21. key: 'age',
  22. },
  23. {
  24. title: 'Address',
  25. dataIndex: 'address',
  26. key: 'address',
  27. },
  28. {
  29. title: 'Tags',
  30. key: 'tags',
  31. dataIndex: 'tags',
  32. render: (_, { tags }) => (
  33. <>
  34. {tags.map((tag) => {
  35. let color = tag.length > 5 ? 'geekblue' : 'green';
  36. if (tag === 'loser') {
  37. color = 'volcano';
  38. }
  39. return (
  40. <Tag color={color} key={tag}>
  41. {tag.toUpperCase()}
  42. </Tag>
  43. );
  44. })}
  45. </>
  46. ),
  47. },
  48. {
  49. title: 'Action',
  50. key: 'action',
  51. render: (_, record) => (
  52. <Space size="middle">
  53. <a>Invite {record.name}</a>
  54. <a>Delete</a>
  55. </Space>
  56. ),
  57. },
  58. ];
  59. const data: DataType[] = [
  60. {
  61. key: '1',
  62. name: 'John Brown1111',
  63. age: 32,
  64. address: 'New York No. 1 Lake Park',
  65. tags: ['nice', 'developer'],
  66. },
  67. {
  68. key: '2',
  69. name: 'Jim Green 1111',
  70. age: 42,
  71. address: 'London No. 1 Lake Park',
  72. tags: ['loser'],
  73. },
  74. ];
  75. const DemoTable: React.FC = () => <Table columns={columns} dataSource={data} />;
  76. export default DemoTable;