import React, { useState } from 'react'; import { Flex, Switch, Table, Tag, Transfer } from 'antd'; import type { GetProp, TableColumnsType, TableProps, TransferProps } from 'antd'; type TransferItem = GetProp[number]; type TableRowSelection = TableProps['rowSelection']; interface DataType { key: string; title: string; description: string; tag: string; } interface TableTransferProps extends TransferProps { dataSource: DataType[]; leftColumns: TableColumnsType; rightColumns: TableColumnsType; } // Customize Table Transfer const TableTransfer: React.FC = (props) => { const { leftColumns, rightColumns, ...restProps } = props; return ( {({ direction, filteredItems, onItemSelect, onItemSelectAll, selectedKeys: listSelectedKeys, disabled: listDisabled, }) => { const columns = direction === 'left' ? leftColumns : rightColumns; const rowSelection: TableRowSelection = { getCheckboxProps: () => ({ disabled: listDisabled }), onChange(selectedRowKeys) { onItemSelectAll(selectedRowKeys, 'replace'); }, selectedRowKeys: listSelectedKeys, selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT, Table.SELECTION_NONE], }; return ( ({ onClick: () => { if (itemDisabled || listDisabled) { return; } onItemSelect(key, !listSelectedKeys.includes(key)); }, })} /> ); }} ); }; const mockTags = ['cat', 'dog', 'bird']; const mockData = Array.from({ length: 20 }).map((_, i) => ({ key: i.toString(), title: `content${i + 1}`, description: `description of content${i + 1}`, tag: mockTags[i % 3], })); const columns: TableColumnsType = [ { dataIndex: 'title', title: 'Name', }, { dataIndex: 'tag', title: 'Tag', render: (tag: string) => ( {tag.toUpperCase()} ), }, { dataIndex: 'description', title: 'Description', }, ]; const filterOption = (input: string, item: DataType) => item.title?.includes(input) || item.tag?.includes(input); const App: React.FC = () => { const [targetKeys, setTargetKeys] = useState([]); const [disabled, setDisabled] = useState(false); const onChange: TableTransferProps['onChange'] = (nextTargetKeys) => { setTargetKeys(nextTargetKeys); }; const toggleDisabled = (checked: boolean) => { setDisabled(checked); }; return ( ); }; export default App;