/** * PostCard 主组件 * 帖子卡片组件 - 支持列表模式和网格模式 * * @example * // 新 API 使用方式 * handleAction(post, action)} * variant="list" * features="full" * /> */ import React from 'react'; import { PostCardProps, LegacyPostCardProps } from './types'; import PostCardList from './PostCardList'; import PostCardGrid from './PostCardGrid'; import { usePostCardFeatures } from './hooks/usePostCardFeatures'; import { createLegacyAdapter, isLegacyProps } from './legacyAdapter'; /** * PostCard 主组件 * 支持新旧两种 API */ const PostCard: React.FC = (props) => { // 检测是否使用旧 API const isLegacy = isLegacyProps(props as LegacyPostCardProps); // 兼容层:转换旧 Props 到新 Props const normalizedProps: PostCardProps = isLegacy ? createLegacyAdapter(props as LegacyPostCardProps) : (props as PostCardProps); const { post, onAction, variant = 'list', features: featuresConfig, isPostAuthor = false, isAuthor = false, index, style, } = normalizedProps; // 解析 Features 配置 const resolvedFeatures = usePostCardFeatures(featuresConfig); // 根据 variant 选择渲染模式 if (variant === 'grid') { return ( ); } return ( ); }; export default PostCard;