2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
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 {
|
2019-02-01 09:23:00 +00:00
|
|
|
name: 'Item',
|
2018-04-06 16:20:45 +00:00
|
|
|
props: {
|
|
|
|
renderedText: PropTypes.any,
|
|
|
|
renderedEl: PropTypes.any,
|
|
|
|
item: PropTypes.any,
|
2019-01-12 03:33:27 +00:00
|
|
|
lazy: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
2018-04-06 16:20:45 +00:00
|
|
|
checked: PropTypes.bool,
|
|
|
|
prefixCls: PropTypes.string,
|
2018-12-05 12:00:13 +00:00
|
|
|
disabled: PropTypes.bool,
|
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} />
|
2018-04-06 16:20:45 +00:00
|
|
|
<span>{renderedEl}</span>
|
|
|
|
</li>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
|
|
|
let children = null;
|
2018-04-06 16:20:45 +00:00
|
|
|
if (lazy) {
|
|
|
|
const lazyProps = {
|
|
|
|
props: {
|
|
|
|
height: 32,
|
|
|
|
offset: 500,
|
|
|
|
throttle: 0,
|
|
|
|
debounce: false,
|
|
|
|
...lazy,
|
2018-09-05 13:28:54 +00:00
|
|
|
_propsSymbol: Symbol(),
|
2018-04-06 16:20:45 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +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
|
|
|
};
|