Skip to content

Commit

Permalink
feat(stark-ui): implementation of the app sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
catlabs committed Sep 5, 2018
1 parent f8d31cd commit ec279f0
Show file tree
Hide file tree
Showing 38 changed files with 808 additions and 126 deletions.
33 changes: 20 additions & 13 deletions packages/stark-ui/assets/styles/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
}
}

.stark-container {
max-width: $stark-max-content-width;
margin: 0 auto;
display: block;
width: 100%;
.stark-header-container {
padding: 0 15px;
}

.stark-main-container {
align-self: stretch;
padding-right: 15px;
padding-left: 15px;
}

@media screen {
Expand Down Expand Up @@ -113,6 +116,16 @@ h3 {
font-size: 14px;
}
}

.stark-main-container {
padding-left: 70px;
padding-right: 70px;
}

.stark-main-container {
align-self: center;
width: $stark-max-content-width;
}
}

/********** COLORS **********/
Expand All @@ -135,20 +148,14 @@ td {
border-bottom: solid 1px #fafafa;
}

.stark-container {
max-width: $stark-max-content-width;
margin: auto;
position: relative;
}

@media screen and (max-width: 1230px) {
.stark-header-extra,
.stark-page-header-actions {
margin-right: 15px;
}

.stark-container,
.stark-fixed-header-container .stark-generic-search .stark-generic-search-container .stark-container,
.stark-header-container,
.stark-fixed-header-container .stark-generic-search .stark-generic-search-container .stark-header-container,
.stark-table-action-bar-container {
box-sizing: border-box;
padding-left: 15px;
Expand Down
2 changes: 1 addition & 1 deletion packages/stark-ui/assets/styles/_old-variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $stark-header-size: 100px;
$stark-header-size-desktop: 128px;
$stark-header-actions-top: 78px;
$stark-header-actions-top-desktop: 106px;
$stark-max-content-width: 1200px;
$stark-max-content-width: 960px;

$primary-dark-text-color: map-get($mat-light-theme-foreground, base);
$secondary-dark-text-color: rgba(0, 0, 0, 0.7);
Expand Down
21 changes: 21 additions & 0 deletions packages/stark-ui/assets/themes/_menu-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@
color: map-get($mat-light-theme-foreground, disabled-button);
}
}

