<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nephi Wright</title>
    <description>The latest articles on DEV Community by Nephi Wright (@nephiw).</description>
    <link>https://dev.to/nephiw</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F276298%2F60ba486a-3e87-44c9-8aa3-fd41993d6970.jpeg</url>
      <title>DEV Community: Nephi Wright</title>
      <link>https://dev.to/nephiw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nephiw"/>
    <language>en</language>
    <item>
      <title>Theming Material Design - Colors</title>
      <dc:creator>Nephi Wright</dc:creator>
      <pubDate>Tue, 26 Nov 2019 21:46:46 +0000</pubDate>
      <link>https://dev.to/nephiw/theming-material-design-mm3</link>
      <guid>https://dev.to/nephiw/theming-material-design-mm3</guid>
      <description>&lt;p&gt;Usually I find Googles documentation to be pretty good at describing the basics, however, when I started trying to edit the color scheme for a project built on Angular Material for the first time, &lt;a href="https://material.io/design/color/the-color-system.html"&gt;the documentation provided many details on why&lt;/a&gt; - &lt;a href="https://material.angular.io/guide/theming"&gt;but not enough in the way of how&lt;/a&gt;. This information is useful, but all I really needed to know at this point is how to make a color scheme work on my site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://material.angular.io"&gt;The Material Angular site&lt;/a&gt; had examples on theming here &lt;a href="https://material.angular.io/guide/theming"&gt;https://material.angular.io/guide/theming&lt;/a&gt; which provided what I thought was a good example of how to change the theme with scss:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;'~@angular/material/theming'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Plus imports for other components in your app.&lt;/span&gt;

&lt;span class="c1"&gt;// Include the common styles for Angular Material. We include this here so that you only&lt;/span&gt;
&lt;span class="c1"&gt;// have to load a single css file for Angular Material in your app.&lt;/span&gt;
&lt;span class="c1"&gt;// Be sure that you only ever include this mixin once!&lt;/span&gt;
&lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;mat-core&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

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

&lt;span class="c1"&gt;// The warn palette is optional (defaults to red).&lt;/span&gt;
&lt;span class="nv"&gt;$candy-app-warn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nf"&gt;mat-palette&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$mat-red&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Create the theme object (a Sass map containing all of the palettes).&lt;/span&gt;
&lt;span class="nv"&gt;$candy-app-theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;mat-light-theme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$candy-app-primary&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$candy-app-accent&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$candy-app-warn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Include theme styles for core and each component used in your app.&lt;/span&gt;
&lt;span class="c1"&gt;// Alternatively, you can import and @include the theme mixins for each component&lt;/span&gt;
&lt;span class="c1"&gt;// that you are using.&lt;/span&gt;
&lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;angular-material-theme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$candy-app-theme&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;I expected &lt;code&gt;$mat-indigo&lt;/code&gt; to be a single color from which the shades were generated. My expectations were wrong. The goal of the documentation appears to be to show you how to use one of the predefined themes. If you try providing a single color, like I did, you will get the error message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR in ./src/styles.scss (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!./node_modules/sass-loader/lib/loader.js??ref--15-3!./src/styles.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):

    default: map-get($base-palette, $default),
            ^
      $map: #4b0082 is not a map.
     ╷
1262 │     default: map-get($base-palette, $default),
     │              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     ╵
  node_modules/@angular/material/_theming.scss 1262:14  mat-palette()
  stdin 46:20                                           root stylesheet
      in /home/user/site/node_modules/@angular/material/_theming.scss (line 1262, column 14)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a bit cryptic, but it did lead me to the solution. &lt;em&gt;Drop the manual and read the source.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;This happens because the &lt;code&gt;mat-palette&lt;/code&gt; mixin requires a color map not a single color. I figured out how to build my own palette by reading the &lt;a href="https://github.com/angular/components/blob/8.2.3/src/material/core/theming/_theming.scss#L17"&gt;&lt;code&gt;_theming.scss&lt;/code&gt; source code&lt;/a&gt; and the default palette definitions in the &lt;a href="https://github.com/angular/components/blob/8.2.3/src/material/core/theming/_palette.scss#L171"&gt;_palette.scss source code&lt;/a&gt; but here is an example of the basic structure required for &lt;code&gt;mat-palette&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$mat-indigo: (
  50: #e8eaf6,
  100: #c5cae9,
  200: #9fa8da,
  300: #7986cb,
  400: #5c6bc0,
  500: #3f51b5,
  600: #3949ab,
  700: #303f9f,
  800: #283593,
  900: #1a237e,
  A100: #8c9eff,
  A200: #536dfe,
  A400: #3d5afe,
  A700: #304ffe,
  contrast: (
    50: $dark-primary-text,
    100: $dark-primary-text,
    200: $dark-primary-text,
    300: $light-primary-text,
    400: $light-primary-text,
    500: $light-primary-text,
    600: $light-primary-text,
    700: $light-primary-text,
    800: $light-primary-text,
    900: $light-primary-text,
    A100: $dark-primary-text,
    A200: $light-primary-text,
    A400: $light-primary-text,
    A700: $light-primary-text,
  )
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note also that Angular Material provides many existing palettes for you to use and what follows here gives an example of using a built in palette named &lt;code&gt;mat-blue-grey&lt;/code&gt; with another by creating the proper map. In the end the entire file for my theme looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import '~@angular/material/theming';
@include mat-core();

// this defines a map for an orange color palette
$bc-accent-palette: (
   50: #FFF3E0,
  100: #FFE0B2,
  200: #FFCC80,
  300: #FFB74D,
  400: #FFA726,
  500: #FF9800,
  600: #FB8C00,
  700: #F57C00,
  800: #EF6C00,
  900: #E65100,
 A100: #FFD180,
 A200: #FFAB40,
 A400: #FF9100,
 A700: #FF6D00,
  contrast: (
    50: $dark-primary-text,
    100: $dark-primary-text,
    200: $dark-primary-text,
    300: $dark-primary-text,
    400: $dark-primary-text,
    500: $light-primary-text,
    600: $light-primary-text,
    700: $light-primary-text,
    800: $light-primary-text,
    900: $light-primary-text,
    A100: $dark-primary-text,
    A200: $dark-primary-text,
    A400: $dark-primary-text,
    A700: $light-primary-text,
  )
);

// Build the theme palettes out of an existing palette and a custom one.
$bc-theme-primary: mat-palette($mat-blue-grey);
$bc-theme-accent:  mat-palette($bc-accent-palette, A200, A100, A400);

// Build the theme and include it in your styles.
$bc-theme: mat-light-theme($bc-theme-primary, $bc-theme-accent);
@include angular-material-theme($bc-theme);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this example, I simply used the color scheme defined for &lt;code&gt;mat-orange&lt;/code&gt; - but I am just getting started on this project; I expect to tweak it quite a bit as I move forward. Defining the colors in this way gives you more control to customize the entire site's theme moving forward. However, if you just want to generate a css to use instead, you might try exploring the &lt;a href="https://material.io/resources/color/#!/?view.left=0&amp;amp;view.right=0&amp;amp;primary.color=FF2828&amp;amp;secondary.color=ffdedd"&gt;resources Angular provides&lt;/a&gt;. This allows you to export your color scheme to apps and also &lt;a href="https://codepen.io/"&gt;CodePen&lt;/a&gt; to view the specifics.&lt;/p&gt;

</description>
      <category>material</category>
      <category>sass</category>
      <category>scss</category>
      <category>angular</category>
    </item>
  </channel>
</rss>
