Fix prayers page layout using flexbox instead of Grid
- Replaced Grid components with Box components using flexbox - Sidebar now takes 25% width on desktop, 100% on mobile - Prayer list takes remaining space with flex: 1 - Responsive layout switches to column on mobile - Fixed side-by-side layout issue 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import {
|
import {
|
||||||
Container,
|
Container,
|
||||||
Grid,
|
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
Typography,
|
Typography,
|
||||||
@@ -285,9 +284,9 @@ export default function PrayersPage() {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Grid container spacing={4}>
|
<Box sx={{ display: 'flex', gap: 4, flexDirection: { xs: 'column', md: 'row' } }}>
|
||||||
{/* Categories Filter */}
|
{/* Categories Filter */}
|
||||||
<Grid item xs={12} md={3}>
|
<Box sx={{ width: { xs: '100%', md: '25%' }, flexShrink: 0 }}>
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{/* Add Prayer Button */}
|
{/* Add Prayer Button */}
|
||||||
@@ -353,10 +352,10 @@ export default function PrayersPage() {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</Grid>
|
</Box>
|
||||||
|
|
||||||
{/* Prayer Requests */}
|
{/* Prayer Requests */}
|
||||||
<Grid item xs={12} md={9}>
|
<Box sx={{ flex: 1, width: { xs: '100%', md: '75%' } }}>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Box>
|
<Box>
|
||||||
{Array.from({ length: 3 }).map((_, index) => (
|
{Array.from({ length: 3 }).map((_, index) => (
|
||||||
@@ -467,8 +466,8 @@ export default function PrayersPage() {
|
|||||||
})}
|
})}
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Box>
|
||||||
</Grid>
|
</Box>
|
||||||
|
|
||||||
{/* Add Prayer Dialog */}
|
{/* Add Prayer Dialog */}
|
||||||
<Dialog
|
<Dialog
|
||||||
|
|||||||
123
bibles/Upgrade to Grid v2 - Material UI-20250920-173905.md
Normal file
123
bibles/Upgrade to Grid v2 - Material UI-20250920-173905.md
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
# Upgrade to Grid v2 - Material UI
|
||||||
|
|
||||||
|
Skip to content
|
||||||
|
|
||||||
|
|
||||||
|
+
|
||||||
|
Upgrade to Grid v2 This guide explains how and why to migrate from the GridLegacy component to the Grid component.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Design and Development tips in your inbox. Every weekday.
|
||||||
|
|
||||||
|
|
||||||
|
ads via Carbon
|
||||||
|
|
||||||
|
|
||||||
|
Grid component versions In Material UI v7, the GridLegacy component has been deprecated and replaced by Grid, which offers several new features as well as significant improvements to the developer experience.
|
||||||
|
This guide explains how to upgrade from GridLegacy to Grid, and includes details for Material UI v5, v6, and v7.
|
||||||
|
Why you should upgrade Grid provides the following improvements over GridLegacy:
|
||||||
|
|
||||||
|
It uses CSS variables, removing CSS specificity from class selectors.
|
||||||
|
You can use sx prop to control any style you'd like.
|
||||||
|
All grids are considered items without specifying the item prop.
|
||||||
|
The offset feature gives you more flexibility for positioning.
|
||||||
|
Nested grids now have no depth limitation.
|
||||||
|
Its implementation doesn't use negative margins so it doesn't overflow like GridLegacy .
|
||||||
|
|
||||||
|
How to upgrade Prerequisites Before proceeding with this upgrade:
|
||||||
|
|
||||||
|
You must be on Material UI v5+.
|
||||||
|
If you're in the process of upgrading your Material UI version, you should complete that upgrade first.
|
||||||
|
|
||||||
|
1. Update the import Depending on the Material UI version you are using, you must update the import as follows:
|
||||||
|
v7 v6 v5 Copy (or ⌘C ) // The legacy Grid component is named GridLegacy
|
||||||
|
- import Grid from '@mui/material/GridLegacy';
|
||||||
|
|
||||||
|
// The updated Grid component is named Grid
|
||||||
|
+ import Grid from '@mui/material/Grid'; 2. Remove legacy props The item and zeroMinWidth props have been removed in the updated Grid.
|
||||||
|
You can safely remove them:
|
||||||
|
- <Grid item zeroMinWidth>
|
||||||
|
+ <Grid>
|
||||||
|
Copy Copied (or ⌘C )
|
||||||
|
3. Update the size props In the GridLegacy component, the size props were named to correspond with the theme's breakpoints.
|
||||||
|
For the default theme, these were xs , sm , md , lg , and xl .
|
||||||
|
Starting from Material UI v6, these props are renamed to size on the updated Grid:
|
||||||
|
<Grid
|
||||||
|
- xs={12}
|
||||||
|
- sm={6}
|
||||||
|
+ size={{ xs: 12, sm: 6 }}
|
||||||
|
>
|
||||||
|
Copy Copied (or ⌘C )
|
||||||
|
If the size is the same for all breakpoints, then you can use a single value:
|
||||||
|
- <Grid xs={6}>
|
||||||
|
+ <Grid size={6}>
|
||||||
|
Copy Copied (or ⌘C )
|
||||||
|
Additionally, the true value for the size props was renamed to "grow" :
|
||||||
|
- <Grid xs>
|
||||||
|
+ <Grid size="grow">
|
||||||
|
Copy Copied (or ⌘C )
|
||||||
|
You can use the following codemod to update the size props:
|
||||||
|
v7 v6 v5 Copy (or ⌘C ) npx @mui/codemod@next v7.0.0/grid-props < path/to/folder > 4. Opt in to legacy negative margins If you're using Material UI v5 and want to apply the negative margins similar to GridLegacy, specify disableEqualOverflow={true} on the grid container.
|
||||||
|
To apply to all grids, add the default props to the theme:
|
||||||
|
import { createTheme , ThemeProvider } from '@mui/material/styles' ;
|
||||||
|
import Grid from '@mui/material/Unstable_Grid2' ;
|
||||||
|
|
||||||
|
const theme = createTheme ( {
|
||||||
|
components : {
|
||||||
|
MuiGrid2 : {
|
||||||
|
defaultProps : {
|
||||||
|
// all grids under this theme will apply
|
||||||
|
// negative margin on the top and left sides.
|
||||||
|
disableEqualOverflow : true ,
|
||||||
|
} ,
|
||||||
|
} ,
|
||||||
|
} ,
|
||||||
|
} ) ;
|
||||||
|
|
||||||
|
function Demo ( ) {
|
||||||
|
return (
|
||||||
|
< ThemeProvider theme = { theme } >
|
||||||
|
< Grid container > ... grids </ Grid >
|
||||||
|
</ ThemeProvider >
|
||||||
|
) ;
|
||||||
|
}
|
||||||
|
Copy Copied (or ⌘C )
|
||||||
|
Common issues Column direction Using direction="column" or direction="column-reverse" is not supported on GridLegacy nor on the updated Grid .
|
||||||
|
If your layout used GridLegacy with these values, it might break when you switch to the updated Grid.
|
||||||
|
If you need a vertical layout, follow the instructions in the Grid documentation .
|
||||||
|
Container width The updated Grid component doesn't grow to the full width of the container by default.
|
||||||
|
If you need the grid to grow to the full width, you can use the sx prop:
|
||||||
|
- <GridLegacy container>
|
||||||
|
+ <Grid container sx={{ width: '100%' }}>
|
||||||
|
|
||||||
|
// alternatively, if the Grid's parent is a flex container:
|
||||||
|
- <GridLegacy container>
|
||||||
|
+ <Grid container sx={{ flexGrow: 1 }}>
|
||||||
|
Copy Copied (or ⌘C )
|
||||||
|
Codemod not covering wrapped Grid components The provided codemods won't cover Grid components which are wrapped in other components or styled:
|
||||||
|
// The codemod won't cover StyledGrid
|
||||||
|
const StyledGrid = styled ( Grid ) ( {
|
||||||
|
// styles
|
||||||
|
} ) ;
|
||||||
|
|
||||||
|
// The codemod won't cover WrappedGrid
|
||||||
|
const WrappedGrid = ( props ) => < Grid { ... props } /> ;
|
||||||
|
Copy Copied (or ⌘C )
|
||||||
|
You'll need to manually update these components.
|
||||||
|
Documentation pages
|
||||||
|
Grid:
|
||||||
|
Documentation
|
||||||
|
API
|
||||||
|
|
||||||
|
|
||||||
|
GridLegacy:
|
||||||
|
Documentation
|
||||||
|
API
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user