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.

355 lines
9.9 KiB

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import omit from 'omit.js';
9 years ago
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';
9 years ago
const defaultRender = () => null;
9 years ago
function isRenderResultPlainObject(result: RenderResult) {
6 years ago
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;
9 years ago
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) {
9 years ago
super(props);
this.state = {
filterValue: '',