import * as React from 'react'; import './Transfer.less'; import { Checkbox, Input } from 'antd'; import { createGetClassName } from '../../util/util'; import ReactDragListView from 'react-drag-listview'; const getClassName = createGetClassName('transfer'); const Search = Input.Search; export interface TransferDataSource { key: any; text: string; } export interface TransferListProps { title: string; dataSource: TransferDataSource[]; checkedKeys: any[]; onSelect: (selectedKey: any, checked: boolean) => void; onSelectAll: (checked: boolean) => void; style?: React.CSSProperties; drag?: boolean; onDragEnd?: (fromIndex: number, toIndex: number) => void; onSearch?: (value: string) => void; } export default class TransferList extends React.Component { handleCheckAllChange = e => { if (this.props.dataSource.length === 0) { return; } this.props.onSelectAll(e.target.checked); } handleChange = (e, key) => { this.props.onSelect(key, e.target.checked); } handleDragEnd = (fromIndex, toIndex) => { if (this.props.onDragEnd) { this.props.onDragEnd(fromIndex, toIndex); } } render() { const indeterminate = !!this.props.checkedKeys.length && this.props.checkedKeys.length < this.props.dataSource.length; const list = this.props.dataSource.map(item => { return (
{ this.handleChange(e, item.key); }} checked={this.props.checkedKeys.indexOf(item.key) >= 0} /> {item.text}
); }); return (
0 && this.props.checkedKeys.length === this.props.dataSource.length} /> {this.props.title}
{this.props.onSearch ? { this.props.onSearch(e.target.value); }} /> : null} {this.props.drag ? {list}
拖动调整顺序
: list}
); } }