2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-08-31 16:53:19 +08:00
|
|
|
import classNames from '../_util/classNames';
|
2019-01-12 11:33:27 +08:00
|
|
|
import Lazyload from '../vc-lazy-load';
|
|
|
|
import Checkbox from '../checkbox';
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
function noop() {}
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
export default {
|
2020-03-07 19:45:13 +08:00
|
|
|
name: 'ListItem',
|
2020-07-19 22:40:35 +08:00
|
|
|
inheritAttrs: false,
|
2018-04-07 00:20:45 +08:00
|
|
|
props: {
|
|
|
|
renderedText: PropTypes.any,
|
|
|
|
renderedEl: PropTypes.any,
|
|
|
|
item: PropTypes.any,
|
2020-10-10 18:16:28 +08:00
|
|
|
lazy: PropTypes.oneOfType([PropTypes.looseBool, PropTypes.object]),
|
|
|
|
checked: PropTypes.looseBool,
|
2018-04-07 00:20:45 +08:00
|
|
|
prefixCls: PropTypes.string,
|
2020-10-10 18:16:28 +08:00
|
|
|
disabled: PropTypes.looseBool,
|
2020-08-05 17:17:07 +08:00
|
|
|
onClick: PropTypes.func,
|
2018-04-07 00:20:45 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
const { renderedText, renderedEl, item, lazy, checked, disabled, prefixCls } = this.$props;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
const className = classNames({
|
|
|
|
[`${prefixCls}-content-item`]: true,
|
2018-12-05 20:00:13 +08:00
|
|
|
[`${prefixCls}-content-item-disabled`]: disabled || item.disabled,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
let title;
|
2018-12-05 20:00:13 +08:00
|
|
|
if (typeof renderedText === 'string' || typeof renderedText === 'number') {
|
2019-01-12 11:33:27 +08:00
|
|
|
title = String(renderedText);
|
2018-12-05 20:00:13 +08:00
|
|
|
}
|
|
|
|
|
2018-04-07 00:20:45 +08:00
|
|
|
const listItem = (
|
|
|
|
<li
|
|
|
|
class={className}
|
2018-12-05 20:00:13 +08:00
|
|
|
title={title}
|
2019-01-12 11:33:27 +08:00
|
|
|
onClick={
|
|
|
|
disabled || item.disabled
|
|
|
|
? noop
|
|
|
|
: () => {
|
|
|
|
this.$emit('click', item);
|
|
|
|
}
|
|
|
|
}
|
2018-04-07 00:20:45 +08:00
|
|
|
>
|
2018-12-05 20:00:13 +08:00
|
|
|
<Checkbox checked={checked} disabled={disabled || item.disabled} />
|
2020-03-07 19:45:13 +08:00
|
|
|
<span class={`${prefixCls}-content-item-text`}>{renderedEl}</span>
|
2018-04-07 00:20:45 +08:00
|
|
|
</li>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
|
|
|
let children = null;
|
2018-04-07 00:20:45 +08:00
|
|
|
if (lazy) {
|
|
|
|
const lazyProps = {
|
2020-07-19 22:40:35 +08:00
|
|
|
height: 32,
|
|
|
|
offset: 500,
|
|
|
|
throttle: 0,
|
|
|
|
debounce: false,
|
|
|
|
...lazy,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2020-08-27 22:38:56 +08:00
|
|
|
children = <Lazyload {...lazyProps}>{listItem}</Lazyload>;
|
2018-04-07 00:20:45 +08:00
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
children = listItem;
|
2018-04-07 00:20:45 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
return children;
|
2018-04-07 00:20:45 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|