From bd9463c836130c1d37e56be3658076ecd11ed76d Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Sun, 28 Jan 2018 21:28:42 +0100 Subject: [Dashboard]: Reworked sidebar menu auto expanding Signed-off-by: Sebastien Douheret --- webapp/src/app/@theme/layouts/xds/xds.layout.html | 17 +++++--- webapp/src/app/@theme/layouts/xds/xds.layout.scss | 18 ++++++++ webapp/src/app/@theme/layouts/xds/xds.layout.ts | 53 ++++++++++++++++------- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/webapp/src/app/@theme/layouts/xds/xds.layout.html b/webapp/src/app/@theme/layouts/xds/xds.layout.html index 74d0f97..ee0a80b 100644 --- a/webapp/src/app/@theme/layouts/xds/xds.layout.html +++ b/webapp/src/app/@theme/layouts/xds/xds.layout.html @@ -4,18 +4,21 @@ - - - + + - - + + + - - + + diff --git a/webapp/src/app/@theme/layouts/xds/xds.layout.scss b/webapp/src/app/@theme/layouts/xds/xds.layout.scss index 7ccf7b7..5ac018e 100644 --- a/webapp/src/app/@theme/layouts/xds/xds.layout.scss +++ b/webapp/src/app/@theme/layouts/xds/xds.layout.scss @@ -58,6 +58,12 @@ text-align: center; } + /deep/ .tooltip { + animation-name: delayedFadeIn; + animation-duration: 2s; + width: 8rem; + } + background: transparent; .main-btn { @@ -98,6 +104,12 @@ } } } + + &.left.expanded { + #pin-sidebar { + margin-left: 11rem; + } + } } @include media-breakpoint-down(xs) { @@ -128,3 +140,9 @@ } } } + +@Keyframes delayedFadeIn { + 0% {opacity: 0;} + 75% {opacity: 0;} /* Set this to 99% for no fade-in. */ + 100% {opacity: 1;} +} diff --git a/webapp/src/app/@theme/layouts/xds/xds.layout.ts b/webapp/src/app/@theme/layouts/xds/xds.layout.ts index 7e7f0fd..b362fff 100644 --- a/webapp/src/app/@theme/layouts/xds/xds.layout.ts +++ b/webapp/src/app/@theme/layouts/xds/xds.layout.ts @@ -29,6 +29,7 @@ export class XdsLayoutComponent implements OnDestroy { subMenu: NbMenuItem[] = []; layout: any = {}; sidebar: any = {}; + sidebarPinned = false; sidebarCompact = true; protected layoutState$: Subscription; @@ -43,6 +44,7 @@ export class XdsLayoutComponent implements OnDestroy { protected themeService: NbThemeService, protected bpService: NbMediaBreakpointsService, protected sidebarService: NbSidebarService) { + this.layoutState$ = this.stateService.onLayoutState() .subscribe((layout: string) => this.layout = layout); @@ -52,40 +54,67 @@ export class XdsLayoutComponent implements OnDestroy { }); const isBp = this.bpService.getByName('is'); + this.menuClick$ = this.menuService.onItemSelect() .withLatestFrom(this.themeService.onMediaQueryChange()) .delay(20) .subscribe(([item, [bpFrom, bpTo]]: [any, [NbMediaBreakpoint, NbMediaBreakpoint]]) => { - + /* this.sidebarCompact = false; + */ + // automatically collapse sidebar for narrow screen / mobile if (bpTo.width <= isBp.width) { this.sidebarService.collapse('menu-sidebar'); } }); // Set sidebarCompact according to sidebar state changes - this.sidebarService.onToggle().subscribe(s => s.tag === 'menu-sidebar' && (this.sidebarCompact = !this.sidebarCompact)); + this.sidebarService.onToggle().subscribe(s => { + if (s.tag === 'menu-sidebar') { + this.sidebarPinned = false; + this.sidebarCompact = !this.sidebarCompact; + } + }); + this.sidebarService.onCollapse().subscribe(s => s.tag === 'menu-sidebar' && (this.sidebarCompact = true)); - this.sidebarService.onExpand().subscribe(() => this.sidebarCompact = false); + this.sidebarService.onExpand().subscribe(s => s.tag === 'menu-sidebar' && (this.sidebarCompact = false)); this.menuService.onSubmenuToggle().subscribe(i => i.item && i.item.expanded && (this.sidebarCompact = false)); // Automatically expand sidebar on mouse over this._mouseEnterStream.flatMap(e => { return Observable .of(e) - .delay(200) + .delay(100) .takeUntil(this._mouseLeaveStream); }) - .subscribe(e => (this.sidebarCompact) && this.sidebarService.toggle(true, 'menu-sidebar')); + .subscribe(e => { + if (this.sidebarPinned || !this.sidebarCompact) { + return; + } + // this._mouseLeaveStream.emit(null); + this.sidebarService.toggle(false, 'menu-sidebar'); + }); // Automatically collapse sidebar on mouse leave this._mouseLeaveStream.flatMap(e => { return Observable .of(e) - .delay(500) + .delay(100) .takeUntil(this._mouseEnterStream); }) - .subscribe(e => this.sidebarService.toggle(true, 'menu-sidebar')); + .subscribe(e => { + if (this.sidebarPinned || this.sidebarCompact) { + return; + } + // this._mouseEnterStream.emit(null); + this.sidebarService.toggle(true, 'menu-sidebar'); + }); + } + + ngOnDestroy() { + this.layoutState$.unsubscribe(); + this.sidebarState$.unsubscribe(); + this.menuClick$.unsubscribe(); } onMouseEnter($event) { @@ -96,13 +125,7 @@ export class XdsLayoutComponent implements OnDestroy { this._mouseLeaveStream.emit($event); } - toogleSidebar() { - this.sidebarService.toggle(true, 'menu-sidebar'); - } - - ngOnDestroy() { - this.layoutState$.unsubscribe(); - this.sidebarState$.unsubscribe(); - this.menuClick$.unsubscribe(); + pinSidebar() { + this.sidebarPinned = !this.sidebarPinned; } } -- cgit 1.2.3-korg