Jem*_*Jem 3 sass angular-material angular
使用Angular 2 (4) + Material,我需要自定义一个组件的主题。我首先尝试使用内置调色板,但不断收到“错误:未定义”。仅当 map-get 传递“primary”、“accent”或“warn”作为第二个参数时才有效:
样式.scss
@import '~@angular/material/theming';
@include mat-core();
@import 'app/app.component.scss-theme';
$default-theme-primary: mat-palette($mat-light-green);
$default-theme-accent: mat-palette($mat-indigo);
$default-theme-warn: mat-palette($mat-red);
$default-theme: mat-light-theme($default-theme-primary, $default-theme-accent, $default-theme-warn);
@include angular-material-theme($default-theme);
@include app-component-theme($default-theme);
Run Code Online (Sandbox Code Playgroud)
app.component.scss-theme.scss
@import '~@angular/material/theming';
@mixin app-component-theme($theme){
$primary: map-get($theme, primary);
$accent: map-get($theme, accent);
$text: map-get($theme, text);
$card: map-get($theme, card);
$lighter: map-get($theme, lighter);
$darker: map-get($theme, darker);
.test{
font-size: 5em;
color: mat-color($primary)!important; // works
// color: mat-color($darker)!important; // fails
// color: mat-color($lighter)!important; // fails
// color: mat-color($text)!important; // fails
// color: mat-color($card)!important; // fails
}
}
Run Code Online (Sandbox Code Playgroud)
我依靠以下帖子/网址找到了第二个参数接受的可能值的方法,但可以找出问题所在。
好的,发现我的错误:
$text: map-get($theme, text);
$card: map-get($theme, card);
$lighter: map-get($theme, lighter);
$darker: map-get($theme, darker);
.test{
font-size: 5em;
color: mat-color($darker)!important; // fails because $darker isn't called on foreground
}
Run Code Online (Sandbox Code Playgroud)
解决方案:文本、卡片等存在于“$foreground”和“$background”地图上:
@mixin app-component-theme($theme){
$primary: map-get($theme, primary);
$accent: map-get($theme, accent);
$foreground: map-get($theme, foreground);
$background: map-get($theme, background);
$text: map-get($foreground, text);
$card: map-get($background, card);
.crap{
font-size: 5em;
color: $text;
background-color: $card;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4059 次 |
| 最近记录: |