Change Angular 9 material design color scheme

Asked

Viewed 1,133 times

1

I added the material design package, ng add @angular/material, to my project and selected Deep Purple/Amber. I want to change the color palette of my project, but I couldn’t find how to generate CSS on the site https://material.io/resources/color/

Project colors are in CSS and not defined in some external SCSS.

Do you know where I can generate a new CSS? or Change via NPM?

inserir a descrição da imagem aqui

  • Do you want to create your own theme or use another pre-existing one? Like Indigo-pink, pink-bluegrey, Purple-green.css.

  • 1

    I want to use a theme with different color of the predefined themes

2 answers

1

In the archive src/style.css, add:

@import '@angular/material/prebuilt-themes/NOME_DO_TEMA';

Available topics.

  • deeppurple-Amber.css
  • Indigo-pink.css
  • pink-bluegrey.css
  • Purple-green.css

Source: Using a pre-built theme

1


You should implement changing the.scss style as below:

@import '~@angular/material/theming';
// Plus imports for other components in your app.

// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// Be sure that you only ever include this mixin once!
@include mat-core();

// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
// hue. Available color palettes: https://material.io/design/color/
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent:  mat-palette($mat-pink, A200, A100, A400);

// The warn palette is optional (defaults to red).
$candy-app-warn:    mat-palette($mat-red);

// Create the theme object. A theme consists of configurations for individual
// theming systems such as `color` or `typography`.
$candy-app-theme: mat-light-theme((
  color: (
    primary: $candy-app-primary,
    accent: $candy-app-accent,
    warn: $candy-app-warn,  
  )
));

// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.
@include angular-material-theme($candy-app-theme);

Source: Theming your Angular Material app

If you prefer a Dark theme, you should change the corresponding line to the code below:

// Create the theme object. A theme consists of configurations for individual
// theming systems such as `color` or `typography`.
$candy-app-theme: mat-dark-theme((
  color: (
    primary: $candy-app-primary,
    accent: $candy-app-accent,
    warn: $candy-app-warn,  
  )
));

The colors available are: $mat-red, $mat-pink, $mat-purple, $mat-deep-purple, $mat-indigo, $mat-blue, $mat-light-blue, $mat-cyan, $mat-teal, $mat-green, $mat-light-green, $mat-lime, $mat-yellow, $mat-amber, $mat-orange, $mat-deep-orange, $mat-brown, $mat-grey, $mat-blue-grey.

But let’s say you want a color that is not in the above color list, in this case refer to the site Material Design Palette Generator, a name to your palette, adjust to the desired color, and review the contrast colors to look good, and click on the clipboard to see the code, choose Angular JS 2 (Material 2) and there, copy and paste in style.scss and use in the construction of the theme.

As you created your project using a standard theme, you may need to change the angular.json to point to style.scss, would be at the point below:

projects/[SEU_APP]/architect/build/options/styles

View documentation here

One last tip, take a look at the Schematics project I’m developing:

angular-mat-Baum

I hope you like!

Hugs,
Bernardo Baumblatt

  • Nice project.. Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.