2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2016-11-04 16:52:57 +08:00
|
|
|
import classNames from 'classnames';
|
2020-03-05 13:19:00 +08:00
|
|
|
import { TransferItem } from '.';
|
2016-11-04 16:52:57 +08:00
|
|
|
import Checkbox from '../checkbox';
|
|
|
|
|
2020-03-05 13:19:00 +08:00
|
|
|
type ListItemProps = {
|
|
|
|
renderedText?: string | number;
|
|
|
|
renderedEl: React.ReactNode;
|
|
|
|
disabled?: boolean;
|
|
|
|
checked?: boolean;
|
|
|
|
prefixCls: string;
|
|
|
|
onClick: (item: TransferItem) => void;
|
|
|
|
item: TransferItem;
|
|
|
|
};
|
|
|
|
|
|
|
|
const ListItem = (props: ListItemProps) => {
|
|
|
|
const { renderedText, renderedEl, item, checked, disabled, prefixCls, onClick } = props;
|
2019-08-05 18:38:10 +08:00
|
|
|
|
2020-03-05 13:19:00 +08:00
|
|
|
const className = classNames({
|
|
|
|
[`${prefixCls}-content-item`]: true,
|
|
|
|
[`${prefixCls}-content-item-disabled`]: disabled || item.disabled,
|
|
|
|
[`${prefixCls}-content-item-checked`]: checked,
|
|
|
|
});
|
2016-11-04 16:52:57 +08:00
|
|
|
|
2020-03-05 13:19:00 +08:00
|
|
|
let title: string | undefined;
|
|
|
|
if (typeof renderedText === 'string' || typeof renderedText === 'number') {
|
|
|
|
title = String(renderedText);
|
|
|
|
}
|
2016-11-04 16:52:57 +08:00
|
|
|
|
2020-03-05 13:19:00 +08:00
|
|
|
const listItem = (
|
|
|
|
<li
|
|
|
|
className={className}
|
|
|
|
title={title}
|
|
|
|
onClick={disabled || item.disabled ? undefined : () => onClick(item)}
|
|
|
|
>
|
|
|
|
<Checkbox checked={checked} disabled={disabled || item.disabled} />
|
|
|
|
<span className={`${prefixCls}-content-item-text`}>{renderedEl}</span>
|
|
|
|
</li>
|
|
|
|
);
|
2018-09-25 19:32:08 +08:00
|
|
|
|
2020-03-05 13:19:00 +08:00
|
|
|
return listItem;
|
|
|
|
};
|
2016-12-16 17:59:52 +08:00
|
|
|
|
2020-03-05 13:19:00 +08:00
|
|
|
export default React.memo(ListItem);
|