-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs][CardActionArea] Added demo in docs of cards for adding props t…
…o CardActionArea (#44789) Signed-off-by: siddhantantil39 <[email protected]> Co-authored-by: siriwatknp <[email protected]> Co-authored-by: Sycamore <[email protected]> Co-authored-by: ZeeshanTamboli <[email protected]>
- Loading branch information
1 parent
04ac13a
commit 3ae7a04
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Card from '@mui/material/Card'; | ||
import CardContent from '@mui/material/CardContent'; | ||
import Typography from '@mui/material/Typography'; | ||
import CardActionArea from '@mui/material/CardActionArea'; | ||
|
||
const cards = [ | ||
{ | ||
id: 1, | ||
title: 'Plants', | ||
description: 'Plants are essential for all life.', | ||
}, | ||
{ | ||
id: 2, | ||
title: 'Animals', | ||
description: 'Animals are a part of nature.', | ||
}, | ||
{ | ||
id: 3, | ||
title: 'Humans', | ||
description: 'Humans depend on plants and animals for survival.', | ||
}, | ||
]; | ||
|
||
function SelectActionCard() { | ||
const [selectedCard, setSelectedCard] = React.useState(0); | ||
return ( | ||
<Box | ||
sx={{ | ||
width: '100%', | ||
display: 'grid', | ||
gridTemplateColumns: 'repeat(auto-fill, minmax(min(200px, 100%), 1fr))', | ||
gap: 2, | ||
}} | ||
> | ||
{cards.map((card, index) => ( | ||
<Card> | ||
<CardActionArea | ||
onClick={() => setSelectedCard(index)} | ||
data-active={selectedCard === index ? '' : undefined} | ||
sx={{ | ||
height: '100%', | ||
'&[data-active]': { | ||
backgroundColor: 'action.selected', | ||
'&:hover': { | ||
backgroundColor: 'action.selectedHover', | ||
}, | ||
}, | ||
}} | ||
> | ||
<CardContent sx={{ height: '100%' }}> | ||
<Typography variant="h5" component="div"> | ||
{card.title} | ||
</Typography> | ||
<Typography variant="body2" color="text.secondary"> | ||
{card.description} | ||
</Typography> | ||
</CardContent> | ||
</CardActionArea> | ||
</Card> | ||
))} | ||
</Box> | ||
); | ||
} | ||
|
||
export default SelectActionCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Card from '@mui/material/Card'; | ||
import CardContent from '@mui/material/CardContent'; | ||
import Typography from '@mui/material/Typography'; | ||
import CardActionArea from '@mui/material/CardActionArea'; | ||
|
||
const cards = [ | ||
{ | ||
id: 1, | ||
title: 'Plants', | ||
description: 'Plants are essential for all life.', | ||
}, | ||
{ | ||
id: 2, | ||
title: 'Animals', | ||
description: 'Animals are a part of nature.', | ||
}, | ||
{ | ||
id: 3, | ||
title: 'Humans', | ||
description: 'Humans depend on plants and animals for survival.', | ||
}, | ||
]; | ||
|
||
function SelectActionCard() { | ||
const [selectedCard, setSelectedCard] = React.useState(0); | ||
return ( | ||
<Box | ||
sx={{ | ||
width: '100%', | ||
display: 'grid', | ||
gridTemplateColumns: 'repeat(auto-fill, minmax(min(200px, 100%), 1fr))', | ||
gap: 2, | ||
}} | ||
> | ||
{cards.map((card, index) => ( | ||
<Card> | ||
<CardActionArea | ||
onClick={() => setSelectedCard(index)} | ||
data-active={selectedCard === index ? '' : undefined} | ||
sx={{ | ||
height: '100%', | ||
'&[data-active]': { | ||
backgroundColor: 'action.selected', | ||
'&:hover': { | ||
backgroundColor: 'action.selectedHover', | ||
}, | ||
}, | ||
}} | ||
> | ||
<CardContent sx={{ height: '100%' }}> | ||
<Typography variant="h5" component="div"> | ||
{card.title} | ||
</Typography> | ||
<Typography variant="body2" color="text.secondary"> | ||
{card.description} | ||
</Typography> | ||
</CardContent> | ||
</CardActionArea> | ||
</Card> | ||
))} | ||
</Box> | ||
); | ||
} | ||
|
||
export default SelectActionCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters