Issues with color scheme in Angular Material 18

While using (ng generate @angular/material:my--own-theme), I came across some code in own-theme.scss. Surprisingly, this code works for the palette included in Angular Material, but I prefer to use my own theme. Here's what was generated and what I did:


@use 'sass:map';
@use '@angular/material' as mat;

// Color palettes are generated from primary: #2397e6, secondary: #00639a, tertiary: #006c51, neutral: #9dcaff
$_palettes: (
    // color values here...
);

$_rest: (
  // mapping values here...
);

$_rest2: (
  // more mapping here...
);

$_tertiary: map.merge(map.get($_palettes, tertiary), $_rest2);

$_primary: mat.$orange-palette;

$light-theme: mat.define-theme((
  color: (
    theme-type: light,
      primary: $_primary,
      tertiary: $_tertiary
  ),
));

and in HTML

<div class="demo-buttons custom-theme">
  <h2>Custom Theme</h2>
  <button mat-raised-button color="primary">Raised</button>
  <button mat-raised-button color="accent">Accent</button>
  <button mat-raised-button color="tertiary">Tertiary</button>
  <button mat-raised-button color="warn">Warn</button>
</div>

https://i.sstatic.net/XIZMpsHc.png

The main issues I encountered were:

  1. Primary and tertiary colors appear to be the same (possibly not from my own theme) - how can I change this?
  2. How can I modify the background of these buttons?
  3. Is there a way to adjust the 'accent' color?

Appreciate any help or insights on this matter.

Answer №1

In reference to a recent github discussion:

The use of the color input has been phased out in M3. Instead, users are encouraged to create their own themes for different variations. For more information, visit material.angular.io/guide/theming#using-component-color-variants

Referring to the updated material 18 documentation:

Although it is recommended to apply mixins with explicit color variants, if transitioning from M2 to M3, you can also utilize provided backward compatibility mixins that directly style existing CSS classes (such as mat-primary, mat-accent, and mat-warn).

In response to your query:

The color input predominantly originates from M2, which lacks a tertiary color option. By including

@include mat.color-variants-backwards-compatibility(my-custom-theme.$light-theme);
, the "tertiary" variant will no longer be accessible.

To incorporate it, you can modify your global style.scss file like this:

.tertiary-button{
  @include mat.button-color(my-custom-theme.$light-theme, $color-variant: tertiary);
}

and utilize it within your template:

<button mat-raised-button class="tertiary-color">Tertiary</button>

However, note that the color might align with the accent shade since M3 treats the tertiary color as the legacy mode's accent hue. Consider defining the secondary color instead.

To customize the background-color, override the default background with your preferred color, such as:

.tertiary-button{
  @include mat.button-color(my-custom-theme.$light-theme, $color-variant: tertiary);
  background-color: red !important;
}

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

How can I delete a hyperlink on a number from my iPhone or iPad?

Is there a way to prevent certain sets of numbers from being linked, like phone numbers do on iPhones? <h2>Table</h2> <table class="table table-sm table-striped table-hover"> <caption class="sr-only">Search Results</caption> ...

Modify the value of the <select> tag based on whether it is required or not

When utilizing a my-select.component within a form component, the following code snippet is used: <div *ngIf="items?.length"> <select [ngModel]="selectedItem" (ngModelChange)="valueChanged($event)"> <optio ...

Replacing the left styling using CSS

Struggling to adjust the position of a side panel that pops up when hovering over an option. This is the code I found in Chrome Developer Tools: <nav id= "side_nav" class= "sidebar-bg-color header-side-nav-scroll-show"> <ul ...

Troubleshooting problem with resizing the sidebar in Bootstrap's responsive

I'm facing an issue with my responsive sidebar. I want the sidebar to maintain its size when resizing the window, but still collapse when the screen becomes too small. I attempted setting a min-width, however, it only made things worse. The jsfiddle ...

Retrieve the predetermined value from the dropdown menu option

I currently have two classes with a mapping structure as follows: User *--------------------1 Sexe Users are listed in the file list-users.component.html. When selecting a user for modification, I am redirected to the modify-user.component.html B ...

