ant-design/components/table/demo/jsx.tsx
lijianan 89c1a053ef
Some checks failed
Publish Any Commit / build (push) Has been cancelled
✅ test v6 / lint (push) Has been cancelled
✅ test v6 / test-react-legacy (18, 1/2) (push) Has been cancelled
✅ test v6 / test-react-legacy (18, 2/2) (push) Has been cancelled
✅ test v6 / test-node (push) Has been cancelled
✅ test v6 / test-react-latest (dom, 1/2) (push) Has been cancelled
✅ test v6 / test-react-latest (dom, 2/2) (push) Has been cancelled
✅ test v6 / build (push) Has been cancelled
✅ test v6 / test lib/es module (es, 1/2) (push) Has been cancelled
✅ test v6 / test lib/es module (es, 2/2) (push) Has been cancelled
✅ test v6 / test lib/es module (lib, 1/2) (push) Has been cancelled
✅ test v6 / test lib/es module (lib, 2/2) (push) Has been cancelled
👁️ Visual Regression Persist Start / test image (push) Has been cancelled
✅ test v6 / test-react-latest-dist (dist, 1/2) (push) Has been cancelled
✅ test v6 / test-react-latest-dist (dist, 2/2) (push) Has been cancelled
✅ test v6 / test-react-latest-dist (dist-min, 1/2) (push) Has been cancelled
✅ test v6 / test-react-latest-dist (dist-min, 2/2) (push) Has been cancelled
✅ test v6 / test-coverage (push) Has been cancelled
refactor: [v6] rm Tag margin style (#52123)
* refactor: rm Tag margin style

* chore: rerun CICD

* demo: update demo
2024-12-25 19:55:51 +08:00

84 lines
1.8 KiB
TypeScript

import React from 'react';
import { Flex, Space, Table, Tag } from 'antd';
const { Column, ColumnGroup } = Table;
interface DataType {
key: React.Key;
firstName: string;
lastName: string;
age: number;
address: string;
tags: string[];
}
const data: DataType[] = [
{
key: '1',
firstName: 'John',
lastName: 'Brown',
age: 32,
address: 'New York No. 1 Lake Park',
tags: ['nice', 'developer'],
},
{
key: '2',
firstName: 'Jim',
lastName: 'Green',
age: 42,
address: 'London No. 1 Lake Park',
tags: ['loser'],
},
{
key: '3',
firstName: 'Joe',
lastName: 'Black',
age: 32,
address: 'Sydney No. 1 Lake Park',
tags: ['cool', 'teacher'],
},
];
const App: React.FC = () => (
<Table<DataType> dataSource={data}>
<ColumnGroup title="Name">
<Column title="First Name" dataIndex="firstName" key="firstName" />
<Column title="Last Name" dataIndex="lastName" key="lastName" />
</ColumnGroup>
<Column title="Age" dataIndex="age" key="age" />
<Column title="Address" dataIndex="address" key="address" />
<Column
title="Tags"
dataIndex="tags"
key="tags"
render={(tags: string[]) => (
<Flex gap="small" align="center" wrap>
{tags.map((tag) => {
let color = tag.length > 5 ? 'geekblue' : 'green';
if (tag === 'loser') {
color = 'volcano';
}
return (
<Tag color={color} key={tag}>
{tag.toUpperCase()}
</Tag>
);
})}
</Flex>
)}
/>
<Column
title="Action"
key="action"
render={(_: any, record: DataType) => (
<Space size="middle">
<a>Invite {record.lastName}</a>
<a>Delete</a>
</Space>
)}
/>
</Table>
);
export default App;