import { Component, OnInit, Input, Output, ElementRef, EventEmitter, HostBinding } from '@angular/core'; import { CfCoreComponent } from '../core/core.component'; import { IconModel } from '../../models/icon/icon.model'; import { IconStylingModel } from '../../models/icon/icon-styling.model'; import { IconTemplates } from '../../templates/icon.template'; /** *
Icon is creating based on Icon Class.
*Example of using component:
***/ @Component({ selector: 'cf-icon', template: "<cf-icon [properties]="icon"></cf-icon>*
Whether the icon is in toggle mode or normal mode.
*/ checked: boolean = true; currentIcon: any = {}; /** * It is cf-icon html attribute [settings] with json icon object. *Example of icon object:
*{
* name: 'home',
* size: '24px'
* }
* It is name of icon. Default is home.
*Next icons libraries are available:
* * *If icon name consists of more then one word, then:
*- for Material Icons: join words with underscore (like: thumb_up)
*- for Font Awesome Icons: join words with dash (like: fa-address-book)
*The styling object of the icon.
*Refer to ../models/icon/icon-styling.model.ts.
*/ @Input() styling: IconStylingModel; /** *The name of the icon as external property.
*mi Icons and FontAwesome names work in this case.
*/ @Input() public name: string; /** *The size of the icon and its container.
*In pixels and percentage.
*/ @Input() public size: string; /** *display or hide the icon.
*/
@Input() public display: boolean;
/**
* It is (cfOnToggle) attribute of cf-icon component. Means what event to call when toggle icon was clicked.
*/
@Output()
cfOnToggle: EventEmitter On Icon component initialization next things are heppening: Updating the properties object if any of the external inputs has been changed to keep the component dynamic. Changes that occured from the user.
*
*
*/
ngOnInit() {
if(this.notificationAction.observers.length > 0) this.notifacationClickable = 'notification-clickable';
this.activeTemplate = IconTemplates["defaultTemplate"];
if(this.compTemplate!=null && this.compTemplate!="")
{
if(IconTemplates[this.compTemplate]!=null)
{
this.activeTemplate = IconTemplates[this.compTemplate];
}
else
this.activeTemplate = this.compTemplate;
}
if(this.properties==null)
this.properties = new IconModel(this.activeTemplate["property"]);
else
{
var mainKeys = Object.keys(this.activeTemplate["property"]);
if(this.properties.toggle!=null && this.activeTemplate["property"].toggle!=null)
{
var toggleKeys = Object.keys(this.activeTemplate["property"].toggle);
for(let key of toggleKeys)
{
if(this.properties["toggle"][key]==null)
this.properties["toggle"][key]=this.activeTemplate["property"]["toggle"][key];
}
}
for(let key of mainKeys)
{
if(this.properties[key]==null)
this.properties[key]=this.activeTemplate["property"][key];
}
}
if(this.styling==null)
this.styling = new IconStylingModel(this.activeTemplate["style"]);
if(this.display!=null) this.properties.display = this.display;
if(this.name!=null)
{
this.properties.name = this.name;
if(this.name.startsWith("fa-"))
this.properties.type = "fa";
else
this.properties.type = "mi";
}
if(this.size!=null) this.properties.size = this.size;
this.cfIcon = this.properties;
this.currentIcon = this.cfIcon;
}
/**
*