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

Challenges with the dropdown menu navigation bar

I am struggling with my dropdown menu and sign up/sign in buttons as they are not aligning properly. I have tried various coding methods but haven't been able to fix the issue. Can someone provide me with suggestions on how to rectify this problem? c ...

Handling generic errors in Angular 2's Http responses

I'm currently developing an Angular 2 application that involves API requests. I was curious if there is a way to create a universal error handling mechanism. For example, I'd like to automatically redirect users to the login page if the API retur ...

Angular2 - Model not being refreshed by Directive

I have implemented a directive on an HTML input box to handle numeric values. The directive is meant to "clean" the number (removing commas, dollar signs, etc) when a user pastes a number into the textbox. Although the cleaning code works properly, the iss ...

The text-decoration is here to stay

Currently, I am facing an issue with the customization of a wordpress theme related to the styling of links within posts. Although I have tried to change the color and remove underlining using CSS rules, I am unsuccessful so far: a, .entry-meta a, entry-c ...

numerous inquiries regarding my CSS header navigation bars

As someone who is new to CSS, I find myself struggling to grasp the correct approach. Online examples vary and leave me confused. Specifically, I have questions about my markup but overall, am I doing things correctly? I feel like my CSS code is bloated. ...

A guide to accurately accessing form data in Jquery Ajax requests

My beforeSend function is not working properly, as the background color does not change. I suspect it may be due to not correctly referencing the id variable posted from the form. Below is the relevant HTML and JS code: HTML <div id="rec<?php echo ...

Angular 5 introduces a bespoke directive that allows for element repetition within the framework

Looking to create a directive that contains an array of elements, and when the directive is bound to any element, that element will repeat the number of times equal to the length of the array. For example, if the array has 3 elements, the element will re ...

Using Angular 4: Redirecting Menu to Component with Electron

I am currently working on my first project using Angular 4 and Electron to develop a desktop application. One of the challenges I'm facing is figuring out how to redirect to a specific component when a submenu item is clicked after overriding the ele ...

What method can be used to verify if a username exists within Angular data?

We want to display online users on a webpage by checking if they are currently active. The current code logs all online users in the console, but we need to show this visually on the page. public isOnline: boolean = false; ... ... ngOnInit() { ...

Leveraging MUI v5 sx Prop for Applying Various CSS Properties Simultaneously (such as margin, border-radius, and more)

Is there a more efficient way to write the following code that utilizes the sx prop's access to spacing units? <MUIComponent sx={{ borderRadius: '4px 8px 12px 16px' }} /> Could it be written like this instead? <MUIComponent sx={{ b ...

What is the reason behind causing the overflow to become visible on the parent anchor when a child anchor is added?

I've been facing a puzzling issue for the past day. I am working on creating a website that resembles Windows 8, where each box represents a list item. The code is more complex than what I have shared here, but the problem seems to be isolated... &l ...

What are the steps for launching an Angular application?

Running on ubuntu 18.0.4, I had angular-cli installed. Attempting to create a new app named conFusion using the command: ng new conFusion -dir=./conFusion --style=scss. CREATE conFusion/README.md (1026 bytes) CREATE conFusion/angular.json (3666 by ...

An error has occurred in the tipo-struttura component file in an Angular application connected with a Spring backend and SQL database. The error message indicates that there is a TypeError where the

Working on my project that combines Spring, Angular, and MYSQL, I encountered a challenge of managing three interconnected lists. The third list depends on the second one, which in turn relies on user choices made from the first list. While attempting to l ...

Overflowing text in the div element

Attempting to generate a sample document and aiming to enlarge the font-size by clicking the "Medium" & "Large" button. Encountering an issue where the font-size overlaps with other divs when pressing the "large" button, though not experiencing any proble ...

How Angular 8 can gracefully handle asynchronous HTTP results within an if statement

Within my component, I have a method that initiates multiple http GET requests in succession. The issue arises when the next request begins before the previous one has finished processing, whereas I would like each request to be completed before the next o ...

List of prices with a dotted line separating the price and product, adjusting its width based on

I am attempting to create a price list with a dotted underline between the price and product that adjusts dynamically in width. Here is my code snippet: https://jsfiddle.net/romariokbn/2gm27rv6/ <ul class="how-can-i-do"> <li> <span ...

Creating an arrow dialog box in Material UI: A step-by-step guide

I have successfully created an arrow box (div) using custom CSS and HTML. However, I am facing difficulty in implementing the same design in Material UI with React JS. The code below demonstrates how to achieve this using custom CSS. My question is: How ...

The combination of absolute positioning and percentage-based height measurements allows for

For more information, go to http://jsfiddle.net/A2Qnx/1/ <div id='w'> <div id='p'> <div id='c'> </div> </div> </div> With absolute positioning enabled, div P has a height ...

Shift the content downwards within an 'a' snippet located in the sidebar when it reaches the edge of the right border

I'm having an issue with my style.css file. As a beginner in programming, I am trying to position text next to an image attached in the sidebar. However, the text is overflowing past the border. Here's the HTML code: Please see this first to ide ...

Include category to the smallest element

I am attempting to use JQuery to find the height of the tallest element and then add that height to other elements that are shorter. My goal is to assign the class, main-nav-special-padding, to these shorter elements using my current JQuery code. I tried t ...