Skip to content

Commit

Permalink
Prepare custom default loading example
Browse files Browse the repository at this point in the history
  • Loading branch information
fboeller committed Mar 7, 2021
1 parent cc2fbb0 commit 7944cfb
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 6 deletions.
1 change: 1 addition & 0 deletions projects/example-app/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ <h1>Example App</h1>
<app-lightweight-example></app-lightweight-example>
<app-default-example></app-default-example>
<app-custom-loading-template-example></app-custom-loading-template-example>
<app-custom-default-loading-example></app-custom-default-loading-example>
<app-ngrx-example></app-ngrx-example>
</div>
2 changes: 2 additions & 0 deletions projects/example-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { NgrxExampleModule } from './examples/ngrx-example/ngrx-example.module';
import { CustomLoadingTemplateExampleModule } from './examples/custom-loading-template-example/custom-loading-template-example.module';
import { DefaultExampleModule } from './examples/default-example/default-example.module';
import { LightweightExampleModule } from './examples/lightweight-example/lightweight-example.module';
import { CustomDefaultLoadingExampleModule } from './examples/custom-default-loading-example/custom-default-loading-example.module';

@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
NgrxExampleModule,
CustomLoadingTemplateExampleModule,
CustomDefaultLoadingExampleModule,
DefaultExampleModule,
LightweightExampleModule,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2>Custom default loading template</h2>
<p>
This example displays the usage of the `ld-loadable` component with a loading
component that is registered as a default for all `ld-loadable` components in
that module.
</p>
<app-load-form (loadable)="loadable = $event"></app-load-form>
<ld-loadable [loadable]="loadable">
<h3>Loaded</h3>
<pre>{{ loadable | loadedValue | json }}</pre>
</ld-loadable>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component } from '@angular/core';
import { idle } from 'projects/ngx-loadable/src/lib/loadable.constructors';
import { Loadable } from 'projects/ngx-loadable/src/lib/loadable.type';

@Component({
selector: 'app-custom-default-loading-example',
templateUrl: './custom-default-loading-example.component.html',
})
export class CustomDefaultLoadingExampleComponent {
loadable: Loadable<object> = idle;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { LoadableModule } from 'projects/ngx-loadable/src/lib/angular/loadable.module';
import { LoadFormModule } from '../../load-form/load-form.module';
import { CustomDefaultLoadingExampleComponent } from './custom-default-loading-example.component';
import { LoadingSpinnerComponent } from './loading-spinner/loading-spinner.component';

@NgModule({
declarations: [CustomDefaultLoadingExampleComponent, LoadingSpinnerComponent],
imports: [BrowserModule, LoadFormModule, LoadableModule],
exports: [CustomDefaultLoadingExampleComponent],
})
export class CustomDefaultLoadingExampleModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.lds-facebook {
display: inline-block;
position: relative;
width: 80px;
height: 80px;
}
.lds-facebook div {
display: inline-block;
position: absolute;
left: 8px;
width: 16px;
background: #fff;
animation: lds-facebook 1.2s cubic-bezier(0, 0.5, 0.5, 1) infinite;
}
.lds-facebook div:nth-child(1) {
left: 8px;
animation-delay: -0.24s;
}
.lds-facebook div:nth-child(2) {
left: 32px;
animation-delay: -0.12s;
}
.lds-facebook div:nth-child(3) {
left: 56px;
animation-delay: 0;
}
@keyframes lds-facebook {
0% {
top: 8px;
height: 64px;
}
50%,
100% {
top: 24px;
height: 32px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="lds-facebook">
<div></div>
<div></div>
<div></div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h2>Lightweight example</h2>
</p>
<app-load-form (loadable)="loadable = $event"></app-load-form>
<ng-container [ngSwitch]="loadable | loadingState">
<app-loading-spinner *ngSwitchCase="'loading'"></app-loading-spinner>
<ld-loadable-loading *ngSwitchCase="'loading'"></ld-loadable-loading>
<div *ngSwitchCase="'loaded'">
<h3>Loaded</h3>
<pre>{{ loadable | loadedValue | json }}</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { NgModule } from '@angular/core';

import { LoadableModule } from 'projects/ngx-loadable/src/lib/angular/loadable.module';
import { LightweightExampleComponent } from './lightweight-example.component';
import { LoadingSpinnerComponent } from './loading-spinner/loading-spinner.component';
import { LoadFormModule } from '../../load-form/load-form.module';

@NgModule({
declarations: [LoadingSpinnerComponent, LightweightExampleComponent],
declarations: [LightweightExampleComponent],
imports: [BrowserModule, LoadFormModule, LoadableModule],
exports: [LightweightExampleComponent],
})
Expand Down
Empty file.

This file was deleted.

4 changes: 3 additions & 1 deletion projects/ngx-loadable/src/lib/angular/loadable.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import { defaultComponents, DefaultComponents } from './module.options';

export const DEFAULT_COMPONENTS = new InjectionToken<DefaultComponents>(
'DEFAULT_COMPONENTS',
{ factory: () => defaultComponents }
{
factory: () => defaultComponents,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export class LoadableComponent implements OnChanges {
constructor(
private resolver: ComponentFactoryResolver,
@Inject(DEFAULT_COMPONENTS) private defaultComponents: DefaultComponents
) {}
) {
console.log(this.defaultComponents);
}

updateContent(loadable: Loadable<unknown>): void {
const defaultComponent = this.defaultComponents[getLoadingState(loadable)];
Expand Down

0 comments on commit 7944cfb

Please sign in to comment.