fix(header): adopt for smaller screens

This commit is contained in:
Sergey Andrievskiy 2019-06-22 19:18:16 +03:00
parent 5d543a4eeb
commit 082f72b441
3 changed files with 47 additions and 17 deletions

View file

@ -18,8 +18,12 @@
</nb-action>
<nb-action class="control-item" icon="email-outline"></nb-action>
<nb-action class="control-item" icon="bell-outline"></nb-action>
<nb-action *nbIsGranted="['view', 'user']" >
<nb-user [nbContextMenu]="userMenu" [name]="user?.name" [picture]="user?.picture"></nb-user>
<nb-action class="user-action" *nbIsGranted="['view', 'user']" >
<nb-user [nbContextMenu]="userMenu"
[onlyPicture]="userPictureOnly"
[name]="user?.name"
[picture]="user?.picture">
</nb-user>
</nb-action>
</nb-actions>
</div>

View file

@ -1,3 +1,5 @@
@import '~bootstrap/scss/mixins/breakpoints';
@import '~@nebular/theme/styles/global/breakpoints';
@import '../../styles/themes';
@include nb-install-component() {
@ -5,17 +7,6 @@
justify-content: space-between;
width: 100%;
.left {
display: flex;
width: 100%;
order: 0;
flex-direction: row;
}
.right {
order: 1;
flex-direction: row-reverse;
}
.logo-container {
display: flex;
align-items: center;
@ -60,4 +51,20 @@
text-decoration: none;
}
}
@include media-breakpoint-down(sm) {
.control-item {
display: none;
}
.user-action {
border: none;
padding: 0;
}
}
@include media-breakpoint-down(is) {
nb-select {
display: none;
}
}
}

View file

@ -1,16 +1,20 @@
import { Component, OnInit } from '@angular/core';
import { NbMenuService, NbSidebarService, NbThemeService } from '@nebular/theme';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { NbMediaBreakpointsService, NbMenuService, NbSidebarService, NbThemeService } from '@nebular/theme';
import { UserData } from '../../../@core/data/users';
import { LayoutService } from '../../../@core/utils';
import { map, takeUntil } from 'rxjs/operators';
import { pipe, Subject } from 'rxjs';
@Component({
selector: 'ngx-header',
styleUrls: ['./header.component.scss'],
templateUrl: './header.component.html',
})
export class HeaderComponent implements OnInit {
export class HeaderComponent implements OnInit, OnDestroy {
private destroy$: Subject<void> = new Subject<void>();
userPictureOnly: boolean = false;
user: any;
themes = [
@ -40,12 +44,27 @@ export class HeaderComponent implements OnInit {
private menuService: NbMenuService,
private themeService: NbThemeService,
private userService: UserData,
private layoutService: LayoutService) {
private layoutService: LayoutService,
private breakpointService: NbMediaBreakpointsService) {
}
ngOnInit() {
this.userService.getUsers()
.pipe(takeUntil(this.destroy$))
.subscribe((users: any) => this.user = users.nick);
const { xl } = this.breakpointService.getBreakpointsMap();
this.themeService.onMediaQueryChange()
.pipe(
map(([, currentBreakpoint]) => currentBreakpoint.width < xl),
takeUntil(this.destroy$),
)
.subscribe((isLessThanXl: boolean) => this.userPictureOnly = isLessThanXl);
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
toggleTheme() {