Skip to content

Commit

Permalink
fix(demo): use new sidebar implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
damienwebdev committed Jul 21, 2023
1 parent 22d293c commit e1a6122
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<daff-sidebar-viewport (backdropClicked)="close()" mode="over" [opened]="showSidebar$ | async">
<demo-sidebar ngProjectAs="daff-sidebar"></demo-sidebar>
<daff-sidebar-viewport (backdropClicked)="close()">
<demo-sidebar ngProjectAs="daff-sidebar:not([side='right'])" side="left" mode="under" [open]="showSidebar$ | async"></demo-sidebar>
<ng-content></ng-content>
</daff-sidebar-viewport>
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Component } from '@angular/core';
import {
Component,
Input,
} from '@angular/core';
import {
waitForAsync,
ComponentFixture,
Expand All @@ -13,8 +16,10 @@ import {

import {
DaffSidebarModule,
DaffSidebarSide,
DaffSidebarViewportComponent,
} from '@daffodil/design';
import { DaffSidebarMode } from '@daffodil/design';

import {
ToggleSidebar,
Expand All @@ -26,7 +31,14 @@ import * as fromDemoSidebar from '../../reducers';
import { SidebarViewportContainer } from './sidebar-viewport.component';

@Component({ selector: 'demo-sidebar', template: '' })
class MockSidebarContainer {}
class MockSidebarContainer {
@Input() side: DaffSidebarSide;

@Input() mode: DaffSidebarMode;

@Input() open: boolean;

}

describe('SidebarViewportContainer', () => {
let component: SidebarViewportContainer;
Expand Down Expand Up @@ -74,8 +86,8 @@ describe('SidebarViewportContainer', () => {
expect(component).toBeTruthy();
});

it('should set the `daff-sidebar-viewport` mode to over', () => {
expect(sidebarViewport.mode).toEqual('over');
it('should set the `daff-sidebar` mode to under', () => {
expect(sidebarContainer.mode).toEqual('under');
});

it('should call close when the `daff-sidebar-viewport` emits `backdropClicked`', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<daff-sidebar class="demo-sidebar" (escapePressed)="onClose()">
<daff-sidebar class="demo-sidebar" [side]="side" [mode]="mode" (escapePressed)="onClose()" [open]="open">
<span class="demo-sidebar__close" (click)="onClose()"><fa-icon [icon]="faTimes"></fa-icon></span>
<demo-sidebar-list [tree]="tree$ | async" *ngIf="(treeLoading$ | async) === false"></demo-sidebar-list>
<div class="demo-sidebar__error" *ngFor="let error of (treeErrors$ | async)"> {{ error }}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TestBed,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { provideMockStore } from '@ngrx/store/testing';
import {
Expand Down Expand Up @@ -49,6 +50,7 @@ describe('SidebarContainer', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
DaffSidebarModule,
FontAwesomeModule,
DaffLoadingIconModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import {
ChangeDetectionStrategy,
Component,
forwardRef,
Input,
OnInit,
ViewChild,
} from '@angular/core';
import { faTimes } from '@fortawesome/free-solid-svg-icons';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';

import { DaffStateError } from '@daffodil/core/state';
import {
DaffSidebarSide,
DaffSidebarMode,
DaffSidebarComponent,
} from '@daffodil/design';
import { DaffNavigationTree } from '@daffodil/navigation';
import {
DaffNavigationFacade,
Expand All @@ -20,8 +29,23 @@ import * as fromDemoSidebar from '../../reducers/index';
selector: 'demo-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.scss'],
// eslint-disable-next-line @typescript-eslint/no-use-before-define
providers: [{ provide: DaffSidebarComponent, useExisting: forwardRef(() => SidebarContainer ) }],
})
export class SidebarContainer implements OnInit {

@Input() side: DaffSidebarSide;

@Input() mode: DaffSidebarMode;

@Input() open: boolean;

@ViewChild(DaffSidebarComponent) sidebar: DaffSidebarComponent;

get width() {
return this.sidebar.width;
}

faTimes = faTimes;
tree$: Observable<DaffNavigationTree>;
treeLoading$: Observable<boolean>;
Expand Down

0 comments on commit e1a6122

Please sign in to comment.