I'm currently utilizing an older version of react-boilerplate that includes CSS Modules, allowing for the creation of variables and the ability to import them into other CSS files.
Below is my colors.css file:
:root {
/* Status colors */
--error: #842A2B;
--success: #657C59;
--pending: #666;
--warning: #7E6939;
}
To import this file, all I need to do is include the following at the top of my .css file:
@import 'components/App/colors.css';
I am interested in implementing two themes on my website and am seeking a way to dynamically update these variables using JavaScript. What would be the most effective approach for achieving this?
Edit: I am hoping there's a solution that allows me to update the colors.css file without needing to apply conditional imports throughout all components that may use either of the two possible CSS files. If such a method exists, please let me know so I can change the accepted answer. Thank you to everyone who provided responses!