I am developing a Dashboard in Angular with a Plugin Architecture to keep it easily extensible. The dashboard consists of pre-defined visualizations like scatter plots. I also want to allow adding visualizations from external sources, i.e., an angular component that is capable of drawing 3D plots. I have successfully implemented the Plugin Architecture on the Angular and Typescript side. However, I'm facing challenges in making the SCSS styles easily extensible and ensuring a seamless look and feel when integrating visualizations from external sources.
Specifically, I want each component to have its own styles, such as font color and size. Additionally, I want to define a global-styles.scss file where I can overwrite these styles. When styles are defined in global-styles.scss, they should overwrite the local styles.
Currently, I have come up with the following (working) approach:
/* global-styles.scss */
:root {
--header-color: hotpink;
}
/* scatter-plot.scss */
:host {
--default-header-color: blue;
}
.header {
color: var(--header-color, var(--default-header-color));
}
While this approach seems to work, it involves lots of repetition because I always need to use var(--XY, var(--default-XY)) for each custom property usage. So I'm wondering whether there's a cleaner and more efficient way to achieve the desired behavior? I have attempted to directly overwrite the custom properties, but I couldn't get it working as the "outer CSS" would need to overwrite the "inner CSS" (i.e., global-styles.scss should overwrite scatter-plot.scss).
EDIT
Ideally, it should also support theming (light and dark mode). Thus, I guess it would be easier to stick to CSS custom properties rather than SCSS, because they can be easily overwritten at runtime.
You can utilize CSS custom properties. By organizing your styles and leveraging cascading nature of CSS, you can achieve the desired behavior without the repetition of var(--XY, var(--default-XY)) for each custom property usage.
Here's an improved approach that builds upon your existing setup:
By using the var(--header-color) directly in the .header class, the pattern for each usage and rest will be taken care of with the help of CSS Cascading.
Regarding theming (light and dark mode), you can create different sets of custom properties for each theme, and swap them out dynamically. For example:
To switch to the dark theme, you can programmatically update the values of the custom properties to their corresponding dark mode values.
With this setup, you can easily extend and override styles in individual components while maintaining a seamless look and feel across your dashboard.
Try this and let me know.