mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 17:31:25 +08:00
f67d09b28e
* Extract type of the element of a tuple without indexing. * Amend ElementOf<T> to also support readonly arrays.
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import * as React from 'react';
|
|
import { ElementOf, Omit, tuple } from '../_util/type';
|
|
import { TransferItem } from '.';
|
|
import { TransferListProps, RenderedItem } from './list';
|
|
import ListItem from './ListItem';
|
|
|
|
export const OmitProps = tuple('handleFilter', 'handleClear', 'checkedKeys');
|
|
export type OmitProp = ElementOf<typeof OmitProps>;
|
|
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() {
|
|
const {
|
|
prefixCls,
|
|
onScroll,
|
|
filteredRenderItems,
|
|
selectedKeys,
|
|
disabled: globalDisabled,
|
|
} = this.props;
|
|
|
|
return (
|
|
<ul className={`${prefixCls}-content`} onScroll={onScroll}>
|
|
{filteredRenderItems.map(({ renderedEl, renderedText, item }: RenderedItem) => {
|
|
const { disabled } = item;
|
|
const checked = selectedKeys.indexOf(item.key) >= 0;
|
|
|
|
return (
|
|
<ListItem
|
|
disabled={globalDisabled || disabled}
|
|
key={item.key}
|
|
item={item}
|
|
renderedText={renderedText}
|
|
renderedEl={renderedEl}
|
|
checked={checked}
|
|
prefixCls={prefixCls}
|
|
onClick={this.onItemSelect}
|
|
/>
|
|
);
|
|
})}
|
|
</ul>
|
|
);
|
|
}
|
|
}
|
|
|
|
const ListBodyWrapper = (props: TransferListBodyProps) => <ListBody {...props} />;
|
|
|
|
export default ListBodyWrapper;
|