/* TODO: This code should be moved when the app menu is implemented */
stark-app-sidebar {
.stark-app-sidenav-menu {
background-color: #16385a;
.mat-nav-list {
padding-top: 0;
.mat-list-item {
color: #fff;
font-size: 13px;
&:hover a {
background-color: rgba($color: #fff, $alpha: 0.3);
}
}
.mat-list-item-focus.active,
a.active {
background-color: rgba($color: #fff, $alpha: 0.4);
}
}
}
}
3 changes: 2 additions & 1 deletion packages/stark-ui/src/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ export * from "./modules/action-bar";
export * from "./modules/app-logo";
export * from "./modules/app-logout";
export * from "./modules/breadcrumb";
export * from "./modules/app-sidebar";
export * from "./modules/keyboard-directives";
export * from "./modules/date-picker";
export * from "./modules/date-range-picker";
export * from "./modules/dropdown";
export * from "./modules/keyboard-directives";
export * from "./modules/pretty-print";
export * from "./modules/slider";
export * from "./modules/svg-view-box";
Expand Down
4 changes: 4 additions & 0 deletions packages/stark-ui/src/modules/app-sidebar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./app-sidebar/app-sidebar.module";
export * from "./app-sidebar/components";
export * from "./app-sidebar/services";
export * from "./app-sidebar/testing";
41 changes: 41 additions & 0 deletions packages/stark-ui/src/modules/app-sidebar/app-sidebar.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { NgModule, Optional, SkipSelf } from "@angular/core";
import { CommonModule } from "@angular/common";
import { MatSidenavModule } from "@angular/material/sidenav";
import { StarkAppSidebarComponent } from "./components";
import { STARK_APP_SIDEBAR_SERVICE, StarkAppSidebarServiceImpl } from "./services";
import { ModuleWithProviders } from "@angular/compiler/src/core";

@NgModule({
declarations: [StarkAppSidebarComponent],
imports: [CommonModule, MatSidenavModule],
exports: [StarkAppSidebarComponent]
})
export class StarkAppSidebarModule {
/**
* Instantiates the services only once since they should be singletons
* so the forRoot() should be called only by the AppModule
* @link https://angular.io/guide/singleton-services#forroot
* @returns a module with providers
*/
public static forRoot(): ModuleWithProviders {
return {
ngModule: StarkAppSidebarModule,
providers: [{ provide: STARK_APP_SIDEBAR_SERVICE, useClass: StarkAppSidebarServiceImpl }]
};
}

/**
* Prevents this module from being re-imported
* @link https://angular.io/guide/singleton-services#prevent-reimport-of-the-coremodule
* @param parentModule - the parent module
*/
public constructor(
@Optional()
@SkipSelf()
parentModule: StarkAppSidebarModule
) {
if (parentModule) {
throw new Error("StarkAppSidebarModule is already loaded. Import it in the AppModule only");
}
}
}
1 change: 1 addition & 0 deletions packages/stark-ui/src/modules/app-sidebar/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./components/app-sidebar.component";
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* ============================================================================== */
/* S t a r k A p p S i d e b a r - T h e m e */
/* ============================================================================== */
/* stark-ui: src/modules/app-sidebar/components/_app-sidebar-theme.scss */

/* END stark-ui: src/modules/app-sidebar/components/_app-sidebar-theme.scss */
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* ============================================================================== */
/* S t a r k A p p S i d e b a r */
/* ============================================================================== */
/* stark-ui: src/modules/app-sidebar/components/_app-sidebar.component.scss */

.stark-app-sidebar {
.mat-sidenav-content {
margin-top: $stark-header-size;
[stark-app-sidenav-content] {
align-items: center;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
}

.mat-sidenav-container {
min-height: 100%;
}

.mat-sidenav {
display: flex;
flex-direction: column;
justify-content: space-between;
}

.stark-app-sidenav-left {
width: 150px;
}
.stark-app-sidenav-right {
width: 300px;
}
.stark-app-sidenav-menu {
margin-top: $stark-header-size;
width: 200px;
}
}

@media #{$tablet-query} {
.stark-app-sidebar {
.stark-app-sidenav-menu,
.mat-sidenav-content {
margin-top: $stark-header-size-desktop;
}
}
}

/* END stark-ui: src/modules/app-sidebar/components/_app-sidebar.component.scss */
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<mat-sidenav-container #appSidenavContainer>
<mat-sidenav #appSidenavLeft class="stark-app-sidenav-left" [ngClass]="{'stark-app-sidenav-menu': sidenavLeftMode==='menu'}" mode="over" [fixedInViewport]="true"
[fixedBottomGap]="0">
<ng-container *ngIf="sidenavLeftMode==='regular'">
<ng-content class="regular" select="[stark-app-sidenav-left]"></ng-content>
</ng-container>
<ng-container class="menu" *ngIf="sidenavLeftMode==='menu'">
<ng-content select="[stark-app-sidenav-menu]"></ng-content>
</ng-container>
</mat-sidenav>
<mat-sidenav #appSidenavRight class="stark-app-sidenav-right" mode="over" position="end" [fixedInViewport]="true"
[fixedBottomGap]="0">
<ng-content select="[stark-app-sidenav-right]"></ng-content>
</mat-sidenav>
<mat-sidenav-content>
<ng-content select="[stark-app-sidenav-content]"></ng-content>
</mat-sidenav-content>
</mat-sidenav-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { CommonModule } from "@angular/common";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { MatSidenavModule } from "@angular/material/sidenav";
import { STARK_LOGGING_SERVICE } from "@nationalbankbelgium/stark-core";
import { MockStarkLoggingService } from "@nationalbankbelgium/stark-core/testing";
import { StarkAppSidebarComponent } from "./app-sidebar.component";
import { MockAppSidebarService } from "./../testing/app-sidebar.mock";
import { STARK_APP_SIDEBAR_SERVICE } from "./../services/app-sidebar.service.intf";

describe("AppSidebarComponent", () => {
let fixture: ComponentFixture<StarkAppSidebarComponent>;
let component: StarkAppSidebarComponent;

beforeEach(async(() => {
const mockLogger: MockStarkLoggingService = new MockStarkLoggingService();
return TestBed.configureTestingModule({
declarations: [StarkAppSidebarComponent],
imports: [CommonModule, MatSidenavModule, NoopAnimationsModule],
providers: [
{ provide: STARK_LOGGING_SERVICE, useValue: mockLogger },
{ provide: STARK_APP_SIDEBAR_SERVICE, useValue: new MockAppSidebarService() }
]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(StarkAppSidebarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

describe("sidenavs opening features ", () => {
it("left sidebar should be opened", () => {
component.onOpenSideNav({
sidebar: "left"
});
expect(component.appSidenavLeft.opened).toBe(true);
});

it("right sidebar should be opened", () => {
component.onOpenSideNav({
sidebar: "right"
});
expect(component.appSidenavRight.opened).toBe(true);
});

it("left sidebar should show the menu in menu mode", () => {
component.onOpenSideNav({
mode: "menu",
sidebar: "left"
});
fixture.detectChanges();
const sidenav: HTMLElement = fixture.nativeElement.querySelector(".stark-app-sidenav-menu");
expect(sidenav).toBeTruthy();
});

it("left sidebar should hide the menu in regular mode", () => {
component.onOpenSideNav({
mode: "regular",
sidebar: "left"
});
fixture.detectChanges();
const sidenav: HTMLElement = fixture.nativeElement.querySelector(".stark-app-sidenav-menu");
expect(sidenav).toBeFalsy();
});
});

describe("sidenavs closing features ", () => {
it("left sidebar should close", () => {
component.onOpenSideNav({
sidebar: "left"
});
component.onCloseSideNavs();
expect(component.appSidenavLeft.opened).toBe(false);
});

it("right sidebar should close", () => {
component.onOpenSideNav({
sidebar: "right"
});
component.onCloseSideNavs();
expect(component.appSidenavRight.opened).toBe(false);
});
});
});
Loading

0 comments on commit ec279f0

Please sign in to comment.