Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  83] [ 1]  / answers: 1 / hits: 9381  / 5 Years ago, sun, december 8, 2019, 12:00:00

I would like to declare some css variables that I will reuse among my components. This is how you do it with plain css:



:root {
--box-shadow: 0 2px 5px -1px rgba(0, 0, 0, 0.3);
}


That would then be used as follows:



.my-class {
box-shadow: var(--box-shadow);
}


How can I achieve the same with useStyles? I tried the following with no avail:



const theme = createMuiTheme({
shadowing: {
boxShadow: 0 2px 5px -1px rgba(0, 0, 0, 0.3),
}
});


My main App is enclosed within



<ThemeProvider theme={theme}>
<App />
</ThemeProvider>


I tried using it in my component:



const useStyles = makeStyles(theme => ({
workImage: {
boxShadow: theme.shadowing,
},
}));


But it's not working.


More From » css

 Answers
6

createMuiTheme function accepts object with limited set of keys.(palette, Typography, spacing...etc)



You can use just normal object.



const theme = {
shadowing: {
boxShadow: 0 2px 5px -1px rgba(0, 0, 0, 0.3),
}
};

[#5397] Wednesday, December 4, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daquanmilesw

Total Points: 57
Total Questions: 102
Total Answers: 110

Location: Wallis and Futuna
Member since Sat, Aug 6, 2022
2 Years ago
daquanmilesw questions
;