import { AppProvider } from "@toolpad/core";
import React from "react";
import { Outlet } from "react-router-dom";
import { ConnectWithoutContact, ViewList } from '@mui/icons-material';
import DashboardIcon from '@mui/icons-material/Dashboard';
import LayersIcon from '@mui/icons-material/Layers';
import SettingsIcon from '@mui/icons-material/Settings';
import logo from './assets/logo.png';
import logoDark from './assets/logo_white.png';
import { extendTheme } from "@mui/material";
import { useAuth } from "./components/Auth/AuthProvider";
const NAVIGATION = [ //my navigation
];
const colors = {
// my colors
};
// Define the theme, adding custom colors to the palette
const dhandhoTheme = extendTheme({
colorSchemes: { light: true, dark: true },
colorSchemeSelector: 'class',
customColors: colors,
palette: {
primary: {
main: '#20A4F3', // #20A4F3
},
success: {
main: '#2EEE80', // #2EEE80
},
// other colors
},
});
// Define the branding object
const branding = {
logo: <img src={logo} alt="Logo" />,
title: '',
homeUrl: '/',
};
export default function App() {
const { session, authentication } = useAuth();
return (
<AppProvider
navigation={NAVIGATION}
branding={branding}
theme={dhandhoTheme}
session={session}
authentication={authentication}
>
<Outlet />
</AppProvider>
);
}
使用MUI的UseColorScheme是一个解决方案:
}
您也可以尝试以下方法:const [mode, setMode] = useState<'light' | 'dark'>('light');
const branding = {
logo: <img
src={mode === 'dark' ? logoDark : logo}
alt="Logo"
/>,
// ...other properties
};
// Add a theme toggle function
const toggleTheme = () => {
setMode(prevMode => prevMode === 'light' ? 'dark' :
'light');
};