File
Description
HeaderComponent is the stylized blue header at the top of every single
application. It has a built-in "Skip to Content" tab-accessible section
that's best practice for screen readers. You must create an element with
id='content'
for this to work! Best practice is to put this "content"
element as a wrapper aroud your <router-outlet>
Implements
Metadata
selector |
common-header |
styleUrls |
./header.component.scss |
templateUrl |
./header.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Constructor
constructor(router: Router)
|
|
Parameters :
Name |
Type |
Optional |
router |
Router
|
No
|
|
logoSrc
|
Type : string
|
Default value : 'assets/gov3_bc_logo.png'
|
|
printLogoSrc
|
Type : string
|
Default value : 'assets/logo_print.png'
|
|
serviceName
|
Type : string
|
Default value : ''
|
|
shouldShowPrintLogo
|
Type : boolean
|
Default value : false
|
|
urlBaseName
|
Type : string
|
Default value : ''
|
|
Methods
Private
generateSkipToContentLink
|
generateSkipToContentLink()
|
|
|
routeIsActive
|
routeIsActive(url: string)
|
|
Parameters :
Name |
Type |
Optional |
url |
string
|
No
|
|
updateSkipContentLink
|
updateSkipContentLink()
|
|
|
Private
SKIP_CONTENT_HASH
|
Type : string
|
Default value : '#content'
|
|
import { Component, OnInit, Input } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { filter } from 'rxjs/operators';
/**
* HeaderComponent is the stylized blue header at the top of every single
* application. It has a built-in "Skip to Content" tab-accessible section
* that's best practice for screen readers. **You must create an element with
* `id='content'` for this to work!** Best practice is to put this "content"
* element as a wrapper aroud your `<router-outlet>`
*
*/
@Component({
selector: 'common-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
@Input() serviceName: string = '';
@Input() urlBaseName: string = '';
@Input() logoSrc: string = 'assets/gov3_bc_logo.png';
@Input() shouldShowPrintLogo: boolean = false;
@Input() printLogoSrc: string = 'assets/logo_print.png';
public skipLinkPath;
private SKIP_CONTENT_HASH = '#content';
constructor(private router: Router ) {
}
ngOnInit() {
this.router.events.pipe(
filter(ev => ev instanceof NavigationEnd),
).subscribe(this.updateSkipContentLink.bind(this));
this.updateSkipContentLink();
}
routeIsActive(url: string): boolean {
return this.router.url.includes(url);
}
updateSkipContentLink() {
this.skipLinkPath = this.generateSkipToContentLink();
}
// Slightly complicated because we have to include the deployUrl in manually.
// If deployUrl changes this code must too.
//
// "http://full-url.com/fpcare/example#content"
private generateSkipToContentLink(): string {
// don't add duplicate #contents
if (window.location.href.indexOf(this.SKIP_CONTENT_HASH) !== -1) {
return window.location.href;
}
return `${window.location.origin}/${this.urlBaseName + this.router.url}#content`;
}
}
<header>
<div class="container-fluid header-container d-flex justify-content-between align-items-center flex-wrap">
<div class='d-flex flex-wrap'>
<a [href]='skipLinkPath' class='skip-to-content order-3'>Skip to main content</a>
<a href="http://www2.gov.bc.ca/">
<img class="header-logo"
tabindex="-1"
alt="B.C. Government Logo"
src="{{logoSrc}}">
<img *ngIf="shouldShowPrintLogo"
class="header-logo-print"
tabindex="-1"
alt="B.C. Government Print Logo"
src="{{printLogoSrc}}">
</a>
<span class="title px-2 mt-1">{{serviceName}}</span>
</div>
</div>
</header>
Legend
Html element with directive