Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material custom theming - why does mat-palette take 4 variables?

I'm currently learning how to create my own Angular Material 2 theme using the documentation (https://github.com/angular/material2/blob/master/guides/theming.md)

It seems the main bit is to just specify the colors here

// 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.
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent:  mat-palette($mat-pink, A200, A100, A400);

I do not quite understand what the mat-palette does. I understand the first parameter which specifies the color - I do not understand why there is a default, lighter and darker color.

I thought these colors are to be displayed when you've got code like this

<md-toolbar color="primary">
text
</md-toolbar>

In that case, the toolbar should be in the primary color. I can't see anywhere that specifies I can make it darker or lighter too. So what are the default, lighter and darker colors that are used for?

like image 528
Diskdrive Avatar asked Apr 05 '17 14:04

Diskdrive


People also ask

What is Mat palette?

A material palette consist of a range of colors with different contrast. They use a number system as a key for which color to use. The 500 is the default color. There are material components that use the default as their color. background-color: mat-color($palette); color: mat-color($palette, default-contrast);

What does a Theam consist of in angular 10 material?

A theme is a set of colors that will be applied to the Angular Material components. To be more specific, a theme is a composition of color palettes. That's right, not just a single color palette, multiple color palettes.

What is theming in angular?

Angular Material's theming system lets you customize color and typography styles for components in your application. The theming system is based on Google's Material Design specification. This document describes the concepts and APIs for customizing colors. For typography customization, see Angular Material Typography.

How do I change the mat toolbar color in angular materials?

The color of a <mat-toolbar> can be changed by using the color property. By default, toolbars use a neutral background color based on the current theme (light or dark). This can be changed to 'primary' , 'accent' , or 'warn' .


2 Answers

Looking at _theming.scss you have the mat-palette definition :

// Creates a map of hues to colors for a theme. This is used to define a theme palette in terms
// of the Material Design hues.
// @param $color-map
// @param $primary
// @param $lighter
@function mat-palette($base-palette, $default: 500, $lighter: 100, $darker: 700)

Use https://material.io/tools/color to get the color names and the paramter values.

In your theme.scss file you have defined your theme with :

$my-app-theme: mat-light-theme($my-app-primary, $my-app-accent, $my-app-warn);

@include angular-material-theme($my-app-theme);

Change mat-light-theme into mat-dark-theme and your theme will use the darker values of your palette.

like image 137
Vincent GODIN Avatar answered Sep 18 '22 10:09

Vincent GODIN


A material palette consist of a range of colors with different contrast. They use a number system as a key for which color to use. The 500 is the default color.

There are material components that use the default as their color.

background-color: mat-color($palette); color: mat-color($palette, default-contrast);

This would assign the 500 color and the contrast text to go with it.

When you're creating the palette you can change the default from 500 to A200 by changing the second value.

$candy-app-accent: mat-palette($mat-pink, A200);

You can check out one of my demo's to see a custom component and custom palette in action https://angular-material-waterlooblue.stackblitz.io

like image 30
devrocket Avatar answered Sep 18 '22 10:09

devrocket