-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
393 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './transition'; | ||
export * from './transition.rxjs'; | ||
export * from './transition.directive'; | ||
export * from './transition.watcher.directive'; |
17 changes: 17 additions & 0 deletions
17
packages/dbx-core/src/lib/router/router/transition/transition.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Observable, startWith } from 'rxjs'; | ||
import { Directive, NgZone } from '@angular/core'; | ||
import { DbxRouterTransitionService } from '../service/router.transition.service'; | ||
import { successTransition } from './transition.rxjs'; | ||
|
||
/** | ||
* Abstract directive that listens to onSuccess transition events and runs a function. | ||
*/ | ||
@Directive() | ||
export abstract class AbstractTransitionDirective { | ||
|
||
readonly transitionSuccess$ = successTransition(this.dbNgxRouterTransitionService.transitions$); | ||
readonly initAndUpdateOnTransitionSuccess$: Observable<void> = this.transitionSuccess$.pipe(startWith(undefined)) as Observable<void>; | ||
|
||
constructor(protected readonly dbNgxRouterTransitionService: DbxRouterTransitionService) { } | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
packages/dbx-core/src/lib/router/router/transition/transition.rxjs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { filter, MonoTypeOperatorFunction, Observable } from "rxjs"; | ||
import { DbxRouterTransitionEvent, DbxRouterTransitionEventType } from "./transition"; | ||
|
||
/** | ||
* Convenience function for filtering success from the input observable. | ||
* | ||
* @param obs | ||
* @returns | ||
*/ | ||
export function successTransition(obs: Observable<DbxRouterTransitionEvent>): Observable<DbxRouterTransitionEvent> { | ||
return obs.pipe(filterTransitionSuccess()); | ||
} | ||
|
||
export function filterTransitionSuccess(): MonoTypeOperatorFunction<DbxRouterTransitionEvent> { | ||
return filterTransitionEvent(DbxRouterTransitionEventType.SUCCESS); | ||
} | ||
|
||
export function filterTransitionEvent(type: DbxRouterTransitionEventType): MonoTypeOperatorFunction<DbxRouterTransitionEvent> { | ||
return filter(x => x.type === type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './bar'; | ||
export * from './block'; | ||
export * from './card'; | ||
export * from './column'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './anchor'; | ||
export * from './sidenav'; | ||
export * from './layout.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { DbxAnchorModule } from './anchor/anchor.module'; | ||
import { DbxNavbarModule } from './navbar/navbar.module'; | ||
import { DbxSidenavModule } from './sidenav/sidenav.module'; | ||
|
||
@NgModule({ | ||
exports: [ | ||
DbxAnchorModule | ||
DbxAnchorModule, | ||
DbxNavbarModule, | ||
DbxSidenavModule | ||
] | ||
}) | ||
export class DbxRouterLayoutModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './navbar.component'; | ||
export * from './navbar.module'; |
19 changes: 19 additions & 0 deletions
19
packages/dbx-web/src/lib/router/layout/navbar/navbar.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<ng-container [ngSwitch]="mode$ | async"> | ||
<!-- Button --> | ||
<ng-container *ngSwitchCase="'button'"> | ||
<button mat-icon-button [matMenuTriggerFor]="menu" class="nav-menu-button" aria-label="open navigation"> | ||
<mat-icon>menu</mat-icon> | ||
</button> | ||
<mat-menu #menu> | ||
<dbx-anchor *ngFor="let x of anchors$ | async" [anchor]="x.anchor"> | ||
<button mat-menu-item [ngClass]="(x.selected) ? 'active' : ''">{{ x.anchor.title }}</button> | ||
</dbx-anchor> | ||
</mat-menu> | ||
</ng-container> | ||
<!-- Bar --> | ||
<nav *ngSwitchDefault mat-tab-nav-bar [attr.mat-align-tabs]="navAlign"> | ||
<dbx-anchor *ngFor="let x of anchors$ | async" [anchor]="x.anchor"> | ||
<a mat-tab-link [active]="x.selected">{{ x.anchor.title }}</a> | ||
</dbx-anchor> | ||
</nav> | ||
</ng-container> |
58 changes: 58 additions & 0 deletions
58
packages/dbx-web/src/lib/router/layout/navbar/navbar.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { Component, Input } from '@angular/core'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { UIRouterModule } from '@uirouter/angular'; | ||
import { DbxNavbarModule } from './navbar.module'; | ||
import { ClickableAnchorLink } from '@dereekb/dbx-core'; | ||
|
||
describe('NavbarComponent', () => { | ||
|
||
beforeEach(async () => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NoopAnimationsModule, | ||
DbxNavbarModule, | ||
UIRouterModule.forRoot() | ||
], | ||
declarations: [TestViewComponent] | ||
}).compileComponents(); | ||
}); | ||
|
||
let testComponent: TestViewComponent; | ||
let fixture: ComponentFixture<TestViewComponent>; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TestViewComponent); | ||
testComponent = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
describe('with links', () => { | ||
|
||
beforeEach(async () => { | ||
testComponent.links = [{ | ||
title: 'Test' | ||
}]; | ||
|
||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should render', () => { | ||
expect(true).toBe(true); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
@Component({ | ||
template: ` | ||
<app-nav-bar [links]="links"></app-nav-bar> | ||
` | ||
}) | ||
class TestViewComponent { | ||
|
||
@Input() | ||
public links?: ClickableAnchorLink[]; | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
packages/dbx-web/src/lib/router/layout/navbar/navbar.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Observable } from 'rxjs'; | ||
import { ScreenMediaWidthType, screenMediaWidthTypeIsActive } from './../../../screen/screen'; | ||
import { DbxScreenMediaService } from '../../../screen/screen.service'; | ||
import { Maybe } from '@dereekb/util'; | ||
import { Input, Component, NgZone, OnDestroy, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; | ||
import { ClickableAnchorLink, AbstractTransitionWatcherDirective, DbxRouterService, DbxRouterTransitionService, AbstractTransitionDirective, tapDetectChanges } from '@dereekb/dbx-core'; | ||
import { BehaviorSubject, combineLatest, map, shareReplay, distinctUntilChanged, startWith, tap } from 'rxjs'; | ||
|
||
interface NavAnchorLink { | ||
selected: boolean; | ||
anchor: ClickableAnchorLink; | ||
} | ||
|
||
export type NavBarContentAlign = 'center' | 'left' | 'right'; | ||
export type NavbarMode = 'bar' | 'button'; | ||
|
||
/** | ||
* Component that displays a navbar. | ||
*/ | ||
@Component({ | ||
selector: 'dbx-navbar', | ||
templateUrl: './navbar.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class DbxNavbarComponent extends AbstractTransitionDirective implements OnDestroy { | ||
|
||
@Input() | ||
navAlign = 'center'; | ||
|
||
private _inputMode = new BehaviorSubject<Maybe<NavbarMode>>(undefined); | ||
private _breakpoint = new BehaviorSubject<ScreenMediaWidthType>('large'); | ||
private _anchors = new BehaviorSubject<ClickableAnchorLink[]>([]); | ||
|
||
readonly isBreakpointActive$ = combineLatest([this._dbxScreenMediaService.widthType$, this._breakpoint]).pipe( | ||
map(([current, breakpoint]) => screenMediaWidthTypeIsActive(current, breakpoint)), | ||
distinctUntilChanged(), | ||
shareReplay(1) | ||
); | ||
|
||
readonly mode$ = combineLatest([this._inputMode, this.isBreakpointActive$]).pipe( | ||
map(([inputMode, breakpointActive]) => { | ||
return (breakpointActive) ? (inputMode ?? 'bar') : 'button'; | ||
}), | ||
distinctUntilChanged(), | ||
tapDetectChanges(this.cdr), | ||
shareReplay(1) | ||
); | ||
|
||
readonly anchors$: Observable<NavAnchorLink[]> = combineLatest([this._anchors, this.initAndUpdateOnTransitionSuccess$]).pipe( | ||
map(([anchors]) => { | ||
return anchors.map((anchor) => { | ||
let selected = this._dbxRouterService.isActive(anchor); | ||
|
||
return { | ||
selected, | ||
anchor | ||
}; | ||
}); | ||
}), | ||
tapDetectChanges(this.cdr), | ||
shareReplay(1) | ||
); | ||
|
||
constructor( | ||
dbxRouterTransitionService: DbxRouterTransitionService, | ||
private cdr: ChangeDetectorRef, | ||
private readonly _dbxScreenMediaService: DbxScreenMediaService, | ||
private readonly _dbxRouterService: DbxRouterService | ||
) { | ||
super(dbxRouterTransitionService); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this._inputMode.complete(); | ||
this._breakpoint.complete(); | ||
this._anchors.complete(); | ||
} | ||
|
||
// MARK: Accessors | ||
@Input() | ||
public set anchors(anchors: Maybe<ClickableAnchorLink[]>) { | ||
this._anchors.next(anchors ?? []); | ||
} | ||
|
||
@Input() | ||
public set mode(mode: Maybe<NavbarMode>) { | ||
this._inputMode.next(mode); | ||
} | ||
|
||
@Input() | ||
public set breakpoint(breakpoint: ScreenMediaWidthType) { | ||
this._breakpoint.next(breakpoint); | ||
} | ||
|
||
} |
Oops, something went wrong.