novo-elements
Version:
Bullhorn's NOVO Element Repository for Angular 2
81 lines (74 loc) • 3.52 kB
text/typescript
// NG2
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
export class CardBestTimeElement implements OnChanges {
label: string;
time: string;
day: string;
hideLabel: boolean;
timeIcon: string;
timeStyle: string;
dayLowerCase: string;
dataAutomationId: string;
ngOnChanges(changes?: SimpleChanges) {
if (this.time) {
let timeIconAndStyle = this.getTimeOfDayStyleAndIcon(this.time);
this.timeIcon = timeIconAndStyle.icon;
this.timeStyle = timeIconAndStyle.style;
this.dayLowerCase = (this.day || '').toLowerCase();
this.dataAutomationId = this.label ? this.label.replace(/\s+/g, '-').toLowerCase() : '';
}
}
getTimeOfDayStyleAndIcon(time) {
let icon = null;
let style = null;
let transformedTime = time.replace(/\s+/g, '-').toUpperCase();
const TIMES = {
morningTimes: {
times: ['5-AM', '6-AM', '7-AM', '8-AM', '9-AM', '10-AM'],
icon: 'bhi-coffee'
},
dayTimes: {
times: ['11-AM', '12-PM', '1-PM', '2-PM', '3-PM', '4-PM', '5-PM', '6-PM'],
icon: 'bhi-day'
},
eveningTimes: {
times: ['7-PM', '8-PM', '9-PM', '10-PM', '11-PM', '12-AM', '1-AM', '2-AM', '3-AM', '4-AM'],
icon: 'bhi-evening'
}
};
for (let prop in TIMES) {
if (TIMES[prop].times.indexOf(transformedTime) > -1) {
icon = TIMES[prop].icon;
if (icon === 'bhi-coffee') {
style = 'morning';
} else if (icon === 'bhi-day') {
style = 'day';
} else if (icon === 'bhi-evening') {
style = 'evening';
}
}
}
return { icon, style };
}
}