Skip to content

Commit 8c53470

Browse files
committed
feat(icon): add input for inline styling of icons
1 parent 73bc948 commit 8c53470

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/demo-app/icon/icon-demo.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@
3232
Custom icon font and CSS:
3333
<mat-icon fontSet="fontawesome" fontIcon="fa-birthday-cake"></mat-icon>
3434
</p>
35+
36+
<p>
37+
Inline styling <mat-icon inline="true">favorite</mat-icon> icons appear as
38+
the same <mat-icon inline="true">directions_car</mat-icon>size as text around them.</p>
3539
</div>

src/lib/icon/icon.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ $mat-icon-size: 24px !default;
1010
fill: currentColor;
1111
height: $mat-icon-size;
1212
width: $mat-icon-size;
13+
14+
&.mat-icon-inline {
15+
font-size: inherit;
16+
height: inherit;
17+
line-height: inherit;
18+
width: inherit;
19+
}
1320
}
1421

1522
.mat-form-field:not(.mat-form-field-appearance-legacy) {

src/lib/icon/icon.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ViewEncapsulation,
2020
} from '@angular/core';
2121
import {CanColor, mixinColor} from '@angular/material/core';
22+
import {coerceBooleanProperty} from '@angular/cdk/coercion';
2223
import {MatIconRegistry} from './icon-registry';
2324

2425

@@ -67,13 +68,25 @@ export const _MatIconMixinBase = mixinColor(MatIconBase);
6768
host: {
6869
'role': 'img',
6970
'class': 'mat-icon',
71+
'[class.mat-icon-inline]': 'inline',
7072
},
7173
encapsulation: ViewEncapsulation.None,
7274
preserveWhitespaces: false,
7375
changeDetection: ChangeDetectionStrategy.OnPush,
7476
})
7577
export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, CanColor {
7678

79+
/** Whether the icon should be inline. */
80+
@Input()
81+
get inline(): boolean {
82+
return this._inline;
83+
}
84+
set inline(inline: boolean) {
85+
this._inline = coerceBooleanProperty(inline);
86+
}
87+
private _inline: boolean = false;
88+
89+
7790
/** Name of the icon in the SVG icon set. */
7891
@Input() svgIcon: string;
7992

0 commit comments

Comments
 (0)