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

[material-ui][docs] Simplify components styling on templates #41845

Merged
merged 9 commits into from
Apr 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,36 @@ import CreditCardRoundedIcon from '@mui/icons-material/CreditCardRounded';
import SimCardRoundedIcon from '@mui/icons-material/SimCardRounded';
import WarningRoundedIcon from '@mui/icons-material/WarningRounded';

import { styled } from '@mui/system';
import { styled } from '@mui/material/styles';

const StyledCard = styled(Card)(({ theme }) => ({
zanivan marked this conversation as resolved.
Show resolved Hide resolved
flexGrow: 1,
border: '1px solid',
borderColor: theme.palette.divider,
'&:hover': {
background:
theme.palette.mode === 'light'
? 'linear-gradient(to bottom right, hsla(210, 100%, 97%, 0.5) 25%, hsla(210, 100%, 90%, 0.3) 100%)'
: 'linear-gradient(to right bottom, hsla(210, 100%, 12%, 0.2) 25%, hsla(210, 100%, 16%, 0.2) 100%)',
borderColor: theme.palette.mode === 'light' ? 'primary.light' : 'primary.dark',
boxShadow:
theme.palette.mode === 'light'
? '0px 2px 8px hsla(0, 0%, 0%, 0.1)'
: '0px 1px 8px hsla(210, 100%, 25%, 0.5) ',
},
}));

const StyledBox = styled(Box)(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
width: '100%',
borderRadius: '20px',
border: '1px solid ',
borderColor: theme.palette.divider,
backgroundColor: theme.palette.background.paper,
boxShadow: '0px 4px 8px hsla(210, 0%, 0%, 0.05)',
}));