Guide to incorporating Jquery-Comment into Angular versions 2 and beyond

I've incorporated the Jquery-Comment plugin into my Angular 2 project by adding the necessary script and css files to my Index.html page. However, when initializing the Comment TextBox id within a script tag, I encountered an error in the console. ...

Choosing a CSS selector for a class that does not have a specific ID

Looking for a way to select all elements with the class .tab-pane except for those with the id #home. I attempted using .tab-pane:not#home{...}, but it proved unsuccessful. Any ideas on how to achieve this? Sample HTML <div id="home" class="tab-pan ...

Can you explain the distinction between the navigate function and routerLink feature in Angular 2?

As I go through the official Angular 2 tutorial, I noticed that it demonstrates using the navigate function in a way similar to routerLink. Can you explain the differences between these two methods and when it is best to use each? this.router.navigate([ ...

Move information from one page to another

I'm currently using Ionic 2 and attempting to pass data from one page to another. Specifically, I want to transfer the data of a selected list item from the first page (quickSearch) to the second page (quickSearchDetail). To illustrate this, refer to ...

I cannot seem to alter the background color of my image through the use of external CSS

body { background-color: #f6f7d4; } h1, h3, hr { color: #68b8ab; } hr { width: 100px; border-style: dotted none none; border-color: gray; border-width: 5px; } img { background-color: black; } Although the external CSS code a ...

What could be causing the malfunction of my button's event handlers?

Users can fill out a form in which they provide information about a grocery item they want to add to their cart. After completing the form, they can click on the "Add Item" button. Here's the form in my app.component.html: <form (ngSubmit)="a ...

What causes the presence of a boundary around the svg?

I have been encountering an issue while attempting to incorporate my logo into the header of my webpage. Specifically, when viewed on smaller screens, I noticed that there is a margin surrounding the SVG image. Below is my HTML file: <html lang="e ...

Guide on how to showcase the template by leveraging the roomList information with ngTemplateOutlet in Angular

TS roomList = [{ name: 'Room2' }] HTML <div class="Layout-body"> <ng-container *ngFor="let dt of roomList; index as i" [ngTemplateOutlet]="Room1" [ngTemplateOutletContext]="{ data: dt, i: i }&qu ...

Select either one checkbox out of two available options

My form includes two checkboxes, allowing users to click on both of them. I'm wondering if it's possible to set it up so that only one checkbox can be selected at a time. For example, clicking on the first checkbox would turn it on while turning ...

SVG Filter: The image is not completely covered by a width and height of 100%

Here's a basic SVG Filter. Click the example below to toggle the appearance of the filter: var image = document.querySelector('image'); var url = 'https://i.picsum.photos/id/202/2 ...

Working with CSS3 transitions in PHPStorm is a breeze

For some reason, my phpstorm does not provide code completion for CSS properties like -webkit-translate, translate, or animation. Has anyone encountered this issue before? Any suggestions on how to fix it? ...

Fixing malfunctioning bootstrap dropdown menus in a few simple steps

For a while, I have been using the bootstrap dropdown code as a template and it was working perfectly fine. However, after ensuring everything is up to date, all my dropdowns have suddenly stopped working. Even when I tried pasting the bootstrap code dire ...

What is the best way to implement iscroll4 in an iPad2 using CSS?

<html> <head> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/iscroll.js"></script> <script type="text/javascript" src="js/jquery-ui.min.js"></script> ...

- Aligning list items using UL bullet style

I'm having trouble aligning my ul dropdown with the rest of my menu. Even after removing the Bullet from my ul dropdown, it still maintains its position (I expected it to move all the way to the left side of the page). I've attempted various st ...

What is the best way to adjust the YouTube player to fit the width of the page while maintaining its aspect ratio?

I would like to feature a YouTube video on my website. My goal is to resize the video to fit a percentage of the user's browser while maintaining the aspect ratio. Here is what I have attempted so far: <iframe width="87%" height="315" src="http: ...