-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
cbb340d
commit 41caa80
Showing
28 changed files
with
432 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
projects/ngx-navigation-animation-example-app/src/app/app-routing.module.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,10 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule, Routes } from '@angular/router'; | ||
|
||
const routes: Routes = []; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forRoot(routes)], | ||
exports: [RouterModule] | ||
}) | ||
export class AppRoutingModule { } |
Empty file.
4 changes: 4 additions & 0 deletions
4
projects/ngx-navigation-animation-example-app/src/app/app.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,4 @@ | ||
<app-navigation-animation *ngIf="true"></app-navigation-animation> | ||
<main [@fadeAnimation]="getRouterOutletState(o)"> | ||
<router-outlet #o="outlet"></router-outlet> | ||
</main> |
35 changes: 35 additions & 0 deletions
35
projects/ngx-navigation-animation-example-app/src/app/app.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,35 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { AppComponent } from './app.component'; | ||
|
||
describe('AppComponent', () => { | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
AppComponent | ||
], | ||
}).compileComponents(); | ||
}); | ||
|
||
it('should create the app', () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
const app = fixture.componentInstance; | ||
expect(app).toBeTruthy(); | ||
}); | ||
|
||
it(`should have as title 'ngx-navigation-animation-example-app'`, () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
const app = fixture.componentInstance; | ||
expect(app.title).toEqual('ngx-navigation-animation-example-app'); | ||
}); | ||
|
||
it('should render title', () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
fixture.detectChanges(); | ||
const compiled = fixture.nativeElement as HTMLElement; | ||
expect(compiled.querySelector('.content span')?.textContent).toContain('ngx-navigation-animation-example-app app is running!'); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
projects/ngx-navigation-animation-example-app/src/app/app.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,63 @@ | ||
import { Component } from '@angular/core'; | ||
import { fadeAnimation, NavigateEventService } from 'ngx-navigation-animation'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'], | ||
animations: [fadeAnimation] | ||
}) | ||
export class AppComponent { | ||
public isPageLoading: boolean = false; | ||
public page: string = document.location.pathname; | ||
public title = 'ngx-navigation-animation-example-app'; | ||
|
||
private navigateEventServiceSubscription!: Subscription; | ||
private navigateEventServiceStartSubscription!: Subscription; | ||
private navigateEventServiceStopSubscription!: Subscription; | ||
|
||
constructor(private navigateEventService: NavigateEventService,){ | ||
this.navigateEventServiceSubscription = this.navigateEventService.navigation$.subscribe( | ||
(navigation) => { | ||
this.page = /*JSON.parse(navigation).url*/document.location.pathname; | ||
} | ||
); | ||
|
||
this.navigateEventServiceStartSubscription = this.navigateEventService | ||
.navigationStart$ | ||
.subscribe( | ||
(navigation) => { | ||
this.isPageLoading = true; | ||
} | ||
); | ||
|
||
this.navigateEventServiceStopSubscription = this.navigateEventService | ||
.navigationStop$ | ||
.subscribe( | ||
(navigation) => { | ||
setTimeout(() => { | ||
this.isPageLoading = false; | ||
}, 0); | ||
} | ||
); | ||
} | ||
|
||
public getRouterOutletState(outlet: { isActivated: any; activatedRoute: any; }): void { | ||
return outlet.isActivated ? outlet.activatedRoute : ''; | ||
} | ||
|
||
ngOnDestroy(): void { | ||
if (this.navigateEventServiceSubscription) { | ||
this.navigateEventServiceSubscription.unsubscribe(); | ||
} | ||
|
||
if (this.navigateEventServiceStartSubscription) { | ||
this.navigateEventServiceStartSubscription.unsubscribe(); | ||
} | ||
|
||
if (this.navigateEventServiceStopSubscription) { | ||
this.navigateEventServiceStopSubscription.unsubscribe(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
projects/ngx-navigation-animation-example-app/src/app/app.module.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 { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgxNavigationAnimationModule } from 'ngx-navigation-animation'; | ||
|
||
import { AppRoutingModule } from './app-routing.module'; | ||
import { AppComponent } from './app.component'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
NgxNavigationAnimationModule, | ||
BrowserModule, | ||
AppRoutingModule | ||
], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } |
Empty file.
Binary file not shown.
13 changes: 13 additions & 0 deletions
13
projects/ngx-navigation-animation-example-app/src/index.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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>NgxNavigationAnimationExampleApp</title> | ||
<base href="/"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/x-icon" href="favicon.ico"> | ||
</head> | ||
<body> | ||
<app-root></app-root> | ||
</body> | ||
</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,7 @@ | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
|
||
import { AppModule } from './app/app.module'; | ||
|
||
|
||
platformBrowserDynamic().bootstrapModule(AppModule) | ||
.catch(err => console.error(err)); |
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,6 @@ | ||
/* You can add global styles to this file, and also import other style files */ | ||
body { | ||
height: 100vh; | ||
margin: 0; | ||
padding: 0; | ||
} |
14 changes: 14 additions & 0 deletions
14
projects/ngx-navigation-animation-example-app/tsconfig.app.json
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,14 @@ | ||
/* To learn more about this file see: https://angular.io/config/tsconfig. */ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../out-tsc/app", | ||
"types": [] | ||
}, | ||
"files": [ | ||
"src/main.ts" | ||
], | ||
"include": [ | ||
"src/**/*.d.ts" | ||
] | ||
} |
14 changes: 14 additions & 0 deletions
14
projects/ngx-navigation-animation-example-app/tsconfig.spec.json
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,14 @@ | ||
/* To learn more about this file see: https://angular.io/config/tsconfig. */ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../out-tsc/spec", | ||
"types": [ | ||
"jasmine" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.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,24 @@ | ||
# NgxNavigationAnimation | ||
|
||
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 15.0.0. | ||
|
||
## Code scaffolding | ||
|
||
Run `ng generate component component-name --project ngx-navigation-animation` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-navigation-animation`. | ||
> Note: Don't forget to add `--project ngx-navigation-animation` or else it will be added to the default project in your `angular.json` file. | ||
## Build | ||
|
||
Run `ng build ngx-navigation-animation` to build the project. The build artifacts will be stored in the `dist/` directory. | ||
|
||
## Publishing | ||
|
||
After building your library with `ng build ngx-navigation-animation`, go to the dist folder `cd dist/ngx-navigation-animation` and run `npm publish`. | ||
|
||
## Running unit tests | ||
|
||
Run `ng test ngx-navigation-animation` to execute the unit tests via [Karma](https://karma-runner.github.io). | ||
|
||
## Further help | ||
|
||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. |
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,7 @@ | ||
{ | ||
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json", | ||
"dest": "../../dist/ngx-navigation-animation", | ||
"lib": { | ||
"entryFile": "src/public-api.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,18 @@ | ||
{ | ||
"name": "ngx-navigation-animation", | ||
"version": "0.0.1", | ||
"peerDependencies": { | ||
"@angular/common": "^15.0.0", | ||
"@angular/core": "^15.0.0", | ||
"@angular/cdk": "^15.0.0", | ||
"@angular/animations": "^15.0.0", | ||
"@angular/material": "^15.0.3", | ||
"@angular/platform-browser": "^15.0.4", | ||
"@angular/platform-browser-dynamic": "^15.0.4", | ||
"@angular/router": "^15.0.4", | ||
"rxjs": "~7.5.0" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.3.0" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
projects/ngx-navigation-animation/src/lib/fade.animation.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,27 @@ | ||
import { trigger, animate, transition, style, query } from '@angular/animations'; | ||
|
||
export const fadeAnimation = | ||
trigger('fadeAnimation', [ | ||
transition('* => *', [ | ||
query(':enter', | ||
[ | ||
style({ opacity: 0 }) | ||
], | ||
{ optional: true } | ||
), | ||
query(':leave', | ||
[ | ||
style({ opacity: 1 }), | ||
animate('0.1s', style({ opacity: 0 })) | ||
], | ||
{ optional: true } | ||
), | ||
query(':enter', | ||
[ | ||
style({ opacity: 0 }), | ||
animate('0.1s', style({ opacity: 1 })) | ||
], | ||
{ optional: true } | ||
) | ||
]) | ||
]); |
16 changes: 16 additions & 0 deletions
16
projects/ngx-navigation-animation/src/lib/navigate-event.service.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,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NavigateEventService } from './navigate-event.service'; | ||
|
||
describe('NavigateEventService', () => { | ||
let service: NavigateEventService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(NavigateEventService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
projects/ngx-navigation-animation/src/lib/navigate-event.service.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,34 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Router, Event as NavigationEvent, NavigationEnd, NavigationStart, NavigationCancel, NavigationError } from '@angular/router'; | ||
import { Subject } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class NavigateEventService { | ||
// Observable string sources | ||
private NavigationSource = new Subject<string>(); | ||
private NavigationStartSource = new Subject<string>(); | ||
private NavigationStopSource = new Subject<string>(); | ||
|
||
// Observable string streams | ||
navigation$ = this.NavigationSource.asObservable(); | ||
navigationStart$ = this.NavigationStartSource.asObservable(); | ||
navigationStop$ = this.NavigationStopSource.asObservable(); | ||
|
||
constructor(private router: Router) { | ||
this.router.events | ||
.subscribe( | ||
(event: NavigationEvent) => { | ||
if (event instanceof NavigationEnd) { | ||
this.NavigationSource.next(JSON.stringify(event)); | ||
} else if (event instanceof NavigationStart) { | ||
this.NavigationStartSource.next(JSON.stringify(event)); | ||
} | ||
|
||
if (event instanceof NavigationEnd || event instanceof NavigationCancel || event instanceof NavigationError) { | ||
this.NavigationStopSource.next(JSON.stringify(event)); | ||
} | ||
}); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
.../ngx-navigation-animation/src/lib/navigation-animation/navigation-animation.component.css
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,6 @@ | ||
.spinnerContainer { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
} |
6 changes: 6 additions & 0 deletions
6
...ngx-navigation-animation/src/lib/navigation-animation/navigation-animation.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,6 @@ | ||
<div> | ||
<mat-progress-bar color="primary" mode="indeterminate"></mat-progress-bar> | ||
</div> | ||
<div class="spinnerContainer"> | ||
<mat-progress-spinner diameter="40" color="primary" mode="indeterminate"></mat-progress-spinner> | ||
</div> |
30 changes: 30 additions & 0 deletions
30
...-navigation-animation/src/lib/navigation-animation/navigation-animation.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,30 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { MatProgressBar, MatProgressBarModule } from '@angular/material/progress-bar'; | ||
import { MatProgressSpinner, MatProgressSpinnerModule } from '@angular/material/progress-spinner'; | ||
|
||
import { NavigationAnimationComponent } from './navigation-animation.component'; | ||
|
||
describe('NavigationAnimationComponent', () => { | ||
let component: NavigationAnimationComponent; | ||
let fixture: ComponentFixture<NavigationAnimationComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ NavigationAnimationComponent ], | ||
imports:[MatProgressBarModule, MatProgressSpinnerModule], | ||
providers:[ | ||
// { provide: MatProgressBar, useValue: {} }, | ||
// { provide: MatProgressSpinner, useValue: {} }, | ||
] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(NavigationAnimationComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
...s/ngx-navigation-animation/src/lib/navigation-animation/navigation-animation.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,10 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-navigation-animation', | ||
templateUrl: './navigation-animation.component.html', | ||
styleUrls: ['./navigation-animation.component.css'] | ||
}) | ||
export class NavigationAnimationComponent { | ||
|
||
} |
Oops, something went wrong.