How to create a custom color theme with angular5 and angular materials

I followed the angular / material documentation on how to create a custom theme, follow other blogs, and check for various stack overflow problems, but this does not seem to work. I have the following styles.css, angular-cli.json, theme.scss and another sass file in which the colors of my theme come from super-styles.sass.

styles.css

...
@import 'assets/styles/theme.scss';
...

angular-cli.json

...
"styles": [
   "styles.css",
    "src/assets/styles/theme.scss"
],
...

theme.scss

@import '~@angular/material/theming';
@import "super-styles";

// 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.
$candy-app-primary: mat-palette($darkblue, A400);
$candy-app-accent:  mat-palette($orange, A400);

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

// Create the theme object (a Sass map containing all of the palettes).
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $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);

Super-styles.sass

...
$darkblue: #7faedd
$mediumblue: #85ceef
$lightblue: #c5e8f1
$yellow: #f4ef5f
$alert: #f37652
$orange: #fbb03c
...

According to the tutorials, I feel this should work, but angular does not compile, and I get an error.

. / node_modules/css-loader?{ "sourceMap":false, "importLoaders":1}!./node_modules/postcss-loader?{ "ident": "postcss" }!./src/assets//theme.scss : (23: 1)

21 | $candy-app-theme: mat-light-theme ($ candy-app-primary, $candy-app-accent, $candy-app-warn); 22 |

23 |// , .        | ^ 24 |// @ mixins 25 |//, .

, angular, . !

+14
2

Angular - , , , . 3 (, , ), , :

// below defines your custom color to build a theme palette from
$my-blue: (
  50: #7fdddd,
  100: #7faedd,
  200: #7f7fdd,
  300: #7faedd,
  400: #7faedd,
  500: #7faedd,
  600: #7faedd,
  700: #7faedd,
  800: #7faedd,
  900: #7faedd,
  A100: #7faedd,
  A200: #7faedd,
  A400: #7faedd,
  A700: #7faedd,
  contrast: (
    50: white,
    100: white,
    200: white,
    300: white,
    400: white,
    500: white,
    600: white,
    700: white,
    800: white,
    900: white,
    A100: white,
    A200: white,
    A400: white,
    A700: white,
  )
);
// below creates a primary palette with three shades of blue
$my-primary: mat-palette($my-blue, 100, 50, 200);
+33

. , , , . , .

$custom-collection: (
    warning :  #FFC116,
    success :  #0a630f,
    danger:    #c00000,
    contrast: (
        warning :  #000000,
        success :  #FFFFFF,
        danger:    #FFFFFF,
    )
);

$my-app-custom: mat-palette($custom-collection, custom);

mat- ,

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

, .

$custom: map-get($my-app-theme, custom);

,

background-color: mat-color($custom, validation-invalid);
color: mat-color($custom, validation-invalid-contrast);

. mat- success

.mat-success {
  background-color: mat-color($custom, success);
  color: mat-color($custom, success-contrast);
}

, .

<button mat-flat-button color="success" >Success</button>

, mat- * -class , * - . , color = "foo" class= "mat- foo" .

0

Source: https://habr.com/ru/post/1689861/


All Articles