ant-design-vue/components/list/ItemMeta.tsx

52 lines
1.7 KiB
Vue
Raw Normal View History

2021-06-26 01:35:40 +00:00
import type { ExtractPropTypes } from 'vue';
import { defineComponent } from 'vue';
2021-06-23 06:44:21 +00:00
import useConfigInject from '../_util/hooks/useConfigInject';
import PropTypes from '../_util/vue-types';
2023-05-18 13:22:58 +00:00
import type { CustomSlotsType } from '../_util/type';
2021-06-23 06:44:21 +00:00
export const listItemMetaProps = () => ({
2021-06-23 06:44:21 +00:00
avatar: PropTypes.any,
description: PropTypes.any,
prefixCls: String,
2021-06-23 06:44:21 +00:00
title: PropTypes.any,
});
2021-06-23 06:44:21 +00:00
export type ListItemMetaProps = Partial<ExtractPropTypes<ReturnType<typeof listItemMetaProps>>>;
2021-06-23 06:44:21 +00:00
export default defineComponent({
compatConfig: { MODE: 3 },
2021-06-23 06:44:21 +00:00
name: 'AListItemMeta',
props: listItemMetaProps(),
2021-06-23 06:44:21 +00:00
displayName: 'AListItemMeta', // 兼容历史函数式组件
__ANT_LIST_ITEM_META: true,
2023-05-18 13:22:58 +00:00
slots: Object as CustomSlotsType<{
avatar: any;
description: any;
title: any;
default: any;
}>,
2021-06-23 06:44:21 +00:00
setup(props, { slots }) {
const { prefixCls } = useConfigInject('list', props);
return () => {
const classString = `${prefixCls.value}-item-meta`;
const title = props.title ?? slots.title?.();
const description = props.description ?? slots.description?.();
const avatar = props.avatar ?? slots.avatar?.();
const content = (
<div class={`${prefixCls.value}-item-meta-content`}>
{title && <h4 class={`${prefixCls.value}-item-meta-title`}>{title}</h4>}
{description && (
<div class={`${prefixCls.value}-item-meta-description`}>{description}</div>
)}
</div>
);
return (
<div class={classString}>
{avatar && <div class={`${prefixCls.value}-item-meta-avatar`}>{avatar}</div>}
{(title || description) && content}
</div>
);
};
},
});