1

Is it possible to create a theme in angular material with your own hex codes?

instead of something like this

$my-theme-primary: mat-palette($mat-blue, 800);
$my-theme-accent: mat-palette($mat-orange);
$my-theme-warn: mat-palette($mat-red);
$my-theme: mat-light-theme($my-theme-primary, $my-theme-accent, $my-theme-warn);

do something like this

$my-theme-primary: #1565C0;
$my-theme-accent: #f4b942;
$my-theme-warn: mat-palette($mat-red);
$my-theme: mat-light-theme($my-theme-primary, $my-theme-accent, $my-theme-warn);

Basically I have users creating their own themes

bradley
  • 445
  • 1
  • 9
  • 17

2 Answers2

0

Yes - but not the way you've shown. 'Theme' objects are made up of 'palettes' created using the mat-palette function which returns a map of key-color pairs. You can use your own hex color values in the palette objects - that is the standard way to add a custom theme. See https://material.angular.io/guide/theming#defining-a-custom-theme.

G. Tranter
  • 16,766
  • 1
  • 48
  • 68
0
$mat-primarycolor: (
500: #1565C0
);
$mat-accentcolor: (
 500: #f4b942
);

$my-theme-primary: mat-palette($mat-primarycolor);
$my-theme-accent:  mat-palette($mat-accentcolor);
$my-theme-warn: mat-palette($mat-red);
$my-theme: mat-light-theme($my-theme-primary, $my-theme-accent, $my-theme-warn);

Please try this code. It helps

Jay
  • 135
  • 8