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';
|
|
|
|
import PureRenderMixin from 'rc-util/lib/PureRenderMixin';
|
|
|
|
import Checkbox from '../checkbox';
|
|
|
|
|
2019-05-07 17:10:42 +08:00
|
|
|
export default class ListItem extends React.Component<any, any> {
|
2017-11-20 17:41:32 +08:00
|
|
|
shouldComponentUpdate(...args: any[]) {
|
2016-11-04 16:52:57 +08:00
|
|
|
return PureRenderMixin.shouldComponentUpdate.apply(this, args);
|
|
|
|
}
|
2019-08-05 18:38:10 +08:00
|
|
|
|
2016-11-04 16:52:57 +08:00
|
|
|
render() {
|
2019-12-23 18:33:08 +08:00
|
|
|
const { renderedText, renderedEl, item, checked, disabled, prefixCls, onClick } = this.props;
|
2016-11-04 16:52:57 +08:00
|
|
|
|
|
|
|
const className = classNames({
|
|
|
|
[`${prefixCls}-content-item`]: true,
|
2018-09-15 15:18:59 +08:00
|
|
|
[`${prefixCls}-content-item-disabled`]: disabled || item.disabled,
|
2019-11-19 11:45:32 +08:00
|
|
|
[`${prefixCls}-content-item-checked`]: checked,
|
2016-11-04 16:52:57 +08:00
|
|
|
});
|
|
|
|
|
2019-08-05 18:38:10 +08:00
|
|
|
let title: string | undefined;
|
2018-09-25 19:32:08 +08:00
|
|
|
if (typeof renderedText === 'string' || typeof renderedText === 'number') {
|
|
|
|
title = String(renderedText);
|
|
|
|
}
|
|
|
|
|
2016-12-16 17:59:52 +08:00
|
|
|
const listItem = (
|
|
|
|
<li
|
|
|
|
className={className}
|
2018-09-25 19:32:08 +08:00
|
|
|
title={title}
|
2018-12-07 20:02:01 +08:00
|
|
|
onClick={disabled || item.disabled ? undefined : () => onClick(item)}
|
2016-12-16 17:59:52 +08:00
|
|
|
>
|
2018-09-15 15:18:59 +08:00
|
|
|
<Checkbox checked={checked} disabled={disabled || item.disabled} />
|
2019-07-20 22:20:02 +08:00
|
|
|
<span className={`${prefixCls}-content-item-text`}>{renderedEl}</span>
|
2016-12-16 17:59:52 +08:00
|
|
|
</li>
|
2016-11-04 16:52:57 +08:00
|
|
|
);
|
2016-12-16 17:59:52 +08:00
|
|
|
|
2019-12-23 18:33:08 +08:00
|
|
|
return listItem;
|
2016-11-04 16:52:57 +08:00
|
|
|
}
|
|
|
|
}
|