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