Ste*_*ieB 9 angular-material angular-material2 angular
所以在Angular Material 2中,我设置了主题
$store-primary: mat-palette($mat-storecast);
$store-accent: mat-palette($mat-pink, A200, A100, A400);
// The warn palette is optional (defaults to red).
$store-warn: mat-palette($mat-red);
// Create the theme object (a Sass map containing all of the palettes).
$store-theme: mat-light-theme($store-primary, $store-accent, $store-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($store-theme);
Run Code Online (Sandbox Code Playgroud)
我从他们的文档中无法弄清楚的是如何从主调色板上获得不同的色调颜色,即按钮上的工具栏.
<button md-mini-fab (click)="zoomIn()" color="primary">
<md-icon>add</md-icon>
</button>
Run Code Online (Sandbox Code Playgroud)
它似乎只能理解color = primary或color = accent等.你指定我想要使用primary-100还是primary-500等?
小智 6
官方的回答是,目前这是不可能的。color大多数组件上可用的属性只接受调色板类型 - 即主要、重音或警告。
如果您真的想这样做,非官方的答案是,如果您不介意滥用内部 API,则可以(在逐个组件的基础上)。例如,要在按钮上获得 A100 颜色,您可以向主题添加自定义混合。
// custom-button-theme.scss
@import '~@angular/material/core/theming/all-theme';
@import '~@angular/material/button/_button-theme';
@mixin custom-button-theme($theme) {
.mat-raised-button.a100, .mat-fab.a100, .mat-mini-fab.a100 {
// _mat-button-theme-color is a mixin defined in _button-theme.scss
// which applies the given property, in this case background-color
// for each of the palettes - i.e. primary, accent and warn.
// The last parameter is the hue colour to apply.
@include _mat-button-theme-color($theme, 'background-color', 'A100');
}
}
Run Code Online (Sandbox Code Playgroud)
然后在您的主主题文件中导入自定义 mixin。
@import 'custom-button-theme.scss';
@include custom-button-theme($store-theme);
Run Code Online (Sandbox Code Playgroud)
然后您的按钮可以通过添加a100类来使用颜色。
<button md-mini-fab (click)="zoomIn()" color="primary" class="a100">
<md-icon>add</md-icon>
</button>
Run Code Online (Sandbox Code Playgroud)
然而,重要的是要注意内部 API 可以随时更改。此代码已使用 2.0.0-beta.2 版进行测试 - 无法保证它在发布时适用于 beta 3。
| 归档时间: |
|
| 查看次数: |
2099 次 |
| 最近记录: |