From 182923629c0f084d738dc3f5bcfc71d892508a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Casas?= <57921784+vicasas@users.noreply.github.com> Date: Tue, 3 May 2022 07:36:38 -0400 Subject: [PATCH] [Rating] Add support for CSS variables (#32556) --- docs/pages/experiments/material-ui/rating.tsx | 87 +++++++++++++++++++ packages/mui-material/src/Rating/Rating.js | 4 +- 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 docs/pages/experiments/material-ui/rating.tsx diff --git a/docs/pages/experiments/material-ui/rating.tsx b/docs/pages/experiments/material-ui/rating.tsx new file mode 100644 index 00000000000000..67aa4e3e22d417 --- /dev/null +++ b/docs/pages/experiments/material-ui/rating.tsx @@ -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 ( + + ); +}; + +export default function CssVarsTemplate() { + const [value, setValue] = React.useState(2); + + return ( + + + + + + + div': { + placeSelf: 'center', + }, + }} + > + + Developer Experience + { + setValue(newValue); + }} + /> + + + Developer Experience + { + setValue(newValue); + }} + /> + + + + + ); +} diff --git a/packages/mui-material/src/Rating/Rating.js b/packages/mui-material/src/Rating/Rating.js index 6e7d57757c4462..f0f2234850c5c8 100644 --- a/packages/mui-material/src/Rating/Rating.js +++ b/packages/mui-material/src/Rating/Rating.js @@ -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}`]: { @@ -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, }), }));