2020-10-11 21:31:57 +08:00
|
|
|
import PropTypes, { withUndefined } 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';
|
2020-10-20 16:45:49 +08:00
|
|
|
import { defineComponent } from 'vue';
|
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
|
|
|
|
2020-10-20 16:45:49 +08:00
|
|
|
export default defineComponent({
|
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-11 21:31:57 +08:00
|
|
|
lazy: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.object])),
|
2020-10-10 18:16:28 +08:00
|
|
|
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,
|
2020-10-20 16:45:49 +08:00
|
|
|
...(lazy as any),
|
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
|
|
|
},
|
2020-10-20 16:45:49 +08:00
|
|
|
});
|