johannesjo / angular-material-css-vars

Little library to use css variables with @angular/material

Home Page:https://johannesjo.github.io/angular-material-css-vars/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow setting theme on a specific element

jmkeppler opened this issue · comments

Would it be possible to allow passing in an optional html element to the SetPrimaryColor, SetAccentColor, and the SetWarnColor methods so that we can add a theme to a specific element other than the body?

What is the use case behind this? From my understanding, an application should have only one set of theme colors. I don't understand why a primary color should be different on different elements, doesn't this miss their purpose?

Material allows this by doing this: https://material.angular.io/guide/theming#scoping-style-customizations

My use case is there are client colors, then there are sections with static "information" colors like green for correctness, etc. I can achieve this by doing it the material way, but I'd like to be able to create generic controls that use the css helpers of this library to get the color for other stylings.

I can create a sample app to demonstrate if needed

Thanks for clarification, a demo app is not necessary. I was not aware that scoping themes to a specific element is supported by Angular Material. In theory this can be achieved by overwriting the CSS variables on an element. However, implementing this will not be too easy, there are a few questions which will need to be answered first:

  1. How can this actually be implemented? Should this be solved via SCSS rather than TypeScript, like Angular Material does, or does it even need to be a hybrid solution?
  2. How can an element be passed to the function? (Name of selector? HTMLElement instance? ElementRef instance?)
  3. Should there be a possibility to remove theming from an element?

Additionally it needs to be ensured that the auto contrast logic runs and updates the foreground color as well.

As this is not so trivial to implement, and there doesn't seem to be a strong need in the community (yet), this has a low priority to be implemented. However, if someone would like to implement this feature themselves, go ahead!