Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs][CardActionArea] Added demo in docs of cards for adding props to CardActionArea #44789

Merged
merged 18 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions docs/data/material/components/cards/SelectActionCard.js
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 part of the nature and wildlife.',
siddhantantil39 marked this conversation as resolved.
Show resolved Hide resolved
},
{
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;
67 changes: 67 additions & 0 deletions docs/data/material/components/cards/SelectActionCard.tsx
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 part of the nature and wildlife.',
siddhantantil39 marked this conversation as resolved.
Show resolved Hide resolved
},
{
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;
6 changes: 6 additions & 0 deletions docs/data/material/components/cards/cards.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ Here's an example of a media control card.

{{"demo": "MediaControlCard.js", "bg": true}}

## Active style
siddhantantil39 marked this conversation as resolved.
Show resolved Hide resolved

To style a card to look like it's active, attach a `data-active` to `CardActionArea` component and style it with `&[data-active]` selector.
siddhantantil39 marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "SelectActionCard.js", "bg": true}}

🎨 If you are looking for inspiration, you can check [MUI Treasury's customization examples](https://mui-treasury.com/?path=/docs/card-introduction--docs).
Loading