const FormGrid = styled('div')(() => ({
display: 'flex',
Expand Down Expand Up @@ -72,24 +101,9 @@ export default function PaymentForm() {
gap: 2,
}}
>
<Card
<StyledCard
sx={(theme) => ({
maxWidth: { sm: '100%', md: '50%' },
flexGrow: 1,
border: '1px solid',
borderColor: 'divider',
'&:hover': {
background:
theme.palette.mode === 'light'
? 'linear-gradient(to bottom right, hsla(210, 100%, 97%, 0.5) 25%, hsla(210, 100%, 90%, 0.3) 100%)'
: 'linear-gradient(to right bottom, hsla(210, 100%, 12%, 0.2) 25%, hsla(210, 100%, 16%, 0.2) 100%)',
borderColor:
theme.palette.mode === 'light' ? 'primary.light' : 'primary.dark',
boxShadow:
theme.palette.mode === 'light'
? '0px 2px 8px hsla(0, 0%, 0%, 0.1)'
: '0px 1px 8px hsla(210, 100%, 25%, 0.5) ',
},
...(paymentType === 'creditCard' && {
backgroundColor: 'action.selected',
borderColor:
Expand Down Expand Up @@ -121,25 +135,10 @@ export default function PaymentForm() {
<Typography fontWeight="medium">Card</Typography>
</CardContent>
</CardActionArea>
</Card>
<Card
</StyledCard>
<StyledCard
sx={(theme) => ({
maxWidth: { sm: '100%', md: '50%' },
flexGrow: 1,
border: '1px solid',
borderColor: 'divider',
'&:hover': {
background:
theme.palette.mode === 'light'
? 'linear-gradient(to bottom right, hsla(210, 100%, 97%, 0.5) 25%, hsla(210, 100%, 90%, 0.3) 100%)'
: 'linear-gradient(to right bottom, hsla(210, 100%, 12%, 0.2) 25%, hsla(210, 100%, 16%, 0.2) 100%)',
borderColor:
theme.palette.mode === 'light' ? 'primary.light' : 'primary.dark',
boxShadow:
theme.palette.mode === 'light'
? '0px 2px 8px hsla(0, 0%, 0%, 0.1)'
: '0px 1px 8px hsla(210, 100%, 25%, 0.5) ',
},
...(paymentType === 'bankTransfer' && {
zanivan marked this conversation as resolved.
Show resolved Hide resolved
backgroundColor: 'action.selected',
borderColor:
Expand Down Expand Up @@ -171,7 +170,7 @@ export default function PaymentForm() {
<Typography fontWeight="medium">Bank account</Typography>
</CardContent>
</CardActionArea>
</Card>
</StyledCard>
</RadioGroup>
</FormControl>
{paymentType === 'creditCard' && (
Expand All @@ -182,21 +181,7 @@ export default function PaymentForm() {
gap: 2,
}}
>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
p: 3,
height: { xs: 300, sm: 350, md: 375 },
width: '100%',
borderRadius: '20px',
border: '1px solid ',
borderColor: 'divider',
backgroundColor: 'background.paper',
boxShadow: '0px 4px 8px hsla(210, 0%, 0%, 0.05)',
}}
>
<StyledBox sx={{ height: { xs: 300, sm: 350, md: 375 }, p: 3 }}>
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Typography variant="subtitle2">Credit card</Typography>
<CreditCardRoundedIcon sx={{ color: 'text.secondary' }} />
Expand Down Expand Up @@ -269,7 +254,7 @@ export default function PaymentForm() {
/>
</FormGrid>
</Box>
</Box>
</StyledBox>
<FormControlLabel
control={<Checkbox name="saveCard" />}
label="Remember credit card details for next time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,36 @@ import CreditCardRoundedIcon from '@mui/icons-material/CreditCardRounded';
import SimCardRoundedIcon from '@mui/icons-material/SimCardRounded';
import WarningRoundedIcon from '@mui/icons-material/WarningRounded';

import { styled } from '@mui/system';
import { styled } from '@mui/material/styles';

const StyledCard = styled(Card)(({ theme }) => ({
flexGrow: 1,
border: '1px solid',
borderColor: theme.palette.divider,
'&:hover': {
background:
theme.palette.mode === 'light'
? 'linear-gradient(to bottom right, hsla(210, 100%, 97%, 0.5) 25%, hsla(210, 100%, 90%, 0.3) 100%)'
: 'linear-gradient(to right bottom, hsla(210, 100%, 12%, 0.2) 25%, hsla(210, 100%, 16%, 0.2) 100%)',
borderColor: theme.palette.mode === 'light' ? 'primary.light' : 'primary.dark',
boxShadow:
theme.palette.mode === 'light'
? '0px 2px 8px hsla(0, 0%, 0%, 0.1)'
: '0px 1px 8px hsla(210, 100%, 25%, 0.5) ',
},
}));

const StyledBox = styled(Box)(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
width: '100%',
borderRadius: '20px',
border: '1px solid ',
borderColor: theme.palette.divider,
backgroundColor: theme.palette.background.paper,
boxShadow: '0px 4px 8px hsla(210, 0%, 0%, 0.05)',
}));

const FormGrid = styled('div')(() => ({
display: 'flex',
Expand Down Expand Up @@ -74,24 +103,9 @@ export default function PaymentForm() {
gap: 2,
}}
>
<Card
<StyledCard
sx={(theme) => ({
maxWidth: { sm: '100%', md: '50%' },
flexGrow: 1,
border: '1px solid',
borderColor: 'divider',
'&:hover': {
background:
theme.palette.mode === 'light'
? 'linear-gradient(to bottom right, hsla(210, 100%, 97%, 0.5) 25%, hsla(210, 100%, 90%, 0.3) 100%)'
: 'linear-gradient(to right bottom, hsla(210, 100%, 12%, 0.2) 25%, hsla(210, 100%, 16%, 0.2) 100%)',
borderColor:
theme.palette.mode === 'light' ? 'primary.light' : 'primary.dark',
boxShadow:
theme.palette.mode === 'light'
? '0px 2px 8px hsla(0, 0%, 0%, 0.1)'
: '0px 1px 8px hsla(210, 100%, 25%, 0.5) ',
},
...(paymentType === 'creditCard' && {
backgroundColor: 'action.selected',
borderColor:
Expand Down Expand Up @@ -123,25 +137,10 @@ export default function PaymentForm() {
<Typography fontWeight="medium">Card</Typography>
</CardContent>
</CardActionArea>
</Card>
<Card
</StyledCard>
<StyledCard
sx={(theme) => ({
maxWidth: { sm: '100%', md: '50%' },
flexGrow: 1,
border: '1px solid',
borderColor: 'divider',
'&:hover': {
background:
theme.palette.mode === 'light'
? 'linear-gradient(to bottom right, hsla(210, 100%, 97%, 0.5) 25%, hsla(210, 100%, 90%, 0.3) 100%)'
: 'linear-gradient(to right bottom, hsla(210, 100%, 12%, 0.2) 25%, hsla(210, 100%, 16%, 0.2) 100%)',
borderColor:
theme.palette.mode === 'light' ? 'primary.light' : 'primary.dark',
boxShadow:
theme.palette.mode === 'light'
? '0px 2px 8px hsla(0, 0%, 0%, 0.1)'
: '0px 1px 8px hsla(210, 100%, 25%, 0.5) ',
},
...(paymentType === 'bankTransfer' && {
backgroundColor: 'action.selected',
borderColor:
Expand Down Expand Up @@ -173,7 +172,7 @@ export default function PaymentForm() {
<Typography fontWeight="medium">Bank account</Typography>
</CardContent>
</CardActionArea>
</Card>
</StyledCard>
</RadioGroup>
</FormControl>
{paymentType === 'creditCard' && (
Expand All @@ -184,21 +183,7 @@ export default function PaymentForm() {
gap: 2,
}}
>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
p: 3,
height: { xs: 300, sm: 350, md: 375 },
width: '100%',
borderRadius: '20px',
border: '1px solid ',
borderColor: 'divider',
backgroundColor: 'background.paper',
boxShadow: '0px 4px 8px hsla(210, 0%, 0%, 0.05)',
}}
>
<StyledBox sx={{ height: { xs: 300, sm: 350, md: 375 }, p: 3 }}>
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Typography variant="subtitle2">Credit card</Typography>
<CreditCardRoundedIcon sx={{ color: 'text.secondary' }} />
Expand Down Expand Up @@ -271,7 +256,7 @@ export default function PaymentForm() {
/>
</FormGrid>
</Box>
</Box>
</StyledBox>
<FormControlLabel
control={<Checkbox name="saveCard" />}
label="Remember credit card details for next time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Grid from '@mui/material/Grid';
import Link from '@mui/material/Link';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import { styled } from '@mui/material/styles';
import ChevronRightRoundedIcon from '@mui/icons-material/ChevronRightRounded';
import DevicesRoundedIcon from '@mui/icons-material/DevicesRounded';
import EdgesensorHighRoundedIcon from '@mui/icons-material/EdgesensorHighRounded';
Expand Down Expand Up @@ -40,6 +41,21 @@ const items = [
},
];

const StyledChip = styled(Chip)(({ theme, selected }) => ({
...(selected && {
borderColor:
theme.palette.mode === 'light'
? theme.palette.primary.light
: theme.palette.primary.dark,
background:
'linear-gradient(to bottom right, hsl(210, 98%, 48%), hsl(210, 98%, 35%))',
color: 'hsl(0, 0%, 100%)',
'& .MuiChip-label': {
color: 'hsl(0, 0%, 100%)',
},
}),
}));

export default function Features() {
const [selectedItemIndex, setSelectedItemIndex] = React.useState(0);

Expand Down Expand Up @@ -69,24 +85,11 @@ export default function Features() {
</div>
<Grid container item gap={1} sx={{ display: { xs: 'auto', sm: 'none' } }}>
{items.map(({ title }, index) => (
<Chip
<StyledChip
key={index}
label={title}
onClick={() => handleItemClick(index)}
sx={(theme) => ({
...(selectedItemIndex === index && {
borderColor:
theme.palette.mode === 'light'
? 'primary.light'
: 'primary.dark',
background:
'linear-gradient(to bottom right, hsl(210, 98%, 48%), hsl(210, 98%, 35%))',
color: 'hsl(0, 0%, 100%)',
'& .MuiChip-label': {
color: 'hsl(0, 0%, 100%)',
},
}),
})}
selected={selectedItemIndex === index}
/>
))}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Grid from '@mui/material/Grid';
import Link from '@mui/material/Link';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import { styled } from '@mui/material/styles';
import ChevronRightRoundedIcon from '@mui/icons-material/ChevronRightRounded';
import DevicesRoundedIcon from '@mui/icons-material/DevicesRounded';
import EdgesensorHighRoundedIcon from '@mui/icons-material/EdgesensorHighRounded';
Expand Down Expand Up @@ -40,6 +41,25 @@ const items = [
},
];

interface StyledChipProps {
zanivan marked this conversation as resolved.
Show resolved Hide resolved
selected?: boolean;
}

const StyledChip = styled(Chip)<StyledChipProps>(({ theme, selected }) => ({
...(selected && {
borderColor:
theme.palette.mode === 'light'
? theme.palette.primary.light
: theme.palette.primary.dark,
background:
'linear-gradient(to bottom right, hsl(210, 98%, 48%), hsl(210, 98%, 35%))',
color: 'hsl(0, 0%, 100%)',
'& .MuiChip-label': {
color: 'hsl(0, 0%, 100%)',
},
}),
}));

export default function Features() {
const [selectedItemIndex, setSelectedItemIndex] = React.useState(0);

Expand Down Expand Up @@ -69,24 +89,11 @@ export default function Features() {
</div>
<Grid container item gap={1} sx={{ display: { xs: 'auto', sm: 'none' } }}>
{items.map(({ title }, index) => (
<Chip
<StyledChip
key={index}
label={title}
onClick={() => handleItemClick(index)}
sx={(theme) => ({
...(selectedItemIndex === index && {
borderColor:
theme.palette.mode === 'light'
? 'primary.light'
: 'primary.dark',
background:
'linear-gradient(to bottom right, hsl(210, 98%, 48%), hsl(210, 98%, 35%))',
color: 'hsl(0, 0%, 100%)',
'& .MuiChip-label': {
color: 'hsl(0, 0%, 100%)',
},
}),
})}
selected={selectedItemIndex === index}
/>
))}
</Grid>
Expand Down
Loading
Loading