Skip to content

Commit

Permalink
Use gap instead of individual paddings for header icons
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevryghem committed Sep 26, 2023
1 parent 404ccd9 commit c7c4b28
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ElementRef } from '@angular/core';
import { ContextHelpService } from '../../shared/context-help.service';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';

/**
Expand All @@ -15,12 +15,23 @@ import { map } from 'rxjs/operators';
export class ContextHelpToggleComponent implements OnInit {
buttonVisible$: Observable<boolean>;

subscriptions: Subscription[] = [];

constructor(
private contextHelpService: ContextHelpService,
) { }
protected elRef: ElementRef,
protected contextHelpService: ContextHelpService,
) {
}

ngOnInit(): void {
this.buttonVisible$ = this.contextHelpService.tooltipCount$().pipe(map(x => x > 0));
this.subscriptions.push(this.buttonVisible$.subscribe((showContextHelpToggle: boolean) => {
if (showContextHelpToggle) {
this.elRef.nativeElement.classList.remove('d-none');
} else {
this.elRef.nativeElement.classList.add('d-none');
}
}));
}

onClick() {
Expand Down
4 changes: 2 additions & 2 deletions src/app/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<ds-context-help-toggle></ds-context-help-toggle>
<ds-themed-auth-nav-menu></ds-themed-auth-nav-menu>
<ds-impersonate-navbar></ds-impersonate-navbar>
<div class="pl-2">
<button class="navbar-toggler" type="button" (click)="toggleNavbar()"
<div *ngIf="isXsOrSm$ | async" class="pl-2">
<button class="navbar-toggler px-0" type="button" (click)="toggleNavbar()"
aria-controls="collapsingNav"
aria-expanded="false" [attr.aria-label]="'nav.toggle' | translate">
<span class="navbar-toggler-icon fas fa-bars fa-fw" aria-hidden="true"></span>
Expand Down
4 changes: 4 additions & 0 deletions src/app/header/header.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
}
}

.navbar {
display: flex;
gap: 0.25rem;
}
14 changes: 10 additions & 4 deletions src/app/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { MenuService } from '../shared/menu/menu.service';
import { MenuID } from '../shared/menu/menu-id.model';
import { HostWindowService } from '../shared/host-window.service';

/**
* Represents the header with the logo and simple navigation
Expand All @@ -11,20 +12,25 @@ import { MenuID } from '../shared/menu/menu-id.model';
styleUrls: ['header.component.scss'],
templateUrl: 'header.component.html',
})
export class HeaderComponent {
export class HeaderComponent implements OnInit {
/**
* Whether user is authenticated.
* @type {Observable<string>}
*/
public isAuthenticated: Observable<boolean>;
public showAuth = false;
public isXsOrSm$: Observable<boolean>;
menuID = MenuID.PUBLIC;

constructor(
private menuService: MenuService
protected menuService: MenuService,
protected windowService: HostWindowService,
) {
}

ngOnInit(): void {
this.isXsOrSm$ = this.windowService.isXsOrSm();
}

