(FuseNavBar) default folded option added, responsive, right/left sidenav issues fixed.

This commit is contained in:
mustafahlvc 2017-08-15 15:34:24 +03:00
parent 117f5a85b2
commit da97ab7e4b
4 changed files with 106 additions and 37 deletions

View File

@ -10,7 +10,7 @@
<div id="wrapper"> <div id="wrapper">
<fuse-navbar class="md-primary-700-bg" *ngIf="layoutSettings.navigation === 'left'"></fuse-navbar> <fuse-navbar [folded]="true" class="md-primary-700-bg left-navbar" *ngIf="layoutSettings.navigation === 'left'"></fuse-navbar>
<div class="content-wrapper"> <div class="content-wrapper">
@ -30,7 +30,7 @@
</div> </div>
<fuse-navbar class="md-primary-bg" *ngIf="layoutSettings.navigation === 'right'"></fuse-navbar> <fuse-navbar [folded]="true" class="md-primary-700-bg right-navbar" *ngIf="layoutSettings.navigation === 'right'"></fuse-navbar>
</div> </div>

View File

@ -10,18 +10,20 @@ export class FuseNavbarToggleDirective
@Input() fuseNavbar: string; @Input() fuseNavbar: string;
navbar: FuseNavbarComponent; navbar: FuseNavbarComponent;
constructor(navbar: FuseNavbarService) constructor(private navbarService: FuseNavbarService)
{ {
this.navbar = navbar.getNavBar();
} }
@HostListener('click') @HostListener('click')
onClick() onClick()
{ {
this.navbar = this.navbarService.getNavBar();
if ( !this.navbar[this.fuseNavbar] ) if ( !this.navbar[this.fuseNavbar] )
{ {
return; return;
} }
this.navbar[this.fuseNavbar](); this.navbar[this.fuseNavbar]();
} }
} }

View File

@ -5,8 +5,15 @@ body {
&.fuse-nav-bar-folded { &.fuse-nav-bar-folded {
.content-wrapper { .content-wrapper {
&:last-child {
padding-left: 64px !important; padding-left: 64px !important;
} }
&:first-child {
padding-right: 64px !important;
}
}
} }
} }
@ -27,6 +34,13 @@ fuse-navbar {
&.folded { &.folded {
position: absolute; position: absolute;
&.left-navbar {
left: 0;
}
&.right-navbar {
right: 0;
}
&:not(.folded-open) { &:not(.folded-open) {
width: 64px; width: 64px;
min-width: 64px; min-width: 64px;
@ -42,21 +56,36 @@ fuse-navbar {
} }
} }
&.open {
transform: translateX(0) !important;
}
&.close { &.close {
&.left-navbar {
transform: translateX(-100%) !important; transform: translateX(-100%) !important;
} }
&.right-navbar {
transform: translateX(100%) !important;
}
box-shadow: none;
}
@include media-breakpoint('xs') { @include media-breakpoint('xs') {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0;
bottom: 0; bottom: 0;
&.left-navbar {
left: 0;
}
&.right-navbar {
right: 0;
}
&:not(.initialized) {
&.left-navbar {
transform: translateX(-100%); transform: translateX(-100%);
} }
&.right-navbar {
transform: translateX(100%);
}
}
}
.navbar-header { .navbar-header {
padding: 0 16px 0 24px; padding: 0 16px 0 24px;

View File

@ -1,8 +1,9 @@
import { Component, HostBinding, HostListener, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; import { Component, HostBinding, HostListener, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { AppComponent } from '../../app.component'; import { AppComponent } from '../../app.component';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { FuseMatchMedia } from '../../core/services/match-media.service'; import { FuseMatchMedia } from '../../core/services/match-media.service';
import { FuseNavbarService } from './navbar.service'; import { FuseNavbarService } from './navbar.service';
import { ObservableMedia } from '@angular/flex-layout';
@Component({ @Component({
selector : 'fuse-navbar', selector : 'fuse-navbar',
@ -13,37 +14,68 @@ import { FuseNavbarService } from './navbar.service';
export class FuseNavbarComponent implements OnInit, OnDestroy export class FuseNavbarComponent implements OnInit, OnDestroy
{ {
@HostBinding('class.close') isClosed: boolean; @HostBinding('class.close') isClosed: boolean;
@HostBinding('class.open') isOpened: boolean = !this.isClosed;
@HostBinding('class.folded') isFoldedActive: boolean; @HostBinding('class.folded') isFoldedActive: boolean;
@HostBinding('class.folded-open') isFoldedOpen: boolean; @HostBinding('class.folded-open') isFoldedOpen: boolean;
@HostBinding('class.initialized') initialized: boolean;
@Input('folded') foldedByDefault = false;
matchMediaWatcher: Subscription; matchMediaWatcher: Subscription;
constructor( constructor(
private bodyEl: AppComponent, private bodyEl: AppComponent,
private fuseMatchMedia: FuseMatchMedia, private fuseMatchMedia: FuseMatchMedia,
private navBarService: FuseNavbarService private navBarService: FuseNavbarService,
public media: ObservableMedia
) )
{ {
navBarService.setNavBar(this); navBarService.setNavBar(this);
this.isClosed = false;
this.isFoldedActive = false;
this.isFoldedOpen = false;
this.updateCssClasses();
this.matchMediaWatcher = this.matchMediaWatcher =
this.fuseMatchMedia.onMediaChange this.fuseMatchMedia.onMediaChange
.subscribe((mediaStep) => { .subscribe((mediaStep) => {
setTimeout(() => {
if ( mediaStep === 'xs' ) if ( mediaStep === 'xs' )
{ {
this.closeBar(); this.closeBar();
this.deActivateFolded();
} }
else else
{ {
this.openBar(); this.openBar();
} }
}); });
});
}
ngOnInit()
{
this.isClosed = false;
this.isFoldedActive = this.foldedByDefault;
this.isFoldedOpen = false;
this.initialized = false;
this.updateCssClasses();
setTimeout(() => {
this.initialized = true;
});
if ( this.media.isActive('xs') )
{
this.closeBar();
this.deActivateFolded();
}
else
{
if ( !this.foldedByDefault )
{
this.deActivateFolded();
}
else
{
this.activateFolded();
}
}
} }
openBar() openBar()
@ -74,14 +106,25 @@ export class FuseNavbarComponent implements OnInit, OnDestroy
{ {
if ( !this.isFoldedActive ) if ( !this.isFoldedActive )
{ {
this.isFoldedActive = true; this.activateFolded();
this.bodyEl.addClass('fuse-nav-bar-folded');
} }
else else
{
this.deActivateFolded();
}
}
activateFolded()
{
this.isFoldedActive = true;
this.bodyEl.addClass('fuse-nav-bar-folded');
this.isFoldedOpen = false;
}
deActivateFolded()
{ {
this.isFoldedActive = false; this.isFoldedActive = false;
this.bodyEl.removeClass('fuse-nav-bar-folded'); this.bodyEl.removeClass('fuse-nav-bar-folded');
}
this.isFoldedOpen = false; this.isFoldedOpen = false;
} }
@ -111,11 +154,6 @@ export class FuseNavbarComponent implements OnInit, OnDestroy
} }
} }
ngOnInit()
{
}
ngOnDestroy() ngOnDestroy()
{ {
this.matchMediaWatcher.unsubscribe(); this.matchMediaWatcher.unsubscribe();