import { ReactNode, useMemo } from 'react'; import { getEntryPointType } from '@/config/features'; import { cn } from '@/lib/utils'; // shadcn 核心类名合并工具 export interface PageHeaderProps extends React.HTMLAttributes { /** 要显示的图标组件 */ icon: ReactNode; /** * 图标的颜色,支持: * 1. Tailwind 颜色类名 (如 'text-blue-500', 'text-primary') -> 推荐 * 2. 原生颜色值 (如 '#3b82f6') */ iconColor?: string; /** 主标题文本 */ title: string; /** 副标题文本(可选) */ subtitle?: string; /** 在标题右侧显示的徽章/标签组件(可选) */ badge?: ReactNode; /** 覆盖图标容器的类名 */ iconClassName?: string; /** 覆盖主标题的类名 */ titleClassName?: string; /** 覆盖副标题的类名 */ subtitleClassName?: string; } export default function PageHeader({ icon, iconColor = 'text-blue-500', // 默认改用类名,若需保持 Hex 可写 "#3b82f6" title, subtitle, badge, iconClassName, titleClassName, subtitleClassName, className, ...props }: PageHeaderProps) { const entryPointType = useMemo(() => getEntryPointType(), []); // 扩展环境判断:如果是 popup 形式则不渲染头部 if (entryPointType === 'popup') { return null; } // 判断传入的是否是 Hex/RGB 等原生颜色值 const isRawColor = iconColor.startsWith('#') || iconColor.startsWith('rgb') || iconColor.startsWith('hsl'); return (
{/* 图标容器 */}
{/* 确保图标大小可控,通过子元素选择器约束 SVG 宽高 */}
{icon}
{/* 标题区域 */}
{/* 标题行(含徽章) */}

{title}

{badge &&
{badge}
}
{/* 副标题 - 使用 p 标签(block)保证换行 */} {subtitle && (

{subtitle}

)}
); }