Skip to content

Commit

Permalink
feat(demo): add examples content, make it runnable
Browse files Browse the repository at this point in the history
  • Loading branch information
tomastrajan committed Jul 23, 2019
1 parent 40977e0 commit abe3493
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 53 deletions.
3 changes: 2 additions & 1 deletion projects/elements-demo/src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HighlightModule } from 'ngx-highlightjs';
import typescript from 'highlight.js/lib/languages/typescript';
import xml from 'highlight.js/lib/languages/xml';

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

Expand All @@ -10,7 +11,7 @@ import { NavigationComponent } from './layout/navigation/navigation.component';
import { FooterComponent } from './layout/footer/footer.component';

export function hljsLanguages() {
return [{ name: 'typescript', func: typescript }];
return [{ name: 'typescript', func: typescript }, { name: 'xml', func: xml }];
}

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ const NAVIGATION = [
{
label: 'Basic',
url: 'examples/basic'
},
{
label: 'Lazy Loading',
url: 'examples/lazy'
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,70 @@
<h1>Basic</h1>
<div class="wrapper">
<h1>Basic</h1>

<div class="content">
<div class="implementation">
<ng-template #error>Loading failed...</ng-template>
<ng-template #loading>Loading...</ng-template>
<mwc-button
*axLazyElement="
'https://unpkg.com/@material/mwc-button@0.6.0/mwc-button.js?module';
loadingTemplate: loading;
errorTemplate: error;
module: true
"
raised
(click)="increment()"
>
Increment
</mwc-button>

Counter: {{ counter }}
<h2>Plain directive</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">
<mwc-icon
*axLazyElement="
'https://unpkg.com/@material/mwc-icon@0.6.0/mwc-icon.js?module';
module: true
"
>
favorite
</mwc-icon>
</div>
<div class="description">
<p>
The most simple example, all we need is to use element tag, for example
<code>&#60;mwc-icon></code> and add
<code>*axLazyElement</code> directive with the url pointing to the
element implementation.
</p>
<pre [highlight]="codeExample1"></pre>
</div>
</div>
<div class="description">
<p>
The most simple example, all we need is to use element tag, for example
<code>&#60;mwc-button></code> and add
<code>*axLazyElement</code> directive with the url pointing to the element
implementation.
</p>

<h2>Use loading <code>&#60;ng-template></code></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 #error>Loading failed...</ng-template>
<ng-template #loading>Loading...</ng-template>
<mwc-button
*axLazyElement="
'https://unpkg.com/@material/mwc-button@0.6.0/mwc-button.js?module';
loadingTemplate: loading;
errorTemplate: error;
module: true
"
raised
(click)="increment()"
>
Increment
</mwc-button>
<p>Counter: {{ counter }}</p>
</div>
<div class="description">
<p>
In this example we're loading
<code>&#60;mwc-button></code> using the
<code>*axLazyElement</code> directive but we're also adding
<code>&#60;ng-template #loading>Loading...&#60;ng-template></code> which
will display before the element was loaded (depending on your connection
speed)
</p>
<pre [highlight]="codeExample2"></pre>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
:host {
.wrapper {
display: flex;
flex-direction: column;

.content {
display: flex;
flex-wrap: wrap;
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
Expand Up @@ -6,8 +6,17 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./basic.component.scss']
})
export class BasicComponent implements OnInit {
// example toggles
example1 = false;
example2 = false;

// example state
counter = 0;

// example code examples
codeExample1 = CODE_EXAMPLE_1;
codeExample2 = CODE_EXAMPLE_2;

constructor() {}

ngOnInit() {}
Expand All @@ -16,3 +25,15 @@ export class BasicComponent implements OnInit {
this.counter++;
}
}

const CODE_EXAMPLE_1 = `<!-- url = 'https://unpkg.com/@material/mwc-icon@0.6.0/mwc-icon.js?module'; -->
<mwc-icon *axLazyElement="url; module: true">
favorite
</mwc-icon>`;

const CODE_EXAMPLE_2 = `<!-- url = 'https://unpkg.com/@material/mwc-button@0.6.0/mwc-button.js?module' -->;
<ng-template #loading>Loading...</ng-template>
<mwc-button *axLazyElement="url; loadingTemplate: loading; module: true"
(click)="increment()">
Increment
</mwc-button>`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { HighlightModule } from 'ngx-highlightjs';

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

Expand All @@ -8,6 +9,6 @@ import { BasicComponent } from './basic.component';
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [BasicComponent],
imports: [SharedModule, BasicRoutingModule]
imports: [HighlightModule, SharedModule, BasicRoutingModule]
})
export class BasicModule {}
5 changes: 3 additions & 2 deletions projects/elements-demo/src/app/features/home/home.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { HighlightModule } from 'ngx-highlightjs';

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

Expand All @@ -8,7 +9,7 @@ import { HomeComponent } from './home/home.component';
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [HomeComponent],
imports: [SharedModule, RouterModule],
imports: [RouterModule, HighlightModule, SharedModule],
exports: [HomeComponent]
})
export class HomeModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h2>Quickstart</h2>
<li>
Use <code>*axLazyElement</code> directive on an element you wish to load and
pass in the url of the element bundle
<pre [highlight]="codeExampleComponent"></pre>
</li>
</ol>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
margin: 50px 0 15px 0;
}

pre {
margin: 20px 0 0 0;
line-height: 1.3em;
}

mat-grid-list {
width: 100%;

Expand Down
44 changes: 27 additions & 17 deletions projects/elements-demo/src/app/features/home/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@ import { Observable } from 'rxjs';

import { ResponsiveLayoutService } from '../../../core/layout/responsive-layout.service';

@Component({
selector: 'demo-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
columnCount: Observable<number>;

features = FEATURES;
codeExampleComponent = CODE_EXAMPLE_COMPONENT;

constructor(private responsiveLayoutService: ResponsiveLayoutService) {}

ngOnInit() {
this.columnCount = this.responsiveLayoutService.columnCount;
}
}

const CODE_EXAMPLE_COMPONENT = `@Component({
selector: 'your-org-feature',
template: '<some-element *axLazyElement="elementUrl"></some-element>'
})
export class FeatureComponent {
elementUrl = 'https://your-org.com/elements/some-element.js';
}
`;

const FEATURES = [
{
title: 'Lightweight',
Expand Down Expand Up @@ -47,20 +74,3 @@ const FEATURES = [
icon: 'category'
}
];

@Component({
selector: 'demo-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
columnCount: Observable<number>;

features = FEATURES;

constructor(private responsiveLayoutService: ResponsiveLayoutService) {}

ngOnInit() {
this.columnCount = this.responsiveLayoutService.columnCount;
}
}

0 comments on commit abe3493

Please sign in to comment.