Variables for Angular Material themes

My app has multiple theme files, and I select the theme during runtime.

.client1-theme{
    // @include angular-material-theme($client1-theme);  
    @include all-component-colors($client1-theme);
    @include theme-color-grabber($client1-theme, $client1-alternate);
    @include status-background($client1-theme);
    @include spinner-color($client1-theme);

}

.client2-theme{
    @include all-component-colors($client2-theme);
    @include theme-color-grabber($client2-theme, $client2-alternate);
    @include status-background($client2-theme);
    @include spinner-color($client2-theme);

}

I have a set of SCSS variables stored in another file colors.scss where I define variables like

$primary: mat-color($client1-primary);
$accent: mat-color($client1-accent);
$alternate: mat-color($client1-alternate);

This setup allows me to import the colors.scss file in my components and use the variables in the component's SCSS file.

Now, for each theme selection, I need to change these variable values. For example, for client2-theme, the variables should be:

$primary: mat-color($client2-primary);
$accent: mat-color($client2-accent);
$alternate: mat-color($client2-alternate);

The goal is for the component's SCSS file to use the correct colors/variable values based on the selected theme. I've tried defining global classes through mixins, but that doesn't allow me to use @extend in the component file.

Any suggestions on how this could be achieved?

Thanks

Answer №1

If you're encountering a similar problem

I found a solution by creating a custom mixin that overrides the styles of the component from the main scss file, then applying the mixin for each theme.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for effectively closing div elements

How can I modify this accordion to close when a user clicks on another link, and also change the image of the open "p" tag? Currently, clicking on a link toggles the content and changes the image. However, what I am struggling with is closing the previousl ...

Encountered an issue with npm install where it cannot read the property 'startsWith' of null

I have been trying to find a solution to this problem everywhere, but without success. Most answers suggest that there might be an issue with the proxy settings. Every time I attempt to use npm install -g package-name, an error occurs. npm ERR! Cannot rea ...

The missing binding.node file is causing an issue with Node-sass

Previously, my angular project 7.1 was running smoothly until I upgraded to ubuntu 19.10 and encountered an error upon running npm install: > [email protected] install /home/gabb/dev/homepage/node_modules/node-sass > node scripts/install.js Do ...

Creating an Overlay using a ScrollStrategy in a declarative way

In Short; Can you explain how to utilize a scroll strategy when creating a CdkConnectedOverlay in a declarative manner? Details; The CdkConnectedOverlay is designed as a Directive for simplifying the creation of Overlays through a declarative approach. I ...

Personalized scroll bar within a Chrome application

I'm currently working on customizing the scrollbar for my Chrome App using CSS and I have encountered an issue with rule #2: section { overflow: auto } section::-webkit-scrollbar { width: 5px ; } Oddly enough, when I apply the second rule, Chrom ...

JavaScript/CSS manipulation: The power of overriding animation-fill-mode

When animating text using CSS keyframes, I use animation-fill-mode: forwards to maintain the final look of the animation. For example: #my-text { opacity: 0; } .show-me { animation-name: show-me; animation-duration: 2s; animation-fill-mod ...

Could we apply 'ngZone: 'noop' specifically to a function or component in Angular?

I am currently utilizing a third-party library to create PowerPoint presentations in Angular (Version 5). The third-party library makes numerous asynchronous calls and promises, causing zone.js to keep track of more than 50 loops running simultaneously. Th ...

Navigating JSON data in a POST request using C# in .NET Core version 3.1

Previously, in my .Net Core 2.1 project, I had implemented a method to handle JSON data successfully as shown below: [HttpPost] [Route("sendJsonData")] public JObject saveTemplate(JObject jsonString) { string templateName = (string)jsonString.Sel ...

AGM MAP | Placing marker within a custom polygon created on the map

Query Description I am utilizing the AGM_MAP library for an Angular website, which includes a map where users can select an address for their orders. Current Issue The problem I am facing is that when I add a polygon to the map, the marker cannot be p ...

Adjusting AngularJS scroll position based on key presses

I am currently working on an autocomplete feature using AngularJS. I seem to be experiencing a problem with the scrollbar behavior. In the interactive gif provided, you can observe that the scrollbar remains stationary when navigating with the arrow keys. ...

Best practices for organizing fonts in SCSS 7-1 architecture?

My current project restructuring involves implementing the 7-1 architecture recommended by . As part of this process, I am incorporating flaticons into my project. I'm unsure of where to place the folder and scss file provided by flaticon within the ...

Valid ways to ensure that a CSS image expands outside the boundaries of the containing div

I have inserted an image using the following CSS code: .imgtemp { float:right; top:0px; left:0px; overflow:visible; width:100%; } Although I have added the div tag to display it on the page, ...

CSS Dialect Debate: Container or Wrapper - Which is the Best Term to

Can you explain the distinction between a container and a wrapper, as well as their respective meanings? ...

Display a string of text containing multiple interactive links

I have a table and I want to create an interactive effect where, upon mouseover or click of certain elements, text will appear next to it. This text may contain multiple lines and clickable links within the content. For instance, in the table generated by ...

Implementing a two-column infinite scrolling feature using ISCroll

I am looking to incorporate multi-column infinite scrolling using IScroll infinite scrolling. I want the content of my HTML to appear as follows: <ul> <li>A</li> <li>B</li> <li>C</li> <li>D</li> ...

Apply CSS3 attributes in real time

The for loop I have is functioning properly: <div id="page1div"></div> <script> list = " "; for (var i = 0 ; i < length ; i++) { list = "<h1 class='entriesdisplayed'>" + item(i) + ...

Using Angular to link Google Places API responses to a form: a guide on merging two different length objects with a shared key

I'm struggling with a key concept here regarding displaying the results of a places autocomplete query. I want to replace the types[0] name with more familiar terms such as suburb or city instead of sublocality_level_1 or administrative_area_level_1 ...

Encountered a problem with NGX Infinite Scroll while implementing it in my Angular project

I'm currently using Angular version 11.0.4 and I've been working on implementing infinite scroll functionality with the help of an npm package. Following all the steps outlined in the documentation at https://www.npmjs.com/package/ngx-virtual-scr ...

The alignment issue persists in HTML/CSS despite troubleshooting efforts

I am facing a challenge while attempting to center text within a modal window, despite my efforts the text remains uncentered. This is my HTML code: <div ng-init="modalCompassDir()"> <div class="myModal"> <img class='floor ...

Encountering dependency tree issues while trying to install @angular/material

I'm running into an issue while attempting to install the @angular/material module. Every time I execute the command: $ npm install --save @angular/material npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! ...