DEV Community

Discussion on: Let's implement a Theme Switch 🎨 like the Angular Material Site

Collapse
 
negue profile image
negue

Great article and example on how to create a theme-switch :)

With this way node_modules/@angular/material/prebuilt-themes/${themeToSet}.css I see two disadvantages:

  • You need to add the themes to your assets to the build output (node_modules probable not exist anymore when you serve your app outside of the CLI)
  • You need to load (to the browser) the same-ish payload for each theme

IMO, a better way would be to use @johannesjo Helper Library: Demo - GitHub

With this you only load your the theme-boilerplate once and change all colors using CSS-Vars in browser. This also enables to allow your user's to have a custom theme.

Collapse
 
siddajmera profile image
Siddharth Ajmera 🇮🇳

Hi Negue,

Good point. 😃 I did realise this issue with the approach. I'll probably cover the CSS vars approach in a future article.

Thanks a lot for the feedback 🙌🏻🙂