2019-05-07 17:10:42 +08:00
|
|
|
import * as React from 'react';
|
2020-04-04 12:32:56 +08:00
|
|
|
import { ElementOf, Omit, tuple } from '../_util/type';
|
2019-05-07 17:10:42 +08:00
|
|
|
import { TransferItem } from '.';
|
|
|
|
import { TransferListProps, RenderedItem } from './list';
|
|
|
|
import ListItem from './ListItem';
|
|
|
|
|
2019-07-09 11:46:21 +08:00
|
|
|
export const OmitProps = tuple('handleFilter', 'handleClear', 'checkedKeys');
|
2020-04-04 12:32:56 +08:00
|
|
|
export type OmitProp = ElementOf<typeof OmitProps>;
|
2019-05-07 17:10:42 +08:00
|
|
|
type PartialTransferListProps = Omit<TransferListProps, OmitProp>;
|
|
|
|
|
|
|
|
export interface TransferListBodyProps extends PartialTransferListProps {
|
|
|
|
filteredItems: TransferItem[];
|
|
|
|
filteredRenderItems: RenderedItem[];
|
|
|
|
selectedKeys: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
class ListBody extends React.Component<TransferListBodyProps> {
|
|
|
|
onItemSelect = (item: TransferItem) => {
|
|
|
|
const { onItemSelect, selectedKeys } = this.props;
|
|
|
|
const checked = selectedKeys.indexOf(item.key) >= 0;
|
|
|
|
onItemSelect(item.key, !checked);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2019-09-17 13:31:32 +08:00
|
|
|
const {
|
|
|
|
prefixCls,
|
|
|
|
onScroll,
|
|
|
|
filteredRenderItems,
|
|
|
|
selectedKeys,
|
|
|
|
disabled: globalDisabled,
|
|
|
|
} = this.props;
|
2019-05-07 17:10:42 +08:00
|
|
|
|
|
|
|
return (
|
2019-12-23 18:33:08 +08:00
|
|
|
<ul className={`${prefixCls}-content`} onScroll={onScroll}>
|
2019-05-07 17:10:42 +08:00
|
|
|
{filteredRenderItems.map(({ renderedEl, renderedText, item }: RenderedItem) => {
|
|
|
|
const { disabled } = item;
|
|
|
|
const checked = selectedKeys.indexOf(item.key) >= 0;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ListItem
|
2019-09-17 13:31:32 +08:00
|
|
|
disabled={globalDisabled || disabled}
|
2019-05-07 17:10:42 +08:00
|
|
|
key={item.key}
|
|
|
|
item={item}
|
|
|
|
renderedText={renderedText}
|
|
|
|
renderedEl={renderedEl}
|
|
|
|
checked={checked}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
onClick={this.onItemSelect}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
2019-12-23 18:33:08 +08:00
|
|
|
</ul>
|
2019-05-07 17:10:42 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:38:10 +08:00
|
|
|
const ListBodyWrapper = (props: TransferListBodyProps) => <ListBody {...props} />;
|
|
|
|
|
|
|
|
export default ListBodyWrapper;
|