|
|
|
import React from 'react';
|
|
|
|
import { PropTypes } from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import List from './list';
|
|
|
|
import { TransferListProps } from './list';
|
|
|
|
import Operation from './operation';
|
|
|
|
import Search from './search';
|
|
|
|
|
|
|
|
function noop() {
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TransferItem {
|
|
|
|
key: string;
|
|
|
|
title: string;
|
|
|
|
description?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TransferProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
|
|
|
dataSource: TransferItem[];
|
|
|
|
targetKeys: string[];
|
|
|
|
selectedKeys?: string[];
|
|
|
|
render?: (record: TransferItem) => React.ReactNode;
|
|
|
|
onChange?: (targetKeys: string[], direction: string, moveKeys: any) => void;
|
|
|
|
onSelectChange?: (sourceSelectedKeys: string[], targetSelectedKeys: string[]) => void;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
listStyle?: React.CSSProperties;
|
|
|
|
titles?: string[];
|
|
|
|
operations?: string[];
|
|
|
|
showSearch?: boolean;
|
|
|
|
filterOption: (inputValue: any, item: any) => boolean;
|
|
|
|
searchPlaceholder?: string;
|
|
|
|
notFoundContent?: React.ReactNode;
|
|
|
|
footer?: (props: TransferListProps) => React.ReactNode;
|
|
|
|
body?: (props: TransferListProps) => React.ReactNode;
|
|
|
|
rowKey?: (record: TransferItem) => string;
|
|
|
|
onSearchChange?: (direction: 'left' | 'right', e: Event) => void;
|
|
|
|
lazy?: {};
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TransferContext {
|
|
|
|
antLocale?: {
|
|
|
|
Transfer?: any,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultTitles = ['', ''];
|
|
|
|
export default class Transfer extends React.Component<TransferProps, any> {
|
|
|
|
// For high-level customized Transfer @dqaria
|
|
|
|
static List = List;
|
|
|
|
static Operation = Operation;
|
|
|
|
static Search = Search;
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
dataSource: [],
|
|
|
|
render: noop,
|
|
|
|
showSearch: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
dataSource: PropTypes.array,
|
|
|
|
render: PropTypes.func,
|
|
|
|
targetKeys: PropTypes.array,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
height: PropTypes.number,
|
|
|
|
listStyle: PropTypes.object,
|
|
|
|
className: PropTypes.string,
|
|
|
|
titles: PropTypes.array,
|
|
|
|
operations: PropTypes.array,
|
|
|
|
showSearch: PropTypes.bool,
|
|
|
|
filterOption: PropTypes.func,
|
|
|
|
searchPlaceholder: PropTypes.string,
|
|
|
|
notFoundContent: PropTypes.node,
|
|
|
|
body: PropTypes.func,
|
|
|
|
footer: PropTypes.func,
|
|
|
|
rowKey: PropTypes.func,
|
|
|
|
lazy: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
|
|
|
|
};
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
antLocale: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
context: TransferContext;
|
|
|
|
splitedDataSource: any;
|
|
|
|
|
|
|
|
constructor(props: TransferProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
const { selectedKeys = [], targetKeys = [] } = props;
|
|
|
|
this.state = {
|
|
|
|
leftFilter: '',
|
|
|
|
rightFilter: '',
|
|
|
|
sourceSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) === -1),
|
|
|
|
targetSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) > -1),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps: TransferProps) {
|
|
|
|
|