mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
c8635a7bc0
* feat: add Transfer's key type * docs: update prop * fix: key type * fix: cycle dependency
38 lines
961 B
TypeScript
38 lines
961 B
TypeScript
import React, { useState } from 'react';
|
|
import { Transfer } from 'antd';
|
|
import type { TransferProps } from 'antd';
|
|
|
|
interface RecordType {
|
|
key: string;
|
|
title: string;
|
|
description: string;
|
|
}
|
|
|
|
const mockData: RecordType[] = Array.from({ length: 10 }).map((_, i) => ({
|
|
key: i.toString(),
|
|
title: `content${i + 1}`,
|
|
description: `description of content${i + 1}`,
|
|
}));
|
|
|
|
const oriTargetKeys = mockData.filter((item) => Number(item.key) % 3 > 1).map((item) => item.key);
|
|
|
|
const selectAllLabels: TransferProps['selectAllLabels'] = [
|
|
'Select All',
|
|
({ selectedCount, totalCount }) => `${selectedCount}/${totalCount}`,
|
|
];
|
|
|
|
const App: React.FC = () => {
|
|
const [targetKeys, setTargetKeys] = useState<React.Key[]>(oriTargetKeys);
|
|
return (
|
|
<Transfer
|
|
dataSource={mockData}
|
|
targetKeys={targetKeys}
|
|
onChange={setTargetKeys}
|
|
render={(item) => item.title}
|
|
selectAllLabels={selectAllLabels}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|