Skip to content

Commit

Permalink
[Rating] Add support for CSS variables (#32556)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicasas authored May 3, 2022
1 parent d7afa2e commit 1829236
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
87 changes: 87 additions & 0 deletions docs/pages/experiments/material-ui/rating.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as React from 'react';
import {
Experimental_CssVarsProvider as CssVarsProvider,
useColorScheme,
} from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Container from '@mui/material/Container';
import Moon from '@mui/icons-material/DarkMode';
import Sun from '@mui/icons-material/LightMode';
import Typography from 'docs/src/pages/premium-themes/onepirate/modules/components/Typography';
import { Rating } from '@mui/material';

const ColorSchemePicker = () => {
const { mode, setMode } = useColorScheme();
const [mounted, setMounted] = React.useState(false);
React.useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return null;
}

return (
<Button
variant="outlined"
onClick={() => {
if (mode === 'light') {
setMode('dark');
} else {
setMode('light');
}
}}
>
{mode === 'light' ? <Moon /> : <Sun />}
</Button>
);
};

export default function CssVarsTemplate() {
const [value, setValue] = React.useState<number | null>(2);

return (
<CssVarsProvider>
<CssBaseline />
<Container sx={{ my: 5 }}>
<Box sx={{ pb: 2 }}>
<ColorSchemePicker />
</Box>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(256px, 1fr))',
gridAutoRows: 'minmax(160px, auto)',
gap: 2,
'& > div': {
placeSelf: 'center',
},
}}
>
<Box>
<Typography component="legend">Developer Experience</Typography>
<Rating
name="simple-controlled"
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
/>
</Box>
<Box>
<Typography component="legend">Developer Experience</Typography>
<Rating
disabled
name="simple-controlled"
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
/>
</Box>
</Box>
</Container>
</CssVarsProvider>
);
}
4 changes: 2 additions & 2 deletions packages/mui-material/src/Rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const RatingRoot = styled('span', {
textAlign: 'left',
WebkitTapHighlightColor: 'transparent',
[`&.${ratingClasses.disabled}`]: {
opacity: theme.palette.action.disabledOpacity,
opacity: (theme.vars || theme).palette.action.disabledOpacity,
pointerEvents: 'none',
},
[`&.${ratingClasses.focusVisible} .${ratingClasses.iconActive}`]: {
Expand Down Expand Up @@ -151,7 +151,7 @@ const RatingIcon = styled('span', {
transform: 'scale(1.2)',
}),
...(ownerState.iconEmpty && {
color: theme.palette.action.disabled,
color: (theme.vars || theme).palette.action.disabled,
}),
}));

Expand Down

0 comments on commit 1829236

Please sign in to comment.