Improve Sidenav
parent
d26aad357a
commit
8c987c5ba7
@ -1,15 +0,0 @@
|
||||
<a mat-list-item [ngStyle]="{'padding-left': (depth * 12) + 'px'}" [ngClass]="{'active': item.route ? router.isActive(item.route, true): false, 'expanded': expanded}" class="menu-list-item">
|
||||
<span (click)="onItemSelected(item)">
|
||||
<mat-icon class="routeIcon">{{item.iconName}}</mat-icon>
|
||||
{{item.displayName}}
|
||||
</span>
|
||||
<span fxFlex *ngIf="item.children && item.children.length" (click)="expand(item)">
|
||||
<span fxFlex></span>
|
||||
<mat-icon [@indicatorRotate]="expanded ? 'expanded': 'collapsed'">
|
||||
expand_more
|
||||
</mat-icon>
|
||||
</span>
|
||||
</a>
|
||||
<div *ngIf="expanded">
|
||||
<app-menu-list-item *ngFor="let child of item.children" [item]="child" [depth]="depth+1"> </app-menu-list-item>
|
||||
</div>
|
@ -1,33 +0,0 @@
|
||||
@import '../../../theme';
|
||||
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
outline: none;
|
||||
width: 100%;
|
||||
|
||||
.mat-list-item.active {
|
||||
//background-color: mat-color($dark-primary, 50);
|
||||
}
|
||||
&:hover,
|
||||
&:focus {
|
||||
>.mat-list-item:not(.expanded) {
|
||||
//background-color: mat-color($dark-primary, 100) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.mat-list-item {
|
||||
padding: 8px 0;
|
||||
display: flex;
|
||||
width: auto;
|
||||
|
||||
.routeIcon {
|
||||
margin-right: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
span {
|
||||
display: inline-flex;
|
||||
vertical-align: middle;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
import {Component, HostBinding, Input, OnInit} from '@angular/core';
|
||||
import {NavItem} from './nav-item';
|
||||
import {Router} from '@angular/router';
|
||||
import {NavService} from './nav.service';
|
||||
import {animate, state, style, transition, trigger} from '@angular/animations';
|
||||
|
||||
@Component({
|
||||
selector: 'app-menu-list-item',
|
||||
templateUrl: './menu-list-item.component.html',
|
||||
styleUrls: ['./menu-list-item.component.scss'],
|
||||
animations: [
|
||||
trigger('indicatorRotate', [
|
||||
state('collapsed', style({transform: 'rotate(0deg)'})),
|
||||
state('expanded', style({transform: 'rotate(180deg)'})),
|
||||
transition('expanded <=> collapsed',
|
||||
animate('225ms cubic-bezier(0.4,0.0,0.2,1)')
|
||||
),
|
||||
])
|
||||
]
|
||||
})
|
||||
export class MenuListItemComponent implements OnInit {
|
||||
expanded: boolean = false;
|
||||
@HostBinding('attr.aria-expanded') ariaExpanded = this.expanded;
|
||||
@Input() item: NavItem;
|
||||
@Input() depth: number;
|
||||
|
||||
constructor(public navService: NavService,
|
||||
public router: Router,
|
||||
) {
|
||||
if (this.depth === undefined) {
|
||||
this.depth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.navService.currentUrl.subscribe((url: string) => {
|
||||
if (this.item.route && url) {
|
||||
// console.log(`Checking '/${this.item.route}' against '${url}'`);
|
||||
this.expanded = url.indexOf(`/${this.item.route}`) === 0;
|
||||
this.ariaExpanded = this.expanded;
|
||||
// console.log(`${this.item.route} is expanded: ${this.expanded}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onItemSelected(item: NavItem) {
|
||||
/*if (!item.children || !item.children.length) {
|
||||
this.router.navigate([item.route]);
|
||||
this.navService.closeNav();
|
||||
}
|
||||
if (item.children && item.children.length) {
|
||||
this.expanded = !this.expanded;
|
||||
}*/
|
||||
|
||||
this.router.navigate([item.route]);
|
||||
this.navService.closeNav();
|
||||
}
|
||||
|
||||
expand(item: NavItem) {
|
||||
this.expanded = !this.expanded;
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
export interface NavItem {
|
||||
displayName: string;
|
||||
disabled?: boolean;
|
||||
iconName: string;
|
||||
route?: string;
|
||||
children?: NavItem[];
|
||||
}
|
||||
|
Loading…
Reference in New Issue