|
|
|
import * as React from 'react';
|
|
|
|
import * as ReactDOM from 'react-dom';
|
|
|
|
import omit from 'omit.js';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import PureRenderMixin from 'rc-util/lib/PureRenderMixin';
|
|
|
|
import Checkbox from '../checkbox';
|
|
|
|
import { TransferItem, TransferDirection, RenderResult, RenderResultObject } from './index';
|
|
|
|
import Search from './search';
|
|
|
|
import defaultRenderList, { TransferListBodyProps, OmitProps } from './renderListBody';
|
|
|
|
import triggerEvent from '../_util/triggerEvent';
|
|
|
|
|
|
|
|
const defaultRender = () => null;
|
|
|
|
|
|
|
|
function isRenderResultPlainObject(result: RenderResult) {
|
|
|
|
return (
|
|
|
|
result &&
|
|
|
|
!React.isValidElement(result) &&
|
|
|
|
Object.prototype.toString.call(result) === '[object Object]'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RenderedItem {
|
|
|
|
renderedText: string;
|
|
|
|
renderedEl: React.ReactNode;
|
|
|
|
item: TransferItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
type RenderListFunction = (props: TransferListBodyProps) => React.ReactNode;
|
|
|
|
|
|
|
|
export interface TransferListProps {
|
|
|
|
prefixCls: string;
|
|
|
|
titleText: string;
|
|
|
|
dataSource: TransferItem[];
|
|
|
|
filterOption?: (filterText: string, item: TransferItem) => boolean;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
checkedKeys: string[];
|
|
|
|
handleFilter: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
|
|
handleSelect: (selectedItem: TransferItem, checked: boolean) => void;
|
|
|
|
/** [Legacy] Only used when `body` prop used. */
|
|
|
|
handleSelectAll: (dataSource: TransferItem[], checkAll: boolean) => void;
|
|
|
|
onItemSelect: (key: string, check: boolean) => void;
|
|
|
|
onItemSelectAll: (dataSource: string[], checkAll: boolean) => void;
|
|
|
|
handleClear: () => void;
|
|
|
|
render?: (item: TransferItem) => RenderResult;
|
|
|
|
showSearch?: boolean;
|
|
|
|
searchPlaceholder: string;
|
|
|
|
notFoundContent: React.ReactNode;
|
|
|
|
itemUnit: string;
|
|
|
|
itemsUnit: string;
|
|
|
|
body?: (props: TransferListProps) => React.ReactNode;
|
|
|
|
renderList?: RenderListFunction;
|
|
|
|
footer?: (props: TransferListProps) => React.ReactNode;
|
|
|
|
lazy?: boolean | {};
|
|
|
|
onScroll: Function;
|
|
|
|
disabled?: boolean;
|
|
|
|
direction: TransferDirection;
|
|
|
|
showSelectAll?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface TransferListState {
|
|
|
|
/** Filter input value */
|
|
|
|
filterValue: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderListNode(renderList: RenderListFunction | undefined, props: TransferListBodyProps) {
|
|
|
|
let bodyContent: React.ReactNode = renderList ? renderList(props) : null;
|
|
|
|
const customize: boolean = !!bodyContent;
|
|
|
|
if (!customize) {
|
|
|
|
bodyContent = defaultRenderList(props);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
customize,
|
|
|
|
bodyContent,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class TransferList extends React.Component<TransferListProps, TransferListState> {
|
|
|
|
static defaultProps = {
|
|
|
|
dataSource: [],
|
|
|
|
titleText: '',
|
|
|
|
showSearch: false,
|
|
|
|
lazy: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
timer: number;
|
|
|
|
triggerScrollTimer: number;
|
|
|
|
|
|
|
|
constructor(props: TransferListProps) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
filterValue: '',
|
|