Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
uzenith360 committed Jan 14, 2023
1 parent cbb340d commit 41caa80
Show file tree
Hide file tree
Showing 28 changed files with 432 additions and 0 deletions.
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.
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>
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!');
});
});
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();
}
}
}
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 projects/ngx-navigation-animation-example-app/src/index.html
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>
7 changes: 7 additions & 0 deletions projects/ngx-navigation-animation-example-app/src/main.ts
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));
6 changes: 6 additions & 0 deletions projects/ngx-navigation-animation-example-app/src/styles.css
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 projects/ngx-navigation-animation-example-app/tsconfig.app.json
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 projects/ngx-navigation-animation-example-app/tsconfig.spec.json
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"
]
}
24 changes: 24 additions & 0 deletions projects/ngx-navigation-animation/README.md
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.
7 changes: 7 additions & 0 deletions projects/ngx-navigation-animation/ng-package.json
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"
}
}
18 changes: 18 additions & 0 deletions projects/ngx-navigation-animation/package.json
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 projects/ngx-navigation-animation/src/lib/fade.animation.ts
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 }
)
])
]);
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();
});
});
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));
}
});
}
}
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%);
}
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>
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();
});
});
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 {

}
Loading

0 comments on commit 41caa80

Please sign in to comment.