import PropTypes from '../_util/vue-types'; import classNames from 'classnames'; import { getComponent, isStringElement, isEmptyElement, getSlot } from '../_util/props-util'; import { Col } from '../grid'; import { ConfigConsumerProps } from '../config-provider'; import { ListGridType } from './index'; import { cloneElement } from '../_util/vnode'; import { inject } from 'vue'; 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 AListItemMeta = (props, { slots }) => { const configProvider = inject('configProvider', ConfigConsumerProps); const getPrefixCls = configProvider.getPrefixCls; const { prefixCls: customizePrefixCls } = props; const prefixCls = getPrefixCls('list', customizePrefixCls); const avatar = props.avatar || slots.avatar?.(); const title = props.title || slots.title?.(); const description = props.description || slots.description?.(); const content = (
{title &&

{title}

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