Skip to content

Commit

Permalink
feat(demo): add advanced examples section
Browse files Browse the repository at this point in the history
  • Loading branch information
tomastrajan committed Aug 31, 2019
1 parent e6a8f26 commit c841ce2
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
"code",
"example"
]
},
{
"login": "mohammedzamakhan",
"name": "Zama Khan Mohammed",
"avatar_url": "https://avatars3.githubusercontent.com/u/2327532?v=4",
"profile": "https://www.linkedin.com/in/mohammedzamakhan",
"contributions": [
"code",
"ideas",
"test"
]
}
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ or submit a [pull request](https://github.com/angular-extensions/elements/pulls)

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars0.githubusercontent.com/u/3764868?v=4" width="100px;"/><br /><sub><b>Tomas Trajan</b></sub>](https://medium.com/@tomastrajan)<br />[💻](https://github.com/angular-extensions/elements/commits?author=tomastrajan "Code") [🎨](#design-tomastrajan "Design") [💡](#example-tomastrajan "Examples") [📖](https://github.com/angular-extensions/elements/commits?author=tomastrajan "Documentation") [🤔](#ideas-tomastrajan "Ideas, Planning, & Feedback") [🚇](#infra-tomastrajan "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/angular-extensions/elements/commits?author=tomastrajan "Tests") | [<img src="https://avatars2.githubusercontent.com/u/2899448?v=4" width="100px;"/><br /><sub><b>Wayne Maurer</b></sub>](http://www.lambda-it.ch)<br />[🐛](https://github.com/angular-extensions/elements/issues?q=author%3Awmaurer "Bug reports") [💻](https://github.com/angular-extensions/elements/commits?author=wmaurer "Code") | [<img src="https://avatars3.githubusercontent.com/u/11923975?v=4" width="100px;"/><br /><sub><b>Santosh Yadav</b></sub>](https://www.santoshyadav.dev)<br />[💻](https://github.com/angular-extensions/elements/commits?author=santoshyadav198613 "Code") [📦](#platform-santoshyadav198613 "Packaging/porting to new platform") | [<img src="https://avatars0.githubusercontent.com/u/16886711?v=4" width="100px;"/><br /><sub><b>David Dal Busco</b></sub>](https://twitter.com/daviddalbusco)<br />[💻](https://github.com/angular-extensions/elements/commits?author=peterpeterparker "Code") [💡](#example-peterpeterparker "Examples") |
| :---: | :---: | :---: | :---: |
| [<img src="https://avatars0.githubusercontent.com/u/3764868?v=4" width="100px;"/><br /><sub><b>Tomas Trajan</b></sub>](https://medium.com/@tomastrajan)<br />[💻](https://github.com/angular-extensions/elements/commits?author=tomastrajan "Code") [🎨](#design-tomastrajan "Design") [💡](#example-tomastrajan "Examples") [📖](https://github.com/angular-extensions/elements/commits?author=tomastrajan "Documentation") [🤔](#ideas-tomastrajan "Ideas, Planning, & Feedback") [🚇](#infra-tomastrajan "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/angular-extensions/elements/commits?author=tomastrajan "Tests") | [<img src="https://avatars2.githubusercontent.com/u/2899448?v=4" width="100px;"/><br /><sub><b>Wayne Maurer</b></sub>](http://www.lambda-it.ch)<br />[🐛](https://github.com/angular-extensions/elements/issues?q=author%3Awmaurer "Bug reports") [💻](https://github.com/angular-extensions/elements/commits?author=wmaurer "Code") | [<img src="https://avatars3.githubusercontent.com/u/11923975?v=4" width="100px;"/><br /><sub><b>Santosh Yadav</b></sub>](https://www.santoshyadav.dev)<br />[💻](https://github.com/angular-extensions/elements/commits?author=santoshyadav198613 "Code") [📦](#platform-santoshyadav198613 "Packaging/porting to new platform") | [<img src="https://avatars0.githubusercontent.com/u/16886711?v=4" width="100px;"/><br /><sub><b>David Dal Busco</b></sub>](https://twitter.com/daviddalbusco)<br />[💻](https://github.com/angular-extensions/elements/commits?author=peterpeterparker "Code") [💡](#example-peterpeterparker "Examples") | [<img src="https://avatars3.githubusercontent.com/u/2327532?v=4" width="100px;"/><br /><sub><b>Zama Khan Mohammed</b></sub>](https://www.linkedin.com/in/mohammedzamakhan)<br />[💻](https://github.com/angular-extensions/elements/commits?author=mohammedzamakhan "Code") [🤔](#ideas-mohammedzamakhan "Ideas, Planning, & Feedback") [⚠️](https://github.com/angular-extensions/elements/commits?author=mohammedzamakhan "Tests") |
| :---: | :---: | :---: | :---: | :---: |

<!-- ALL-CONTRIBUTORS-LIST:END -->
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const NAVIGATION = [
{
label: 'Basic',
url: 'examples/basic'
},
{
label: 'Advanced',
url: 'examples/advanced'
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,14 @@ <h2>
<img src="https://avatars0.githubusercontent.com/u/16886711?v=4" />
<span>David Dal Busco</span>
</a>

<a
class="contributor"
href="https://www.linkedin.com/in/mohammedzamakhan"
target="_blank"
>
<img src="https://avatars3.githubusercontent.com/u/2327532?v=4" />
<span>Zama Khan Mohammed</span>
</a>
<!-- ALL-CONTRIBUTORS-LIST:END -->
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { AdvancedComponent } from './advanced.component';

const routes: Routes = [{ path: '', component: AdvancedComponent }];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AdvancedRoutingModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<div class="wrapper">
<h1>Advanced</h1>

<h2>Elements configured in module</h2>
<div class="content">
<div class="implementation" *ngIf="!example1">
<button mat-flat-button color="accent" (click)="example1 = true">
<mat-icon>play_arrow</mat-icon>
Run
</button>
</div>
<div class="implementation" *ngIf="example1">
<ion-button *axLazyElement (click)="increment()">Click me</ion-button>
<p>Counter: {{ counter }}</p>
</div>
<div class="description">
<p>
In this example we're pre-configuring
<code>LazyElementsModule</code> with the element config. That way we
don't have to specify url of the element in the
<code>*axLazyElementDirective</code>. The element will be lazy-loaded
the same way as if we specified url directly.
</p>
<pre [highlight]="codeExample1html"></pre>
<pre [highlight]="codeExample1module"></pre>
</div>
</div>

<h2>Elements configured in module with options</h2>
<div class="content">
<div class="implementation" *ngIf="!example2">
<button mat-flat-button color="accent" (click)="example2 = true">
<mat-icon>play_arrow</mat-icon>
Run
</button>
</div>
<div class="implementation" *ngIf="example2">
<ng-template #loading>Loading...</ng-template>
<mwc-checkbox
*axLazyElement="null; module: true; loadingTemplate: loading"
>Click me</mwc-checkbox
>
</div>
<div class="description">
<p>
We don't have to specify <code>url</code> when using pre-configured
<code>LazyElementsModule</code>. We still might need to pass in
<code>null</code> url into <code>*axLazyElement</code> directive in case
we want to use other options like <code>module</code> or
<code>loadingTemplate</code>.
</p>
<pre [highlight]="codeExample2html"></pre>
<pre [highlight]="codeExample2module"></pre>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.wrapper {
display: flex;
flex-direction: column;

.content {
display: flex;
flex-direction: column;
margin: 0 0 50px 0;

.implementation {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex: 1;
margin: 0 20px 20px 0;
border: 2px solid #eee;
padding: 20px;

p {
margin: 10px 0 0 0;
}
}

.description {
flex: 1.5;
}
}
}

:host-context(.responsive-large) {
.wrapper {
width: 60%;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HighlightModule } from 'ngx-highlightjs';
import typescript from 'highlight.js/lib/languages/typescript';

import { LazyElementsModule } from '../../../../../../elements/src/lib/lazy-elements/lazy-elements.module';

import { AdvancedComponent } from './advanced.component';
import { SharedModule } from '../../../shared/shared.module';

describe('AdvancedComponent', () => {
let component: AdvancedComponent;
let fixture: ComponentFixture<AdvancedComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [
LazyElementsModule,
HighlightModule.forRoot({
languages: () => [{ name: 'typescript', func: typescript }]
}),
SharedModule
],
declarations: [AdvancedComponent]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AdvancedComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'demo-advanced',
templateUrl: './advanced.component.html',
styleUrls: ['./advanced.component.scss']
})
export class AdvancedComponent implements OnInit {
// example toggles
example1 = false;
example2 = false;

// example code examples
codeExample1module = CODE_EXAMPLE_1_MODULE;
codeExample1html = CODE_EXAMPLE_1_HTML;
codeExample2module = CODE_EXAMPLE_2_MODULE;
codeExample2html = CODE_EXAMPLE_2_HTML;

// example state
counter = 0;

constructor() {}

ngOnInit() {}

increment() {
this.counter++;
}
}

const CODE_EXAMPLE_1_MODULE = `// pre-configured LazyElementsModule
const options: LazyElementModuleOptions = {
elementConfigs: [
{ tag: 'ion-button', url: 'https://unpkg.com/@ionic/core@4.6.2/dist/ionic/ionic.js' }
]
};
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [FeatureComponent],
imports: [
LazyElementsModule.forFeature(options),
]
})
export class FeatureModule { }
`;

const CODE_EXAMPLE_1_HTML = `<!-- No need to specify url -->
<ion-button *axLazyElement></ion-button>`;

const CODE_EXAMPLE_2_MODULE = `// pre-configured LazyElementsModule
const options: LazyElementModuleOptions = {
elementConfigs: [
{ tag: 'mwc-checkbox', url: 'https://unpkg.com/@material/mwc-checkbox@0.6.0/mwc-checkbox.js?module' }
]
};
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [FeatureComponent],
imports: [
LazyElementsModule.forFeature(options),
]
})
export class FeatureModule { }
`;

const CODE_EXAMPLE_2_HTML = `<!-- We have to specify null; url to be able to pass in additional options -->
<mwc-checkbox *axLazyElement="null; module: true; loadingTemplate: loading;"></mwc-checkbox>`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { HighlightModule } from 'ngx-highlightjs';

import {
LazyElementModuleOptions,
LazyElementsModule
} from '../../../../../../elements/src/lib/lazy-elements/lazy-elements.module';

import { SharedModule } from '../../../shared/shared.module';

import { AdvancedRoutingModule } from './advanced-routing.module';
import { AdvancedComponent } from './advanced.component';

const options: LazyElementModuleOptions = {
elementConfigs: [
{
tag: 'ion-button',
url: 'https://unpkg.com/@ionic/core@4.6.2/dist/ionic/ionic.js'
},
{
tag: 'mwc-checkbox',
url:
'https://unpkg.com/@material/mwc-checkbox@0.6.0/mwc-checkbox.js?module'
}
]
};

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [AdvancedComponent],
imports: [
HighlightModule,
LazyElementsModule.forFeature(options),
SharedModule,
AdvancedRoutingModule
]
})
export class AdvancedModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export class BasicComponent implements OnInit {
example4 = false;
example5 = false;

// example state
counter = 0;
customYearValues = [2020, 2030, 2040];

// example code examples
codeExample1 = CODE_EXAMPLE_1;
codeExample2 = CODE_EXAMPLE_2;
codeExample3 = CODE_EXAMPLE_3;
codeExample4 = CODE_EXAMPLE_4;
codeExample5 = CODE_EXAMPLE_5;

// example state
counter = 0;
customYearValues = [2020, 2030, 2040];

constructor() {}

ngOnInit() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const routes: Routes = [
path: 'basic',
loadChildren: () =>
import('./basic/basic.module').then(m => m.BasicModule)
},
{
path: 'advanced',
loadChildren: () =>
import('./advanced/advanced.module').then(m => m.AdvancedModule)
}
]
}
Expand Down

0 comments on commit c841ce2

Please sign in to comment.