2017-02-22 32 views
6

所以在角料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); 

我无法从他们的文档弄清楚什么是如何获得不同色调的颜色从主调色板上即按钮上的工具栏上。

<button md-mini-fab (click)="zoomIn()" color="primary"> 
    <md-icon>add</md-icon> 
</button> 

现在看来似乎只能理解颜色=初级或颜色=口音etc..how你指定我想用初级-100或主-500等?

回答

1

官方答案目前这是不可能的。大多数组件上可用的color属性只接受调色板类型 - 即主要,重音或警告。

如果你真的想这样做的非官方答案是,如果你不介意滥用内部API,它是可能的(在逐个组件的基础上)。例如,要在按钮上获取A100颜色,可以将自定义混合添加到主题。

// custom-button-theme.scss 
@import '[email protected]/material/core/theming/all-theme'; 
@import '[email protected]/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'); 
    } 

} 

然后在您的主要主题文件中导入自定义混合。

@import 'custom-button-theme.scss'; 
@include custom-button-theme($store-theme); 

您的按钮可以通过添加a100类来使用颜色。

<button md-mini-fab (click)="zoomIn()" color="primary" class="a100"> 
    <md-icon>add</md-icon> 
</button> 

但需要注意的是,内部API可以随时更改。此代码已使用2.0.0-beta.2版进行了测试,但不能保证在出现此问题时它将与beta 3配合使用。

+0

好的,谢谢伊恩,我想这个会在不久的将来加入。 – StevieB

1

我用的角材1,我不知道,如果是同样的方式,但我做的是使用指令:md-colors="::{background: 'themename-primary-100'}"当然在themename你把主题名称:P

+0

我试着像color =“primary-100”,但由于某种原因它改变了重音主题。很奇怪 – StevieB

+0

你需要定义主题,在角度1它是这样做的:'$ mdThemingProvider.theme('themename') .primaryPalette('blue-grey') .accentPalette('lime') .warnPalette ('红'); $ mdThemingProvider.setDefaultTheme('themename');'然后你使用'md-colors =“:: {background:'themename-primary-100'}”' –

+0

如果它是正确的,请标记答案是正确的我将其全部编辑在答案字段中以便更易读。 –