mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 13:08:41 +08:00
01ca7c7821
* test: replace testing-lib * test: replace testing-lib * test: replace testing-lib * test: update snap * test: replace testing-lib * test: replace testing-lib * test: update for lint * merge: merge * test: testing-lib * test: replace testing-lib * test: testing-lib * test: testing-lib * test: replace testing-lib * test: replace testing-lib * test: Replace test aria replacment logic * test: Update snapshot * chore: hack for id * test: clean up * test: clean demo * chore: update * test: snapshot update * test: fix snapshot rep logic * test: fix snapshot rep logic * test: fix snapshot rep logic * chore: update demo * test: fix snapshot rep logic * test: Update snapshot * test: rest snapshot * test: update snapshot * test: Update test case * test: config env * chore: clean up * chore: Use renderServer instead * test: adjust testing logic * test: modify test logic * test: split ssr test * test: skip if need skip * chore: ignore test file covv Co-authored-by: 二货机器人 <smith3816@gmail.com>
2.2 KiB
2.2 KiB
order | title | ||||
---|---|---|---|---|---|
2 |
|
zh-CN
穿梭框高级用法,可配置操作文案,可定制宽高,可对底部进行自定义渲染。
en-US
Advanced Usage of Transfer.
You can customize the labels of the transfer buttons, the width and height of the columns, and what should be displayed in the footer.
import { Button, Transfer } from 'antd';
import type { TransferDirection, TransferListProps } from 'antd/es/transfer';
import React, { useEffect, useState } from 'react';
interface RecordType {
key: string;
title: string;
description: string;
chosen: boolean;
}
const App: React.FC = () => {
const [mockData, setMockData] = useState<RecordType[]>([]);
const [targetKeys, setTargetKeys] = useState<string[]>([]);
const getMock = () => {
const tempTargetKeys = [];
const tempMockData = [];
for (let i = 0; i < 20; i++) {
const data = {
key: i.toString(),
title: `content${i + 1}`,
description: `description of content${i + 1}`,
chosen: i % 2 === 0,
};
if (data.chosen) {
tempTargetKeys.push(data.key);
}
tempMockData.push(data);
}
setMockData(tempMockData);
setTargetKeys(tempTargetKeys);
};
useEffect(() => {
getMock();
}, []);
const handleChange = (newTargetKeys: string[]) => {
setTargetKeys(newTargetKeys);
};
const renderFooter = (
_: TransferListProps<any>,
{
direction,
}: {
direction: TransferDirection;
},
) => {
if (direction === 'left') {
return (
<Button size="small" style={{ float: 'left', margin: 5 }} onClick={getMock}>
Left button reload
</Button>
);
}
return (
<Button size="small" style={{ float: 'right', margin: 5 }} onClick={getMock}>
Right button reload
</Button>
);
};
return (
<Transfer
dataSource={mockData}
showSearch
listStyle={{
width: 250,
height: 300,
}}
operations={['to right', 'to left']}
targetKeys={targetKeys}
onChange={handleChange}
render={item => `${item.title}-${item.description}`}
footer={renderFooter}
/>
);
};
export default App;