From 93307d0afb9d9fb1aeb616df3d02e3280b5515cb Mon Sep 17 00:00:00 2001 From: efux Date: Mon, 30 Sep 2019 11:15:56 +0200 Subject: [PATCH] fix(business): add icon content child to button component and template (#188) --- .../button/src/button/button.component.html | 6 +++++ .../button/src/button/button.component.ts | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/projects/sbb-esta/angular-business/button/src/button/button.component.html b/projects/sbb-esta/angular-business/button/src/button/button.component.html index 6dbc743063..6524e1ec95 100644 --- a/projects/sbb-esta/angular-business/button/src/button/button.component.html +++ b/projects/sbb-esta/angular-business/button/src/button/button.component.html @@ -1 +1,7 @@ + + + + + + diff --git a/projects/sbb-esta/angular-business/button/src/button/button.component.ts b/projects/sbb-esta/angular-business/button/src/button/button.component.ts index a7879d3c8e..cbb3fc500a 100644 --- a/projects/sbb-esta/angular-business/button/src/button/button.component.ts +++ b/projects/sbb-esta/angular-business/button/src/button/button.component.ts @@ -1,11 +1,14 @@ import { ChangeDetectionStrategy, Component, + ContentChild, HostBinding, Input, + TemplateRef, ViewEncapsulation } from '@angular/core'; import { BaseButton } from '@sbb-esta/angular-core/base'; +import { IconDirective } from '@sbb-esta/angular-core/icon-directive'; @Component({ // tslint:disable-next-line:component-selector @@ -21,6 +24,28 @@ export class ButtonComponent extends BaseButton { */ @Input() mode: 'primary' | 'secondary' | 'ghost' | 'alternative' | 'icon' = 'primary'; + /** + * Template that will contain icons. + * Use the *sbbIcon structural directive to provide the desired icon. + */ + @Input() + get icon(): TemplateRef { + return this._contentIcon || this._icon; + } + set icon(icon: TemplateRef) { + this._icon = icon; + } + private _icon: TemplateRef; + + /** @docs-private */ + @HostBinding('class.sbb-button-has-icon') get buttonHasIconClass() { + return !!this.icon; + } + + /** @docs-private */ + @ContentChild(IconDirective, { read: TemplateRef, static: false }) + _contentIcon: TemplateRef; + /** @docs-private */ @HostBinding('class.sbb-button-alternative') get _alternativeClass() {