public toggleNavbar(): void {
this.menuService.toggleMenu(this.menuID);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/search-navbar/search-navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<form [formGroup]="searchForm" (ngSubmit)="onSubmit(searchForm.value)" autocomplete="on">
<input #searchInput [@toggleAnimation]="isExpanded" [attr.aria-label]="('nav.search' | translate)" name="query"
formControlName="query" type="text" placeholder="{{searchExpanded ? ('nav.search' | translate) : ''}}"
class="d-inline-block bg-transparent position-absolute form-control dropdown-menu-right p-1" [attr.data-test]="'header-search-box' | dsBrowserOnly">
class="d-inline-block bg-transparent position-absolute form-control dropdown-menu-right pl-1" [attr.data-test]="'header-search-box' | dsBrowserOnly">
<button class="submit-icon btn btn-link btn-link-inline" [attr.aria-label]="'nav.search.button' | translate" type="button" (click)="searchExpanded ? onSubmit(searchForm.value) : expand()" [attr.data-test]="'header-search-icon' | dsBrowserOnly">
<em class="fas fa-search fa-lg fa-fw"></em>
</button>
Expand Down
1 change: 1 addition & 0 deletions src/app/search-navbar/search-navbar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ input[type="text"] {
cursor: pointer;
position: sticky;
top: 0;
border: 0 !important;

color: var(--ds-header-icon-color);
&:hover, &:focus {
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/animations/slide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const slideSidebarPadding = trigger('slideSidebarPadding', [

export const expandSearchInput = trigger('toggleAnimation', [
state('collapsed', style({
width: '30px',
width: '0',
opacity: '0'
})),
state('expanded', style({
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/auth-nav-menu/auth-nav-menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<li *ngIf="!(isAuthenticated | async) && !(isXsOrSm$ | async) && (showAuth | async)" class="nav-item"
(click)="$event.stopPropagation();">
<div ngbDropdown #loginDrop display="dynamic" placement="bottom-right" class="d-inline-block" @fadeInOut>
<a href="javascript:void(0);" class="dropdownLogin px-1" [attr.aria-label]="'nav.login' |translate"
<a href="javascript:void(0);" class="dropdownLogin" [attr.aria-label]="'nav.login' |translate"
(click)="$event.preventDefault()" [attr.data-test]="'login-menu' | dsBrowserOnly"
ngbDropdownToggle>{{ 'nav.login' | translate }}</a>
<div class="loginDropdownMenu" [ngClass]="{'pl-3 pr-3': (loading | async)}" ngbDropdownMenu
Expand All @@ -13,7 +13,7 @@
</div>
</li>
<li *ngIf="!(isAuthenticated | async) && (isXsOrSm$ | async)" class="nav-item">
<a routerLink="/login" routerLinkActive="active" class="loginLink px-1">
<a routerLink="/login" routerLinkActive="active" class="loginLink">
{{ 'nav.login' | translate }}<span class="sr-only">(current)</span>
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul class="navbar-nav" *ngIf="(isAuthenticated$ | async) && isImpersonating">
<ul class="navbar-nav" *ngIf="isImpersonating$ | async">
<li class="nav-item">
<button class="btn btn-sm btn-dark" ngbTooltip="{{'nav.stop-impersonating' | translate}}" (click)="stopImpersonating()">
<i class="fa fa-user-secret"></i>
Expand Down
33 changes: 21 additions & 12 deletions src/app/shared/impersonate-navbar/impersonate-navbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ElementRef } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { AppState } from '../../app.reducer';
import { AuthService } from '../../core/auth/auth.service';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { isAuthenticated } from '../../core/auth/selectors';

@Component({
Expand All @@ -13,24 +14,32 @@ import { isAuthenticated } from '../../core/auth/selectors';
* Navbar component for actions to take concerning impersonating users
*/
export class ImpersonateNavbarComponent implements OnInit {
/**
* Whether or not the user is authenticated.
* @type {Observable<string>}
*/
isAuthenticated$: Observable<boolean>;

/**
* Is the user currently impersonating another user?
*/
isImpersonating: boolean;
isImpersonating$: Observable<boolean>;

subscriptions: Subscription[] = [];

constructor(private store: Store<AppState>,
private authService: AuthService) {
constructor(
protected elRef: ElementRef,
protected store: Store<AppState>,
protected authService: AuthService,
) {
}

ngOnInit(): void {
this.isAuthenticated$ = this.store.pipe(select(isAuthenticated));
this.isImpersonating = this.authService.isImpersonating();
this.isImpersonating$ = this.store.pipe(select(isAuthenticated)).pipe(
map((isUserAuthenticated: boolean) => isUserAuthenticated && this.authService.isImpersonating()),
);
this.subscriptions.push(this.isImpersonating$.subscribe((isImpersonating: boolean) => {
if (isImpersonating) {
this.elRef.nativeElement.classList.remove('d-none');
} else {
this.elRef.nativeElement.classList.add('d-none');
}
}));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/lang-switch/lang-switch.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div ngbDropdown class="navbar-nav" *ngIf="moreThanOneLanguage" display="dynamic" placement="bottom-right">
<a href="javascript:void(0);" role="button"
[attr.aria-label]="'nav.language' |translate"
[title]="'nav.language' | translate" class="px-1"
[title]="'nav.language' | translate"
(click)="$event.preventDefault()" data-toggle="dropdown" ngbDropdownToggle
tabindex="0">
<i class="fas fa-globe-asia fa-lg fa-fw"></i>
Expand Down
8 changes: 5 additions & 3 deletions src/app/shared/lang-switch/lang-switch.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Component, OnInit } from '@angular/core';

import { Component, OnInit, ElementRef } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

import { LangConfig } from '../../../config/lang-config.interface';
import { environment } from '../../../environments/environment';
import { LocaleService } from '../../core/locale/locale.service';
Expand All @@ -25,6 +23,7 @@ export class LangSwitchComponent implements OnInit {
moreThanOneLanguage: boolean;

constructor(
public el: ElementRef,
public translate: TranslateService,
private localeService: LocaleService
) {
Expand All @@ -33,6 +32,9 @@ export class LangSwitchComponent implements OnInit {
ngOnInit(): void {
this.activeLangs = environment.languages.filter((MyLangConfig) => MyLangConfig.active === true);
this.moreThanOneLanguage = (this.activeLangs.length > 1);
if (!this.moreThanOneLanguage) {
this.el.nativeElement.style.display = 'none';
}
}

/**
Expand Down

0 comments on commit c7c4b28

Please sign in to comment.