mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 17:19:11 +08:00
14a1e6bd51
* feat: tsconfig enable strict * feat: add no-explicit-any * feat: strict * feat: as THEME * feat: 优化 keys 类型写法 * feat: demo remove any * feat: as number * feat: this any * feat: add eslint * feat: cascader * feat: props any * feat: remove any * feat: remove any * feat: any 提示错误 * feat: remove any * feat: add eslint * feat: 允许 T = any 存在 * feat: color funciton * feat: 恢复 lint * feat: merge master * feat: as ReactElement * feat: type
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { Switch, Transfer } from 'antd';
|
|
import type { TransferProps } from 'antd';
|
|
|
|
interface RecordType {
|
|
key: string;
|
|
title: string;
|
|
description: string;
|
|
disabled: boolean;
|
|
}
|
|
|
|
const mockData: RecordType[] = 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 App: React.FC = () => {
|
|
const [targetKeys, setTargetKeys] = useState<React.Key[]>(oriTargetKeys);
|
|
const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
|
|
const [disabled, setDisabled] = useState(false);
|
|
|
|
const handleChange: TransferProps['onChange'] = (newTargetKeys, direction, moveKeys) => {
|
|
setTargetKeys(newTargetKeys);
|
|
|
|
console.log('targetKeys: ', newTargetKeys);
|
|
console.log('direction: ', direction);
|
|
console.log('moveKeys: ', moveKeys);
|
|
};
|
|
|
|
const handleSelectChange: TransferProps['onSelectChange'] = (
|
|
sourceSelectedKeys,
|
|
targetSelectedKeys,
|
|
) => {
|
|
setSelectedKeys([...sourceSelectedKeys, ...targetSelectedKeys]);
|
|
|
|
console.log('sourceSelectedKeys: ', sourceSelectedKeys);
|
|
console.log('targetSelectedKeys: ', targetSelectedKeys);
|
|
};
|
|
|
|
const handleScroll: TransferProps['onScroll'] = (direction, e) => {
|
|
console.log('direction:', direction);
|
|
console.log('target:', e.target);
|
|
};
|
|
|
|
const handleDisable = (checked: boolean) => {
|
|
setDisabled(checked);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Transfer
|
|
dataSource={mockData}
|
|
titles={['Source', 'Target']}
|
|
targetKeys={targetKeys}
|
|
selectedKeys={selectedKeys}
|
|
onChange={handleChange}
|
|
onSelectChange={handleSelectChange}
|
|
onScroll={handleScroll}
|
|
render={(item) => item.title}
|
|
disabled={disabled}
|
|
oneWay
|
|
style={{ marginBottom: 16 }}
|
|
/>
|
|
<Switch
|
|
unCheckedChildren="disabled"
|
|
checkedChildren="disabled"
|
|
checked={disabled}
|
|
onChange={handleDisable}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|