To modify your Layout component to use Material-UI (MUI) for styling, you can utilize MUI's Container, Box, or Paper components, and also apply theme-aware styling using styled or useTheme.
Here's how you can refactor your Layout component using MUI components and styling:
✅ Updated Layout.tsx using MUI
import React from 'react';
import Navbar from '../Navbar';
import { Box, Container, Theme, useTheme } from '@mui/material';
interface LayoutProps {
mode: 'light' | 'dark';
onToggleTheme: () => void;
children?: React.ReactNode;
}
export default function Layout({ mode, onToggleTheme, children }: LayoutProps) {
const theme = useTheme();
return (
<>
<Navbar mode={mode} onToggleTheme={onToggleTheme} />
<Box
component="main"
sx={{
padding: theme.spacing(4),
backgroundColor: theme.palette.mode === 'dark' ? '#121212' : '#f9f9f9',
minHeight: '100vh',
color: theme.palette.text.primary,
}}
>
<Container maxWidth="lg">
{children}
</Container>
</Box>
</>
);
}
🔍 Explanation of Changes:
useTheme(): Used to access the current MUI theme and apply consistent spacing, colors, etc.
Box: A flexible layout component for applying styles (used as <main>).
Container: Wraps the content in a responsive container with max-width at different breakpoints.
theme.spacing(4): Ensures consistent padding using MUI's spacing system.
- Dynamic background/text color: Based on theme mode (
light or dark).
💡 Optional: Use Paper for a card-like layout
If you want a more card-like layout with elevation:
import { Paper } from '@mui/material';
<Box
component="main"
sx={{
padding: theme.spacing(4),
backgroundColor: theme.palette.mode === 'dark' ? '#121212' : '#f5f5f5',
minHeight: '100vh',
}}
>
<Container maxWidth="lg">
<Paper sx={{ padding: theme.spacing(3) }} elevation={3}>
{children}
</Paper>
</Container>
</Box>
Let me know if you want to integrate this with a global MUI Theme provider or use styled components!