phe*_*lhe 3 material-design angular-material angular
在角材步进器组件中,每个步骤都由一个圆圈图标表示。此圆圈的背景色设置为主题的原色。是否可以将此颜色更改为主题的强调色?我尝试color="accent"在mat-horizontal-stepper组件和每个mat-step组件上都进行设置,但是都没有任何作用,并且在文档中看不到颜色输入。
当然,您可以使用自己的 CSS 并自定义背景和前景色。不需要::ng-deep。 (/deep/ 和 ::ng-deep 目前均已弃用)
通过几个 SCSS,我的步进器的外观如下:我添加了自定义标签和图标所需的 SASS 片段:
已完成的步骤及其标签:
.mat-step-header .mat-step-icon-state-done, .mat-step-header .mat-step-icon-state-edit {
background-color: transparent !important;
color: $success;
+.mat-step-label{
color: $success !important;
}
}
Run Code Online (Sandbox Code Playgroud)
进行中步骤及其标签:
.mat-step-header .mat-step-icon-selected{
// background-color: $primary;
background-color: transparent !important;
color: $primary;
+.mat-step-label{
color: $primary !important;
}
}
Run Code Online (Sandbox Code Playgroud)
待办事项/默认步骤及其标签:
.mat-step-header .mat-step-label{
color: rgba(0, 0, 0, .54)
}
.mat-step-header .mat-step-icon {
color: rgba(0, 0, 0, .54);
background-color: transparent;
}
Run Code Online (Sandbox Code Playgroud)
用于覆盖默认图标的 HTML: 我使用 font Awesome 图标来覆盖默认值:
<mat-horizontal-stepper>
<!-- Icon overrides. -->
<ng-template matStepperIcon="edit">
<i class="fa fa-check-circle"></i>
</ng-template>
<ng-template matStepperIcon="active">
<i class="fa fa-dot-circle-o"></i>
</ng-template>
<ng-template matStepperIcon="done">
<i class="fa fa-dot-circle-o"></i>
</ng-template>
<ng-template matStepperIcon="number">
<i class="fa fa-dot-circle-o"></i>
</ng-template>
</mat-horizontal-stepper>
Run Code Online (Sandbox Code Playgroud)
注意:所有 SCSS 都应位于全局样式表中,而不是组件特定的样式表中。如果样式存在于角度组件的文件内,由于视图封装,它将不会被应用。
如果需要,请在 SCSS 文件开头定义颜色变量,如下所示:将十六进制值替换为您的主题颜色。
$success: #35A255 !default;
$primary: #007CBB !default;
Run Code Online (Sandbox Code Playgroud)
似乎没有更改垫子步进器图标颜色的选项,您可以使用此CSS作为解决方法。
::ng-deep .mat-step-header .mat-step-icon-selected {
background-color: red;
}
Run Code Online (Sandbox Code Playgroud)
:: ng-deep已过时,可以删除,也可以使用
ViewEncapsulation.None在组件装饰器中避免使用:: ng-deep
更新问题解决方案
html文件示例
<div class="yellow-theme"> <----- wrapper theme class
<button mat-raised-button (click)="isLinear = !isLinear" id="toggle-
linear">
{{!isLinear ? 'Enable linear mode' : 'Disable linear mode'}}
</button>
<mat-horizontal-stepper [linear]="isLinear" #stepper>
<mat-step [stepControl]="firstFormGroup">
<form [formGroup]="firstFormGroup">
<ng-template matStepLabel>Fill out your name</ng-template>
<mat-form-field>
<input matInput placeholder="Last name, First name"
formControlName="firstCtrl" required>
</mat-form-field>
<div>
<button mat-button matStepperNext>Next</button>
</div>
</form>
</mat-step>
<mat-step [stepControl]="secondFormGroup">
<form [formGroup]="secondFormGroup">
<ng-template matStepLabel>Fill out your address</ng-template>
<mat-form-field>
<input matInput placeholder="Address" formControlName="secondCtrl" required>
</mat-form-field>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>
</div>
</form>
</mat-step>
<mat-step>
<ng-template matStepLabel>Done</ng-template>
You are now done.
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button (click)="stepper.reset()">Reset</button>
</div>
</mat-step>
</mat-horizontal-stepper>
Run Code Online (Sandbox Code Playgroud)
创建theme.scss文件并将其添加到angular.json中的样式
"styles": [
"src/styles.css",
"src/theme.scss"
]
Run Code Online (Sandbox Code Playgroud)
注意步进器将采用原色
theme.scss
@import '~@angular/material/theming';
@include mat-core();
.yellow-theme {
$yellow-theme-primary: mat-palette($mat-yellow, 400);
$yellow-theme-accent: mat-palette($mat-yellow, 400);
$yellow-theme: mat-light-theme($yellow-theme-primary, $yellow-theme-accent);
@include angular-material-theme($yellow-theme);
}
Run Code Online (Sandbox Code Playgroud)
自定义主题类可以在整个应用程序中使用,只需包装任何材料组件,并使用在类中定义的主,强调或警告颜色属性。包装在自定义类中的组件将使用该颜色,如果不是,则从全局主题设置颜色。
| 归档时间: |
|
| 查看次数: |
7642 次 |
| 最近记录: |