Let's say i have a file with themes:
themes.js:
import {createMuiTheme} from "@material-ui/core/styles";
export const myTheme = createMuiTheme({
palette: {
text: {
color: "#545F66",
},
},
});
And file with App.js, where render looks something like this:
return (
<MuiThemeProvider theme={myTheme}>
<CssBaseline />
<MyComponent />
</MuiThemeProvider>
);
Now i know that i can access the theme via withStyles:
const StyledMyComponent = withStyles(theme => ({
something: {
color: theme.palette.text.color
}
}))(props => <MyComponent {...props} />);
But what i want to achieve is something different. MyComponent is a very big component and has for example class called "react-table-1" And the thing i want is to set the class color "react-table-1" to theme.palette.text so something like this:
const StyledMyComponent = withStyles(theme => ({
"react-table-1": {
color: theme.palette.text
}
}))(props => <MyComponent {...props} />);
But obviously it doesn't work. Does anyone know if this is possible ? And how can i achieve that.
I can set "react-table-1" color in css file but i want to change it inside react via button, and that's why i need something like this.
Live demo: https://stackblitz.com/edit/react-jt9xs1