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 Lazyload from 'react-lazy-load';
|
|
|
|
import Checkbox from '../checkbox';
|
|
|
|
|
|
|
|
export default class Item 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);
|
|
|
|
}
|
|
|
|
render() {
|
2017-01-27 17:08:12 +08:00
|
|
|
const { renderedText, renderedEl, item, lazy, checked, prefixCls, onClick } = this.props;
|
2016-11-04 16:52:57 +08:00
|
|
|
|
|
|
|
const className = classNames({
|
|
|
|
[`${prefixCls}-content-item`]: true,
|
|
|
|
[`${prefixCls}-content-item-disabled`]: item.disabled,
|
|
|
|
});
|
|
|
|
|
2016-12-16 17:59:52 +08:00
|
|
|
const listItem = (
|
|
|
|
<li
|
|
|
|
className={className}
|
|
|
|
title={renderedText}
|
|
|
|
onClick={item.disabled ? undefined : () => onClick(item)}
|
|
|
|
>
|
|
|
|
<Checkbox checked={checked} disabled={item.disabled} />
|
|
|
|
<span>{renderedEl}</span>
|
|
|
|
</li>
|
2016-11-04 16:52:57 +08:00
|
|
|
);
|
2016-12-16 17:59:52 +08:00
|
|
|
let children: JSX.Element | null = null;
|
|
|
|
if (lazy) {
|
2017-07-03 16:57:11 +08:00
|
|
|
const lazyProps = {
|
2016-12-16 17:59:52 +08:00
|
|
|
height: 32,
|
|
|
|
offset: 500,
|
|
|
|
throttle: 0,
|
|
|
|
debounce: false,
|
2017-07-03 16:57:11 +08:00
|
|
|
...lazy,
|
|
|
|
};
|
2016-12-16 17:59:52 +08:00
|
|
|
children = <Lazyload {...lazyProps}>{listItem}</Lazyload>;
|
|
|
|
} else {
|
|
|
|
children = listItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
return children;
|
2016-11-04 16:52:57 +08:00
|
|
|
}
|
|
|
|
}
|