import PropTypes from '../_util/vue-types'; import classNames from 'classnames'; import { getComponentFromProp, isStringElement, getListeners, isEmptyElement, } from '../_util/props-util'; import { Col } from '../grid'; import { ConfigConsumerProps } from '../config-provider'; import { ListGridType } from './index'; import { cloneElement } from '../_util/vnode'; export const ListItemProps = { prefixCls: PropTypes.string, extra: PropTypes.any, actions: PropTypes.arrayOf(PropTypes.any), grid: ListGridType, }; export const ListItemMetaProps = { avatar: PropTypes.any, description: PropTypes.any, prefixCls: PropTypes.string, title: PropTypes.any, }; export const Meta = { functional: true, name: 'AListItemMeta', __ANT_LIST_ITEM_META: true, inject: { configProvider: { default: () => ConfigConsumerProps }, }, render(h, context) { const { props, slots, listeners, injections } = context; const slotsMap = slots(); const getPrefixCls = injections.configProvider.getPrefixCls; const { prefixCls: customizePrefixCls } = props; const prefixCls = getPrefixCls('list', customizePrefixCls); const avatar = props.avatar || slotsMap.avatar; const title = props.title || slotsMap.title; const description = props.description || slotsMap.description; const content = (
{title &&

{title}

} {description &&
{description}
}
); return (
{avatar &&
{avatar}
} {(title || description) && content}
); }, }; function getGrid(grid, t) { return grid[t] && Math.floor(24 / grid[t]); } export default { name: 'AListItem', Meta, props: ListItemProps, inject: { listContext: { default: () => ({}) }, configProvider: { default: () => ConfigConsumerProps }, }, methods: { isItemContainsTextNodeAndNotSingular() { const { $slots } = this; let result; const children = $slots.default || []; children.forEach(element => { if (isStringElement(element) && !isEmptyElement(element)) { result = true; } }); return result && children.length > 1; }, isFlexMode() { const extra = getComponentFromProp(this, 'extra'); const { itemLayout } = this.listContext; if (itemLayout === 'vertical') { return !!extra; } return !this.isItemContainsTextNodeAndNotSingular(); }, }, render() { const { grid, itemLayout } = this.listContext; const { prefixCls: customizePrefixCls, $slots } = this; const listeners = getListeners(this); const getPrefixCls = this.configProvider.getPrefixCls; const prefixCls = getPrefixCls('list', customizePrefixCls); const extra = getComponentFromProp(this, 'extra'); const actions = getComponentFromProp(this, 'actions'); const actionsContent = actions && actions.length > 0 && ( ); const Tag = grid ? 'div' : 'li'; const itemChildren = ( {itemLayout === 'vertical' && extra ? [
{$slots.default} {actionsContent}
,
{extra}
, ] : [$slots.default, actionsContent, cloneElement(extra, { key: 'extra' })]}
); const mainContent = grid ? ( {itemChildren} ) : ( itemChildren ); return mainContent; }, };