You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

349 lines
11 KiB

import React from 'react';
8 years ago
import { PropTypes } from 'react';
import classNames from 'classnames';
import List from './list';
import { TransferListProps } from './list';
import Operation from './operation';
import Search from './search';
9 years ago
function noop() {
}
export interface TransferItem {
key: string;
title: string;
description?: string;
disabled?: boolean;
}
9 years ago
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]),
};
9 years ago
static contextTypes = {
antLocale: PropTypes.object,
};
context: TransferContext;
splitedDataSource: any;
constructor(props: TransferProps) {
9 years ago
super(props);
const { selectedKeys = [], targetKeys = [] } = props;
9 years ago
this.state = {
leftFilter: '',
rightFilter: '',
sourceSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) === -1),
targetSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) > -1),
9 years ago
};
}
8 years ago
componentWillReceiveProps(nextProps: TransferProps) {