From 9937ebadc19f9a95de1ffc04a6ec127de6321b03 Mon Sep 17 00:00:00 2001 From: Steven Ulmer Date: Thu, 26 Sep 2019 15:51:51 -0400 Subject: [PATCH] update branding color to be observable --- .../go-accordion-panel.component.html | 5 +++- .../go-accordion-panel.component.scss | 24 +++++++------------ .../go-accordion-panel.component.ts | 17 ++++++------- .../go-nav-item/go-nav-item.component.html | 5 +++- .../go-nav-item/go-nav-item.component.ts | 14 ++++++----- .../go-lib/src/lib/go-branding.service.ts | 9 +++---- projects/go-tester/src/app/app.component.ts | 4 ++-- 7 files changed, 36 insertions(+), 42 deletions(-) diff --git a/projects/go-lib/src/lib/components/go-accordion/go-accordion-panel.component.html b/projects/go-lib/src/lib/components/go-accordion/go-accordion-panel.component.html index 45e979631..dd0ae7494 100644 --- a/projects/go-lib/src/lib/components/go-accordion/go-accordion-panel.component.html +++ b/projects/go-lib/src/lib/components/go-accordion/go-accordion-panel.component.html @@ -2,7 +2,10 @@ class="go-accordion-panel" [ngClass]="containerClasses" > - +
= new EventEmitter(); - @ViewChild('goAccordionPanelSelected') selectedBinding: ElementRef; - constructor( private brandingService: GoBrandingService ) { } @@ -54,6 +52,10 @@ export class GoAccordionPanelComponent implements AfterContentInit, OnInit, OnCh ngOnInit(): void { // NOTE: `title` is deprecated and will be removed in later version this.heading = this.heading || this.title; + + this.brandingService.brandColor.subscribe((value: string) => { + this.brandColor = value; + }); } ngOnChanges(): void { @@ -75,9 +77,4 @@ export class GoAccordionPanelComponent implements AfterContentInit, OnInit, OnCh 'go-accordion-panel__header--slim': this.slim === true }; } - - ngAfterContentInit(): void { - this.selectedBinding.nativeElement.style.background = this.brandingService.brandColor; - } - } diff --git a/projects/go-lib/src/lib/components/go-side-nav/go-nav-item/go-nav-item.component.html b/projects/go-lib/src/lib/components/go-side-nav/go-nav-item/go-nav-item.component.html index 1781bf0e3..0afe03e98 100644 --- a/projects/go-lib/src/lib/components/go-side-nav/go-nav-item/go-nav-item.component.html +++ b/projects/go-lib/src/lib/components/go-side-nav/go-nav-item/go-nav-item.component.html @@ -4,7 +4,10 @@ [routerLinkActive]="['go-nav-item__link--active']" [routerLink]="[navItem.route]" [routerLinkActiveOptions]="{exact:true}"> - + diff --git a/projects/go-lib/src/lib/components/go-side-nav/go-nav-item/go-nav-item.component.ts b/projects/go-lib/src/lib/components/go-side-nav/go-nav-item/go-nav-item.component.ts index abfc0459c..4f01a06b7 100644 --- a/projects/go-lib/src/lib/components/go-side-nav/go-nav-item/go-nav-item.component.ts +++ b/projects/go-lib/src/lib/components/go-side-nav/go-nav-item/go-nav-item.component.ts @@ -1,4 +1,4 @@ -import { AfterContentInit, Component, ElementRef, Input, ViewChild } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { NavItem } from '../nav-item.model'; import { GoSideNavService } from '../go-side-nav/go-side-nav.service'; import { GoBrandingService } from '../../../go-branding.service'; @@ -8,17 +8,19 @@ import { GoBrandingService } from '../../../go-branding.service'; templateUrl: './go-nav-item.component.html', styleUrls: ['./go-nav-item.component.scss'] }) -export class GoNavItemComponent implements AfterContentInit { - @Input() navItem: NavItem; +export class GoNavItemComponent implements OnInit { + brandColor: string; - @ViewChild('goNavItemSelected') selectedBinding: ElementRef; + @Input() navItem: NavItem; constructor ( public navService: GoSideNavService, private brandingService: GoBrandingService ) { } - ngAfterContentInit(): void { - this.selectedBinding.nativeElement.style.background = this.brandingService.brandColor; + ngOnInit(): void { + this.brandingService.brandColor.subscribe((value: string) => { + this.brandColor = value; + }); } } diff --git a/projects/go-lib/src/lib/go-branding.service.ts b/projects/go-lib/src/lib/go-branding.service.ts index 459aa2301..c7885ff04 100644 --- a/projects/go-lib/src/lib/go-branding.service.ts +++ b/projects/go-lib/src/lib/go-branding.service.ts @@ -1,14 +1,11 @@ import { Injectable } from '@angular/core'; +import { BehaviorSubject } from 'rxjs'; @Injectable() export class GoBrandingService { - brandColor: string; - - constructor() { - this.brandColor = '#65B360'; - } + brandColor: BehaviorSubject = new BehaviorSubject('#65B360'); public setBrandColor(color: string): void { - this.brandColor = color; + this.brandColor.next(color); } } diff --git a/projects/go-tester/src/app/app.component.ts b/projects/go-tester/src/app/app.component.ts index 3f4301dd4..6fb2d6d18 100644 --- a/projects/go-tester/src/app/app.component.ts +++ b/projects/go-tester/src/app/app.component.ts @@ -38,7 +38,7 @@ export class AppComponent implements OnInit { private goModalService: GoModalService ) { } - ngOnInit() { + ngOnInit(): void { this.goBrandingService.setBrandColor('#8A4EDE'); } @@ -62,7 +62,7 @@ export class AppComponent implements OnInit { ); } - openToast() { + openToast(): void { this.goToasterService.toastInfo({ message: 'From the action sheet'}); } }