Skip to content

Commit 93307d0

Browse files
efuxkyubisation
authored andcommitted
fix(business): add icon content child to button component and template (#188)
1 parent 1d7de22 commit 93307d0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
<span class="sbb-svgsprite-icon">
2+
<ng-container *ngTemplateOutlet="icon"></ng-container>
3+
</span>
14
<ng-content></ng-content>
5+
<span class="sbb-svgsprite-icon">
6+
<ng-container *ngTemplateOutlet="icon"></ng-container>
7+
</span>

projects/sbb-esta/angular-business/button/src/button/button.component.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import {
22
ChangeDetectionStrategy,
33
Component,
4+
ContentChild,
45
HostBinding,
56
Input,
7+
TemplateRef,
68
ViewEncapsulation
79
} from '@angular/core';
810
import { BaseButton } from '@sbb-esta/angular-core/base';
11+
import { IconDirective } from '@sbb-esta/angular-core/icon-directive';
912

1013
@Component({
1114
// tslint:disable-next-line:component-selector
@@ -21,6 +24,28 @@ export class ButtonComponent extends BaseButton {
2124
*/
2225
@Input() mode: 'primary' | 'secondary' | 'ghost' | 'alternative' | 'icon' = 'primary';
2326

27+
/**
28+
* Template that will contain icons.
29+
* Use the *sbbIcon structural directive to provide the desired icon.
30+
*/
31+
@Input()
32+
get icon(): TemplateRef<any> {
33+
return this._contentIcon || this._icon;
34+
}
35+
set icon(icon: TemplateRef<any>) {
36+
this._icon = icon;
37+
}
38+
private _icon: TemplateRef<any>;
39+
40+
/** @docs-private */
41+
@HostBinding('class.sbb-button-has-icon') get buttonHasIconClass() {
42+
return !!this.icon;
43+
}
44+
45+
/** @docs-private */
46+
@ContentChild(IconDirective, { read: TemplateRef, static: false })
47+
_contentIcon: TemplateRef<any>;
48+
2449
/** @docs-private */
2550
@HostBinding('class.sbb-button-alternative')
2651
get _alternativeClass() {

0 commit comments

Comments
 (0)