@mui/styles
Version:
MUI Styles - The legacy JSS-based styling solution of Material UI.
25 lines • 823 B
JavaScript
import useTheme from "../useTheme/index.js";
import propsToClassKey from "../propsToClassKey/index.js";
const useThemeVariants = (props, name) => {
const {
classes = {}
} = props;
const theme = useTheme();
let variantsClasses = '';
if (theme && theme.components && theme.components[name] && theme.components[name].variants) {
const themeVariants = theme.components[name].variants;
themeVariants.forEach(themeVariant => {
let isMatch = true;
Object.keys(themeVariant.props).forEach(key => {
if (props[key] !== themeVariant.props[key]) {
isMatch = false;
}
});
if (isMatch) {
variantsClasses = `${variantsClasses}${classes[propsToClassKey(themeVariant.props)]} `;
}
});
}
return variantsClasses;
};
export default useThemeVariants;