import React, { useState } from 'react'; import { ClockCircleOutlined, DownOutlined } from '@ant-design/icons'; import { Anchor, Badge, Button, Calendar, Card, Collapse, DatePicker, Dropdown, Modal, Slider, Switch, Table, Tabs, Timeline, Transfer, Tree, Typography, } from 'antd'; import type { TableProps, TransferProps } from 'antd'; import type { TransferKey } from 'antd/es/transfer/interface'; import dayjs from 'dayjs'; import customParseFormat from 'dayjs/plugin/customParseFormat'; import difference from 'lodash/difference'; dayjs.extend(customParseFormat); const { Panel } = Collapse; const { TreeNode } = Tree; const { TabPane } = Tabs; const { Meta } = Card; const { Link } = Anchor; const { Text } = Typography; const text = ` A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world. `; interface DataType { key: string; title: string; description: string; disabled: boolean; } interface RecordType { key: string; name: string; age: number; address: string; } interface DataTableType { key: string; name: string; borrow: number; repayment: number; } interface ExpandDataType { key: React.Key; date: string; name: string; upgradeNum: string; } interface NestDataType { key: React.Key; name: string; platform: string; version: string; upgradeNum: number; creator: string; createdAt: string; } interface FixedDataType { key: string; name: string; age: number; address: string; } const mockData = Array.from({ length: 20 }).map((_, i) => ({ key: i.toString(), title: `content${i + 1}`, description: `description of content${i + 1}`, disabled: i % 3 < 1, })); const oriTargetKeys = mockData .filter((item) => Number(item.key) % 3 > 1) .map((item) => item.key); const dataSource: RecordType[] = [ { key: '1', name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park' }, { key: '2', name: 'Jim Green', age: 42, address: 'London No. 1 Lake Park' }, { key: '3', name: 'Joe Black', age: 32, address: 'Sydney No. 1 Lake Park' }, { key: '4', name: 'Jim Red', age: 32, address: 'London No. 2 Lake Park' }, ]; const columnsTable: TableProps['columns'] = [ { title: 'Name', dataIndex: 'name' }, { title: 'Borrow', dataIndex: 'borrow' }, { title: 'Repayment', dataIndex: 'repayment' }, ]; const summaryDataSource: DataTableType[] = [ { key: '1', name: 'John Brown', borrow: 10, repayment: 33 }, { key: '2', name: 'Jim Green', borrow: 100, repayment: 0 }, { key: '3', name: 'Joe Black', borrow: 10, repayment: 10 }, { key: '4', name: 'Jim Red', borrow: 75, repayment: 45 }, ]; const expandDataSource = Array.from({ length: 3 }).map((_, i) => ({ key: i, date: '2014-12-24 23:12:00', name: 'This is production name', upgradeNum: 'Upgraded: 56', })); const expandColumns: TableProps['columns'] = [ { title: 'Date', dataIndex: 'date', key: 'date' }, { title: 'Name', dataIndex: 'name', key: 'name' }, { title: 'Status', key: 'state', render: () => ( Finished ), }, { title: 'Upgrade Status', dataIndex: 'upgradeNum', key: 'upgradeNum' }, { title: 'Action', dataIndex: 'operation', key: 'operation', render: () => ( Pause Stop More ), }, ]; const expandedRowRender = () => ( columns={expandColumns} dataSource={expandDataSource} pagination={false} /> ); const columnsNest: TableProps['columns'] = [ { title: 'Name', dataIndex: 'name', key: 'name' }, { title: 'Platform', dataIndex: 'platform', key: 'platform' }, { title: 'Version', dataIndex: 'version', key: 'version' }, { title: 'Upgraded', dataIndex: 'upgradeNum', key: 'upgradeNum' }, { title: 'Creator', dataIndex: 'creator', key: 'creator' }, { title: 'Date', dataIndex: 'createdAt', key: 'createdAt' }, { title: 'Action', key: 'operation', render: () => Publish }, ]; const nestDataSource = Array.from({ length: 3 }).map((_, i) => ({ key: i, name: 'Screem', platform: 'iOS', version: '10.3.4.5654', upgradeNum: 500, creator: 'Jack', createdAt: '2014-12-24 23:12:00', })); const columnsFixed: TableProps['columns'] = [ { title: 'Full Name', width: 100, dataIndex: 'name', key: 'name', fixed: 'left' }, { title: 'Age', width: 100, dataIndex: 'age', key: 'age', fixed: 'left' }, { title: 'Column 1', dataIndex: 'address', key: '1' }, { title: 'Column 2', dataIndex: 'address', key: '2' }, { title: 'Column 3', dataIndex: 'address', key: '3' }, { title: 'Column 4', dataIndex: 'address', key: '4' }, { title: 'Column 5', dataIndex: 'address', key: '5' }, { title: 'Column 6', dataIndex: 'address', key: '6' }, { title: 'Column 7', dataIndex: 'address', key: '7' }, { title: 'Column 8', dataIndex: 'address', key: '8' }, { title: 'Action', key: 'operation', fixed: 'right', width: 100, render: () => action }, ]; const fixedDataSource: FixedDataType[] = [ { key: '1', name: 'John Brown', age: 32, address: 'New York Park' }, { key: '2', name: 'Jim Green', age: 40, address: 'London Park' }, ]; const TableTransfer: React.FC< Readonly['columns']>>> & TransferProps > = (props) => { const { leftColumns, rightColumns, ...restProps } = props; return ( {...restProps} showSelectAll={false}> {(transferProps) => { const { direction, filteredItems, onItemSelectAll, onItemSelect, selectedKeys: listSelectedKeys, disabled: listDisabled, } = transferProps; const columns = (direction === 'left' ? leftColumns : rightColumns) ?? []; const rowSelection: TableProps['rowSelection'] = { getCheckboxProps: (item) => ({ disabled: listDisabled || item.disabled }), onSelectAll(selected, selectedRows) { const treeSelectedKeys = selectedRows .filter((item) => !item.disabled) .map(({ key }) => key); const diffKeys = selected ? difference(treeSelectedKeys, listSelectedKeys) : difference(listSelectedKeys, treeSelectedKeys); onItemSelectAll(diffKeys, selected); }, onSelect({ key }, selected) { onItemSelect(key, selected); }, selectedRowKeys: listSelectedKeys, }; return ( id="components-transfer-table" rowSelection={rowSelection} columns={columns} dataSource={filteredItems} size="small" style={{ pointerEvents: listDisabled ? 'none' : 'auto' }} onRow={({ key, disabled: itemDisabled }) => ({ onClick: () => { if (itemDisabled || listDisabled) { return; } onItemSelect(key, !listSelectedKeys.includes(key)); }, })} /> ); }} ); }; const columns: TableProps['columns'] = [ { title: 'Name', dataIndex: 'name', key: 'name', filters: [ { text: 'Joe', value: 'Joe' }, { text: 'Jim', value: 'Jim' }, ], filteredValue: null, onFilter: (value, record) => record.name.includes(value as string), sorter: (a, b) => a.name.length - b.name.length, sortOrder: 'ascend', ellipsis: true, }, { title: 'Age', dataIndex: 'age', key: 'age', sorter: false, sortOrder: 'ascend', ellipsis: true, }, { title: 'Address', dataIndex: 'address', key: 'address', filters: [ { text: 'London', value: 'London' }, { text: 'New York', value: 'New York' }, ], filteredValue: null, onFilter: (value, record) => record.address.includes(value as string), sorter: false, sortOrder: 'ascend', ellipsis: true, }, ]; const tableTransferColumns: TableProps['columns'] = [ { dataIndex: 'title', title: 'Name' }, { dataIndex: 'description', title: 'Description' }, ]; const Demo: React.FC = () => { const [open, setOpen] = useState(false); const [targetKeys, setTargetKeys] = useState(oriTargetKeys); const [selectedKeys, setSelectedKeys] = useState([]); const [disabled, setDisabled] = useState(false); const [showSearch, setShowSearch] = useState(false); const handleDisable = (isDisabled: boolean) => { setDisabled(isDisabled); }; const handleTableTransferChange = (nextTargetKeys: TransferKey[]) => { setTargetKeys(nextTargetKeys); }; const triggerDisable = (isDisabled: boolean) => { setDisabled(isDisabled); }; const triggerShowSearch = (isShowSearch: boolean) => { setShowSearch(isShowSearch); }; const handleTransferChange = (keys: TransferKey[]) => { setTargetKeys(keys); }; const handleTransferSelectChange = ( sourceSelectedKeys: TransferKey[], targetSelectedKeys: TransferKey[], ) => { setSelectedKeys([...sourceSelectedKeys, ...targetSelectedKeys]); }; const showModal = () => { setOpen(true); }; const handleOk = (e: React.MouseEvent) => { console.log(e); setOpen(false); }; const handleCancel = (e: React.MouseEvent) => { console.log(e); setOpen(false); }; return ( <> Content Content Content Content Content Content Content

{text}

{text}

{text}

dataSource={mockData} titles={['Source', 'Target']} targetKeys={targetKeys} selectedKeys={selectedKeys} onChange={handleTransferChange} onSelectChange={handleTransferSelectChange} render={(item) => item.title} disabled={disabled} /> item.title?.includes(inputValue) || item.tag?.includes(inputValue) } /> Content of Tab Pane 1 Content of Tab Pane 2 Content of Tab Pane 3 Create a services site 2015-09-01 Solve initial network problems 2015-09-01 } color="red"> Technical testing 2015-09-01 Network problems being solved 2015-09-01 } defaultExpandedKeys={['0-0-0']}> columns={columns} dataSource={dataSource} footer={() => 'Footer'} /> columns={columnsTable} dataSource={summaryDataSource} pagination={false} id="table-demo-summary" bordered summary={(pageData) => { let totalBorrow = 0; let totalRepayment = 0; pageData.forEach(({ borrow, repayment }) => { totalBorrow += borrow; totalRepayment += repayment; }); return ( <> Total {totalBorrow} {totalRepayment} Balance {totalBorrow - totalRepayment} ); }} />
columns={columnsNest} expandable={{ expandedRowRender }} dataSource={nestDataSource} /> columns={columnsFixed} dataSource={fixedDataSource} scroll={{ x: 1300, y: 100 }} /> } >
); }; export default Demo;