fix(pageHeader): 使用 MUI 主题色替代硬编码颜色,支持暗色模式

This commit is contained in:
雨霖铃
2026-05-21 00:34:02 +08:00
parent e4fac241f1
commit 704ec7289d
2 changed files with 34 additions and 17 deletions
+8 -5
View File
@@ -1,4 +1,4 @@
import { alpha, Box, Stack, SxProps, Theme, Typography } from '@mui/material';
import { alpha, Box, Stack, SxProps, Theme, Typography, useTheme } from '@mui/material';
import { ReactNode } from 'react';
/**
@@ -7,7 +7,7 @@ import { ReactNode } from 'react';
export interface PageHeaderProps {
/** 要显示的图标组件 */
icon: ReactNode;
/** 图标的颜色,默认为 '#1976d2'(蓝色) */
/** 图标的颜色,默认使用主题 primary.main 色 */
iconColor?: string;
/** 主标题文本 */
title: string;
@@ -53,7 +53,7 @@ export interface PageHeaderProps {
*/
export default function PageHeader({
icon,
iconColor = '#1976d2',
iconColor,
title,
subtitle,
badge,
@@ -62,6 +62,9 @@ export default function PageHeader({
subtitleSx,
sx,
}: PageHeaderProps) {
const theme = useTheme();
const resolvedIconColor = iconColor ?? theme.palette.primary.main;
return (
<Stack direction="row" spacing={1.5} alignItems="center" sx={{ mb: 2.5, ...sx }}>
{/* 图标容器 */}
@@ -69,8 +72,8 @@ export default function PageHeader({
sx={{
p: 1,
borderRadius: 2.5,
bgcolor: alpha(iconColor, 0.1),
color: iconColor,
bgcolor: alpha(resolvedIconColor, 0.1),
color: resolvedIconColor,
display: 'flex',
...iconSx,
}}