From 3da932e206e50094259cff2e26c63435ba2258a0 Mon Sep 17 00:00:00 2001 From: katebatura Date: Fri, 29 Oct 2021 15:24:24 +0300 Subject: [PATCH 1/4] feat(nb window): provide a template to window title --- .../components/window/window.component.ts | 18 +++++++++++++++++- .../theme/components/window/window.options.ts | 11 +++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/framework/theme/components/window/window.component.ts b/src/framework/theme/components/window/window.component.ts index a14fc2c385..de0b931fa6 100644 --- a/src/framework/theme/components/window/window.component.ts +++ b/src/framework/theme/components/window/window.component.ts @@ -12,7 +12,9 @@ import { ComponentFactoryResolver, Input, AfterViewChecked, + ViewContainerRef, } from '@angular/core'; +import { TemplatePortal } from '@angular/cdk/portal'; import { NbFocusTrap, NbFocusTrapFactoryService } from '../cdk/a11y/focus-trap'; import { NbComponentPortal, NbComponentType, NbTemplatePortal } from '../cdk/overlay/mapping'; import { NbOverlayContainerComponent } from '../cdk/overlay/overlay-container'; @@ -24,7 +26,10 @@ import { NbWindowRef } from './window-ref'; template: ` -
{{ config.title }}
+ + + +
{{ config.title }}
@@ -91,6 +96,8 @@ export class NbWindowComponent implements OnInit, AfterViewChecked, OnDestroy { protected focusTrap: NbFocusTrap; + titleTemplatePortal: TemplatePortal | undefined; + constructor( @Inject(NB_WINDOW_CONTENT) public content: TemplateRef | NbComponentType, @Inject(NB_WINDOW_CONTEXT) public context: Object, @@ -99,6 +106,7 @@ export class NbWindowComponent implements OnInit, AfterViewChecked, OnDestroy { protected focusTrapFactory: NbFocusTrapFactoryService, protected elementRef: ElementRef, protected renderer: Renderer2, + protected viewContainerRef: ViewContainerRef, ) {} ngOnInit() { @@ -109,6 +117,14 @@ export class NbWindowComponent implements OnInit, AfterViewChecked, OnDestroy { if (this.config.windowClass) { this.renderer.addClass(this.elementRef.nativeElement, this.config.windowClass); } + + if (this.config.titleTemplate instanceof TemplateRef) { + this.titleTemplatePortal = new TemplatePortal( + this.config.titleTemplate, + this.viewContainerRef, + { $implicit: this.config.titleTemplateContext }, + ); + } } ngAfterViewChecked() { diff --git a/src/framework/theme/components/window/window.options.ts b/src/framework/theme/components/window/window.options.ts index 16f46e9b4d..004efb2941 100644 --- a/src/framework/theme/components/window/window.options.ts +++ b/src/framework/theme/components/window/window.options.ts @@ -36,6 +36,17 @@ export class NbWindowConfig { */ title: string = ''; + /** + * Window title as template. Use it instead of `title` property. + */ + titleTemplate?: TemplateRef; + + /** + * Title as template may receive data through `config.titleTemplateContext` property. + * Window title as Template. You can access context inside template as $implicit. + */ + titleTemplateContext?: Object = {}; + /** * Initial window state. Full screen by default. */ From 3b40dc5d25cc7727bc35dd78284ff25a9cca1e5f Mon Sep 17 00:00:00 2001 From: katebatura Date: Fri, 29 Oct 2021 18:39:08 +0300 Subject: [PATCH 2/4] feat(window): provide a template to window title --- .../theme/components/window/window.component.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/framework/theme/components/window/window.component.ts b/src/framework/theme/components/window/window.component.ts index de0b931fa6..e7a057d3d4 100644 --- a/src/framework/theme/components/window/window.component.ts +++ b/src/framework/theme/components/window/window.component.ts @@ -26,10 +26,13 @@ import { NbWindowRef } from './window-ref'; template: ` - - - -
{{ config.title }}
+
+ +
+ + +
{{ config.title }}
+
From 06e3bc55f703d7e85d649ac8aad15d736718e154 Mon Sep 17 00:00:00 2001 From: katebatura Date: Sat, 30 Oct 2021 11:20:19 +0300 Subject: [PATCH 3/4] feat(window): provide a template to window title --- .../theme/components/window/window.component.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/framework/theme/components/window/window.component.ts b/src/framework/theme/components/window/window.component.ts index e7a057d3d4..50f8970cec 100644 --- a/src/framework/theme/components/window/window.component.ts +++ b/src/framework/theme/components/window/window.component.ts @@ -26,12 +26,12 @@ import { NbWindowRef } from './window-ref'; template: ` -
+
-
{{ config.title }}
+
{{ config.title }}
@@ -120,14 +120,6 @@ export class NbWindowComponent implements OnInit, AfterViewChecked, OnDestroy { if (this.config.windowClass) { this.renderer.addClass(this.elementRef.nativeElement, this.config.windowClass); } - - if (this.config.titleTemplate instanceof TemplateRef) { - this.titleTemplatePortal = new TemplatePortal( - this.config.titleTemplate, - this.viewContainerRef, - { $implicit: this.config.titleTemplateContext }, - ); - } } ngAfterViewChecked() { From 8272ca229940b0f12258edda7f6770dee455771a Mon Sep 17 00:00:00 2001 From: Sergey Andrievskiy Date: Sun, 31 Oct 2021 15:57:14 +0300 Subject: [PATCH 4/4] refactor(window): remove redundant property --- src/framework/theme/components/window/window.component.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/framework/theme/components/window/window.component.ts b/src/framework/theme/components/window/window.component.ts index 50f8970cec..3198f98b09 100644 --- a/src/framework/theme/components/window/window.component.ts +++ b/src/framework/theme/components/window/window.component.ts @@ -12,9 +12,7 @@ import { ComponentFactoryResolver, Input, AfterViewChecked, - ViewContainerRef, } from '@angular/core'; -import { TemplatePortal } from '@angular/cdk/portal'; import { NbFocusTrap, NbFocusTrapFactoryService } from '../cdk/a11y/focus-trap'; import { NbComponentPortal, NbComponentType, NbTemplatePortal } from '../cdk/overlay/mapping'; import { NbOverlayContainerComponent } from '../cdk/overlay/overlay-container'; @@ -26,7 +24,7 @@ import { NbWindowRef } from './window-ref'; template: ` -
+
@@ -99,8 +97,6 @@ export class NbWindowComponent implements OnInit, AfterViewChecked, OnDestroy { protected focusTrap: NbFocusTrap; - titleTemplatePortal: TemplatePortal | undefined; - constructor( @Inject(NB_WINDOW_CONTENT) public content: TemplateRef | NbComponentType, @Inject(NB_WINDOW_CONTEXT) public context: Object, @@ -109,7 +105,6 @@ export class NbWindowComponent implements OnInit, AfterViewChecked, OnDestroy { protected focusTrapFactory: NbFocusTrapFactoryService, protected elementRef: ElementRef, protected renderer: Renderer2, - protected viewContainerRef: ViewContainerRef, ) {} ngOnInit() {