import { Component, ElementRef, Input, OnInit, Renderer2 } from '@angular/core';
// Import navigation elements
import { navigation } from './../../_nav';
@Component({
selector: 'app-sidebar-nav',
template: `
`
})
export class AppSidebarNavComponent {
public navigation = navigation;
public isDivider(item) {
return item.divider ? true : false;
}
public isTitle(item) {
return item.title ? true : false;
}
constructor() { }
}
import { Router } from '@angular/router';
@Component({
selector: 'app-sidebar-nav-item',
template: `
`
})
export class AppSidebarNavItemComponent {
@Input() item: any;
public hasClass() {
return this.item.class ? true : false;
}
public isDropdown() {
return this.item.children ? true : false;
}
public thisUrl() {
return this.item.url;
}
public isActive() {
return this.router.isActive(this.thisUrl(), false);
}
constructor( private router: Router ) { }
}
@Component({
selector: 'app-sidebar-nav-link',
template: `
{{ link.name }}
{{ link.badge.text }}
{{ link.name }}
{{ link.badge.text }}
`
})
export class AppSidebarNavLinkComponent {
@Input() link: any;
public hasVariant() {
return this.link.variant ? true : false;
}
public isBadge() {
return this.link.badge ? true : false;
}
public isExternalLink() {
return this.link.url.substring(0, 4) === 'http' ? true : false;
}
public isIcon() {
return this.link.icon ? true : false;
}
constructor() { }
}
@Component({
selector: 'app-sidebar-nav-dropdown',
template: `
{{ link.name }}
{{ link.badge.text }}
`
})
export class AppSidebarNavDropdownComponent {
@Input() link: any;
public isBadge() {
return this.link.badge ? true : false;
}
public isIcon() {
return this.link.icon ? true : false;
}
constructor() { }
}
@Component({
selector: 'app-sidebar-nav-title',
template: ''
})
export class AppSidebarNavTitleComponent implements OnInit {
@Input() title: any;
constructor(private el: ElementRef, private renderer: Renderer2) { }
ngOnInit() {
const nativeElement: HTMLElement = this.el.nativeElement;
const li = this.renderer.createElement('li');
const name = this.renderer.createText(this.title.name);
this.renderer.addClass(li, 'nav-title');
if ( this.title.class ) {
const classes = this.title.class;
this.renderer.addClass(li, classes);
}
if ( this.title.wrapper ) {
const wrapper = this.renderer.createElement(this.title.wrapper.element);
this.renderer.appendChild(wrapper, name);
this.renderer.appendChild(li, wrapper);
} else {
this.renderer.appendChild(li, name);
}
this.renderer.appendChild(nativeElement, li);
}
}
export const APP_SIDEBAR_NAV = [
AppSidebarNavComponent,
AppSidebarNavDropdownComponent,
AppSidebarNavItemComponent,
AppSidebarNavLinkComponent,
AppSidebarNavTitleComponent
];