使用主题的角材料文本颜色

时间:2018-04-16 00:25:27

标签: css angular sass themes angular-material2

我使用带有主色和强调色的角度材质主题。我有两个不同的主题定义橙色和绿色,最终用户可以动态更改。 theme.scss看起来如下

@import '~@angular/material/theming';

@include mat-core();

@mixin widget-theme($theme) {
    $primary: map-get($theme, primary);
    $accent: map-get($theme, accent);

    .fa-icon {
      color: mat-color($primary);
    }

    .fa-table-data-row-selected {
        background-color: mat-color($accent) !important;
        color: #152A23
    }

    .fa-text-link {
        color: #2A5D9F;
    }
  }



$custom-primary: mat-palette($mat-blue-grey,500);
$custom-accent:  mat-palette($mat-light-blue, A200);
$custom-warn:    mat-palette($mat-red);
$custom-theme: mat-light-theme($custom-primary, $custom-accent, $custom-warn);

@include angular-material-theme($custom-theme);
@include widget-theme($custom-theme);

//Orange theme
$ora-primary: mat-palette($mat-orange, 800);
$ora-accent:  mat-palette($mat-deep-purple, A100);
$ora-theme: mat-light-theme($ora-primary, $ora-accent);

.orange-theme {
    @include angular-material-theme($ora-theme);
    @include widget-theme($ora-theme);
}

//green theme
$green-primary: mat-palette($mat-green, 800);
$green-accent:  mat-palette($mat-lime, A700);
$green-theme: mat-light-theme($green-primary, $green-accent);

.green-theme {
    @include angular-material-theme($green-theme);
    @include widget-theme($green-theme);
}

我的整体配色方案使用主色和强调色很棒。但是,请注意我有一个表的用例,并使用强调颜色和css fa-table-data-row-selected使用选定的行颜色。所选行的文本颜色当前是硬编码的。显然这不适用于所有强调色,并且可能看起来绝对不可读。因此,这也应该根据所挑选的主题动态地改变。

这里有什么建议?我无法清楚地使用主色或强调色,因为这可能看起来不是最好的。它可能需要是一些其他变量,可以根据所挑选的主题来赋值。

1 个答案:

答案 0 :(得分:8)

使用调色板颜色的'对比色':

color: mat-contrast($accent, default);

与以下内容相同:

color: mat-color($accent, default-contrast);

了解theming内部结构可能非常有用。