ant-design/components/transfer/ListItem.tsx

61 lines
1.5 KiB
TypeScript
Raw Normal View History

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 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() {
2018-09-15 15:18:59 +08:00
const {
2018-12-07 20:02:01 +08:00
renderedText,
renderedEl,
item,
lazy,
checked,
disabled,
prefixCls,
onClick,
2018-09-15 15:18:59 +08:00
} = 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,
2016-11-04 16:52:57 +08:00
});
2019-08-05 18:38:10 +08:00
let title: string | undefined;
if (typeof renderedText === 'string' || typeof renderedText === 'number') {
title = String(renderedText);
}
const listItem = (
<li
className={className}
title={title}
2018-12-07 20:02:01 +08:00
onClick={disabled || item.disabled ? undefined : () => onClick(item)}
>
2018-09-15 15:18:59 +08:00
<Checkbox checked={checked} disabled={disabled || item.disabled} />
<span className={`${prefixCls}-content-item-text`}>{renderedEl}</span>
</li>
2016-11-04 16:52:57 +08:00
);
let children: JSX.Element | null = null;
if (lazy) {
const lazyProps = {
height: 32,
offset: 500,
throttle: 0,
debounce: false,
...lazy,
};
children = <Lazyload {...lazyProps}>{listItem}</Lazyload>;
} else {
children = listItem;
}
return children;
2016-11-04 16:52:57 +08:00
}
}