ant-design/components/transfer/ListItem.tsx

45 lines
1.2 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
2016-11-04 16:52:57 +08:00
import classNames from 'classnames';
import { TransferItem } from '.';
2016-11-04 16:52:57 +08:00
import Checkbox from '../checkbox';
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
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
let title: string | undefined;
if (typeof renderedText === 'string' || typeof renderedText === 'number') {
title = String(renderedText);
}
2016-11-04 16:52:57 +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>
);
return listItem;
};
export default React.memo(ListItem);