File

app/dxa/dxa-entity/views/page-detail-views/page-detail-header/page-detail-header.component.ts

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector div[page-detail-header]
styleUrls ./page-detail-header.component.scss
templateUrl ./page-detail-header.component.html

Index

Properties
Methods
Inputs
HostBindings

Constructor

constructor(util: UtilService, titleService: Title, document)
Parameters :
Name Type Optional
util UtilService No
titleService Title No
document No

Inputs

entity
region

HostBindings

class

Methods

Public jsonToLogo
jsonToLogo(json)
Parameters :
Name Optional
json No
Returns : Logo
ngOnInit
ngOnInit()
Returns : void

Properties

Public h1
Type : string
Public logos
import { Component, OnInit, Input, ChangeDetectionStrategy, HostBinding, Inject } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { DOCUMENT } from '@angular/common';

interface Logo {
	altText: string;
	url: string;
}

@Component({
	selector: 'div[page-detail-header]',
	templateUrl: './page-detail-header.component.html',
	styleUrls: ['./page-detail-header.component.scss'],
	changeDetection: ChangeDetectionStrategy.OnPush
})
export class PageDetailHeaderComponent implements OnInit {
	
	@Input() entity;
	@Input() region;
	
	public h1: string;
	public logos;

	@HostBinding('class') get class() { return 'col-md-12'; }

	constructor(
		private util: UtilService,
		private titleService: Title,
		@Inject(DOCUMENT) private document
	) { }

	ngOnInit() {
		this.titleService.setTitle(this.util.extract(this.entity, 'BrowserTabTitle') || 'SKF.com');
		this.h1 = this.entity.H1Title;
		// Consider only first four logos
		this.logos = (this.entity.Logo || []).slice(0, 4).map(e => this.jsonToLogo(e));

		// Add meta data tags to DOM head.
		const metaTags = this.util.extract(this.entity, 'MetaTag') || [];
		metaTags.forEach(metaTag => {
			const tagName = this.util.extract(metaTag, 'MetaName');
			const tagValue = this.util.extract(metaTag, 'MetaTag');
			if (tagName && tagValue) {
				const meta = this.document.createElement('meta');
				meta.name = tagName;
				meta.content = tagValue;
				this.document.getElementsByTagName('head')[0].appendChild(meta);
			}
		});
	}
	public jsonToLogo(json): Logo {
		const url = this.util.extract(json, 'Url') || '';
		const altText = this.util.extract(json, 'Assetmetadata', 'Cmsdescription') || '';
		const logo: Logo = {
			altText: altText,
			url: url
		};

		return logo;
	}

}
<div class="page-details-header">
  <div class="logos" *ngIf="logos?.length > 0">
    <ng-container *ngFor="let logo of logos">
      <!-- We don't set any width or height here. It is up to the content managers to upload images of an appropriate size-->
      <img [src]="logo.url" [alt]="logo.altText">
    </ng-container>
  </div>

  <div [ngClass]="{'h1-white': region ==='TOP', 'title': true}" *ngIf="h1">
    <h1 [innerHtml]="h1"></h1>
  </div>
</div>

./page-detail-header.component.scss

@import "src/app/styles/helpers";

.page-details-header {
    margin: calc-rem(30) 0;

    ::ng-deep .top-region-body-text & {
        margin-bottom: 0;
    }

    .title h1 {
        @include font-size(44);
    }

    .logos {
        display: flex;
        flex-wrap: wrap;
        flex-direction: row;
        margin-bottom: calc-rem(10);

        @include media-breakpoint-down(lg) {
            justify-content: center;
        }

        img {
            margin-bottom: calc-rem(10);
            max-height: calc-rem(90);
            max-width: 100%;

            & + img {
                margin-left: calc-rem(10);
            }
        }
    }

    .title {
        &.h1-white h1 {
            color: white;
        }
    }

}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""