Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): clickable examples #666

Merged
merged 87 commits into from Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
2fb80da
feat(docs): clickable example POC add
32penkin Oct 4, 2019
c8cda4b
refactor(docs): docs displaying refactor
32penkin Oct 7, 2019
d8684a0
feat(doc): playground+examples
32penkin Oct 7, 2019
2dba717
feat(docs): processing refactor
32penkin Oct 7, 2019
2ed562e
feat(docs): height + themes HOC add
32penkin Oct 7, 2019
06fc541
docs(components): add radio and input live examples
Oct 7, 2019
2065932
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 7, 2019
00150ca
docs(components): fix input inline styling route
Oct 7, 2019
6455782
refactor(docs): examples-build refactor
32penkin Oct 8, 2019
908b887
refactor(docs): button/checkbox showcases screens navigation insert r…
32penkin Oct 8, 2019
087936c
feat(docs): docs navifation generation add
32penkin Oct 8, 2019
f346440
refactor(docs): auto-generating live-examples refactor
32penkin Oct 8, 2019
525b34b
feat(docs): toggle showcases add
32penkin Oct 8, 2019
e7148d2
feat(docs): avatar showcases add
32penkin Oct 8, 2019
78c77d0
feat(docs): layout showcases add
32penkin Oct 8, 2019
5490239
refactor(docs): checkbox showcases refactor
32penkin Oct 8, 2019
04f037a
refactor(docs): button showcases refactor
32penkin Oct 8, 2019
9246539
feat(docs): menu showcases add
32penkin Oct 9, 2019
18001f4
feat(docs): select showcases add
32penkin Oct 9, 2019
fea933d
feat(docs): button-group showcases add
32penkin Oct 9, 2019
4e733cf
feat(docs): radio-group showcases add
32penkin Oct 9, 2019
7520371
feat(docs): drawer showcases add
32penkin Oct 9, 2019
ee2b276
docs(components): add calendar and icon live examples
Oct 9, 2019
aff511b
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 9, 2019
99b36e9
feat(docs): bottom-navigation showcases shell prepare
32penkin Oct 9, 2019
218a190
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
32penkin Oct 9, 2019
2c5c835
feat(docs): bottom-navigation showcases add
32penkin Oct 9, 2019
7243b69
docs(components): move component examples to documentation live examp…
Oct 9, 2019
e0b9a17
refactor(docs): remove imports from index
32penkin Oct 10, 2019
b0bbb67
refactor(docs): remove documentation-showcases import file
32penkin Oct 10, 2019
7a3cf89
feat(docs): auto-generate of index.ts files for docs showcases add
32penkin Oct 10, 2019
17153bb
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 10, 2019
41823d5
refactor(docs): remove shit from index
32penkin Oct 10, 2019
32df7cb
refactor(docs): leave ability to have "only-code" examples
32penkin Oct 10, 2019
6d225fc
refactor(docs): modal showcases remove
32penkin Oct 10, 2019
162343f
Merge branch 'master' into feat/clickable-examples
32penkin Oct 10, 2019
1817bc7
feat(docs): checkbox indeterminate state showcase add
32penkin Oct 10, 2019
4bc552e
feat(playground): set OpenSans font as global application font
Oct 10, 2019
15398f0
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 10, 2019
3b1a9d2
feat(docs): doc-examples folder rename
32penkin Oct 10, 2019
c127a09
refactor(playground): remove android and ios dirs
Oct 10, 2019
cfd1d59
feat(docs): drawer with react-navigation example add
32penkin Oct 10, 2019
d88c271
docs(components): refactor avatar showcases
Oct 10, 2019
274685c
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
32penkin Oct 10, 2019
3b97276
docs(components): refactor button live examples
Oct 10, 2019
3af4758
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 10, 2019
39f64f4
docs(components): refactor button live exmaples
Oct 10, 2019
7c0512e
docs(components): refactor button-group live exmaples
Oct 10, 2019
7d80349
docs(components): refactor calendar live exmaples
Oct 10, 2019
32ac9ae
refactor(docs): checkbox/toggle showcases refactor
32penkin Oct 10, 2019
55f5ddc
docs(components): refactor datepicker live exmaples
Oct 10, 2019
8439236
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 10, 2019
8d4e6ad
docs(components): refactor drawer live exmaples
Oct 10, 2019
51fb4b5
docs(components): refactor input live exmaples
Oct 10, 2019
f95e265
docs(components): refactor list live exmaples
Oct 10, 2019
f3fab2f
docs(components): refactor menu live exmaples
Oct 10, 2019
a6246d0
docs(components): refactor overflow-menu live exmaples
Oct 10, 2019
e5bb80b
docs(components): refactor radio live exmaples
Oct 10, 2019
1fd8619
docs(components): refactor select live exmaples
Oct 10, 2019
4a17531
docs(components): refactor spinner live exmaples
Oct 10, 2019
3f95074
feat(docs): popover placement showcase add
32penkin Oct 10, 2019
e2c08c7
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
32penkin Oct 10, 2019
6ed63e7
docs(components): refactor checkbox live exmaples
Oct 10, 2019
9512695
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 10, 2019
188fd46
docs(components): refactor toggle live exmaples
Oct 10, 2019
721f9ee
docs(components): refactor text live exmaples
Oct 10, 2019
b70b712
feat(docs): tooltip placement showcase add
32penkin Oct 10, 2019
2f3cdc8
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
32penkin Oct 10, 2019
2f47b20
docs(components): refactor top-navigation live exmaples
Oct 10, 2019
850e38c
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 10, 2019
95fb1e9
refactor(playground): live example container appearance
Oct 10, 2019
ac01492
docs(components): refactor button live exmaples
Oct 10, 2019
2227417
docs(components): refactor input live exmaples
Oct 10, 2019
6b4a790
docs(components): refactor checkbox live exmaples
Oct 10, 2019
1ae65ff
docs(components): refactor radio live exmaples
Oct 10, 2019
9711eb0
docs(components): refactor toggle live exmaples
Oct 10, 2019
7919c48
docs(components): refactor row-directed examples to wrap container
Oct 10, 2019
17c433e
refactor(playground): add Powered by React Native Web label
Oct 10, 2019
bc46902
refactor(docs): select-status showcase refactor
32penkin Oct 11, 2019
40833bf
refactor(docs): list showcases refactor
32penkin Oct 11, 2019
494e992
refactor(docs): menu-simple-usage showcase refactor
32penkin Oct 11, 2019
4962431
refactor(docs): top-navigation-menu showcase refactor
32penkin Oct 11, 2019
d3a0326
refactor(docs): view-pager showcases refactor
32penkin Oct 11, 2019
6cbfad1
refactor(docs): radio docs structure refactor
32penkin Oct 11, 2019
efd8014
refactor(docs): radio docs structure revert
32penkin Oct 11, 2019
a036d7b
docs(components): refactor input and select simple usage examples
Oct 11, 2019
89cacd9
Merge branch 'feat/clickable-examples' of https://github.com/akveo/re…
Oct 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -12,6 +12,8 @@ npm-debug.log
# docs
docs/docs.json
docs/src/input.json
docs/src/assets/examples-build
docs/src/examples.json

# config
config/index.js
Expand Down
6 changes: 5 additions & 1 deletion docs/src/app/@theme/services/iframe-communicator.service.ts
Expand Up @@ -18,7 +18,11 @@ export class NgdIframeCommunicatorService {
public receive(id: string): Observable<any> {
return observableFromEvent(this.window, 'message')
.pipe(
filter((msg: any) => msg.data && msg.data.id === id),
filter((msg: any) => {
if (msg.data && msg.data.id && msg.data.id.length !== 0) {
return msg.data && msg.data.id === id
}
}),
map((msg: any) => msg.data),
);
}
Expand Down
43 changes: 41 additions & 2 deletions docs/src/app/@theme/services/structure.service.ts
Expand Up @@ -8,17 +8,24 @@ import { Inject, Injectable } from '@angular/core';

import { NgdTabbedService } from './tabbed.service';
import { NgdTextService } from './text.service';
import { DOCS, STRUCTURE } from '../../app.options';
import {
DOCS,
STRUCTURE,
EXAMPLES_STRUCTURE,
} from '../../app.options';

@Injectable()
export class NgdStructureService {

protected prepared;
protected examplesHelperArray: any[];

constructor(private textService: NgdTextService,
private tabbedService: NgdTabbedService,
@Inject(STRUCTURE) structure,
@Inject(DOCS) docs) {
@Inject(DOCS) docs,
@Inject(EXAMPLES_STRUCTURE) examples) {
this.examplesHelperArray = examples;
this.prepared = this.prepareStructure(structure, docs);
}

Expand Down Expand Up @@ -105,6 +112,9 @@ export class NgdStructureService {
images = imagesObj ? imagesObj.images : [];
}

component.overviewExamples = this.processExamples(component.overviewExamples);
component.examples = this.processExamples(component.examples);

return {
...component,
slag: this.textService.createSlag(component.name),
Expand All @@ -121,6 +131,35 @@ export class NgdStructureService {
};
}

protected processExamples(examples: any[]): any[] {
if (examples && examples.length !== 0) {
return examples
.map((example: any) => {
const helper: any = this.examplesHelperArray.find(item => {
return example.description === item.name;
});
return helper ? this.prepareExample(helper, example) : example;
})
.filter(Boolean);
} else {
return [];
}
}

protected prepareExample(helper: any, example: any): any {
return {
id: example.description,
name: example.description.split(/(?=[A-Z])/).join(' '),
files: [{
path: helper.path,
code: helper.code,
extension: helper.path.slice(helper.path.length - 3),
}],
code: helper.code,
url: `/assets/examples-build/#/${helper.name}`,
};
}

protected prepareToc(item: any) {
return item.children.reduce((acc: any[], child: any) => {
if (child.block === 'markdown') {
Expand Down
5 changes: 4 additions & 1 deletion docs/src/app/app.module.ts
Expand Up @@ -27,11 +27,13 @@ import { NgdAppComponent } from './app.component';
import { routes } from './app.routes';

import { structure } from '../structure';
const docs = require('../input.json');
const examples = require('../examples.json');
import {
DOCS,
STRUCTURE,
EXAMPLES_STRUCTURE,
} from './app.options';
const docs = require('../input.json');

@NgModule({
imports: [
Expand All @@ -58,6 +60,7 @@ const docs = require('../input.json');
Title,
{ provide: STRUCTURE, useValue: structure },
{ provide: DOCS, useValue: docs },
{ provide: EXAMPLES_STRUCTURE, useValue: examples },
],
entryComponents: [
],
Expand Down
1 change: 1 addition & 0 deletions docs/src/app/app.options.ts
Expand Up @@ -8,3 +8,4 @@ import { InjectionToken } from '@angular/core';

export const STRUCTURE = new InjectionToken<any>('Docs Structure');
export const DOCS = new InjectionToken<any>('Docs Structure');
export const EXAMPLES_STRUCTURE = new InjectionToken<any>('Docs Structure');
Expand Up @@ -16,8 +16,10 @@ import {
<nb-card [ngdFragment]="source.slag">
<nb-card-body>
<h2>{{ source.name }}</h2>
<ngd-stacked-example-block *ngIf="hasExamples()" [content]="examples"
class="widget-block">
<ngd-stacked-example-block
*ngFor="let example of source.examples"
[content]="example"
class="widget-block">
</ngd-stacked-example-block>
</nb-card-body>
</nb-card>
Expand All @@ -32,10 +34,9 @@ export class NgdExamplesBlockComponent {
@Input('source')
set setExamples(source: any) {
this.source = source;
this.examples = source.examples;
}

hasExamples(): boolean {
return this.examples.length !== 0;
return this.source.examples.length !== 0;
}
}
@@ -1,13 +1,6 @@
<section class="header" >
<strong class="title">{{ content.name }}</strong>
<div class="actions">

<div class="action-selector">
<select class="action-item" [(ngModel)]="currentTheme" (change)="switchTheme($event.target.value)">
<option *ngFor="let theme of themes" [value]="theme.value">{{theme.label}}</option>
</select>
<nb-icon icon="color-palette-outline"></nb-icon>
</div>
<a class="btn action-item action-button" target="_blank" [href]="url">
<nb-icon icon="external-link-outline"></nb-icon>
</a>
Expand Down
Expand Up @@ -35,30 +35,14 @@ export class NgdLiveExampleBlockComponent implements OnInit, AfterViewInit, OnDe
return this.currentTheme === 'default';
}

@HostBinding('class.theme-cosmic')
private get isCosmic() {
return this.currentTheme === 'cosmic';
}

@HostBinding('class.theme-corporate')
private get isCorporate() {
return this.currentTheme === 'corporate';
}

iframeHeight = 0;
alive: boolean = true;

themes: {label: string; value: string}[] = [
{ label: 'Default', value: 'default' },
{ label: 'Cosmic', value: 'cosmic' },
{ label: 'Corporate', value: 'corporate' },
];

currentTheme: string = 'default';
loading = true;

get url(): string {
return this.location.prepareExternalUrl(`example/${this.content.id}`);
return this.location.prepareExternalUrl(this.content.url);
}

get iframeWindow(): Window {
Expand Down Expand Up @@ -94,11 +78,6 @@ export class NgdLiveExampleBlockComponent implements OnInit, AfterViewInit, OnDe
this.alive = false;
}

switchTheme(theme: string) {
this.analytics.trackEvent('changeTheme', theme);
this.communicator.send({ id: this.content.id, theme }, this.iframeWindow);
}

switchToInlineVew() {
this.changeView.emit(NgdExampleView.INLINE);
}
Expand Down
Expand Up @@ -19,14 +19,11 @@ import {
<ng-container>
<div [innerHTML]="description"
[ngStyle]="hasImage && {'margin-bottom': '16px'}"></div>
<ngd-overview-example
<ngd-stacked-example-block
*ngFor="let example of source.overviewExamples"
[example]="example">
</ngd-overview-example>
<img
*ngFor="let image of images"
src={{image}}
/>
[content]="example"
class="widget-block">
</ngd-stacked-example-block>
</ng-container>
</ng-container>
</nb-card-body>
Expand All @@ -52,5 +49,4 @@ export class NgdOverviewBlockComponent {
this.images = source.images.map((image: string) => `assets/images/overview/${image}`);
return source;
}

}
@@ -1,38 +1,65 @@
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import {
Component,
Input,
} from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';

import { NgdExampleView } from '../../enum.example-view';
import { NgdAnalytics } from '../../../@theme/services';
import { animate, animation, keyframes, style, transition, trigger, useAnimation } from '@angular/animations';

export const pulse = animation(
animate(
'{{ timing }}s {{ delay }}s',
keyframes([
style({ transform: 'scale3d(1, 1, 1)' }),
style({ transform: 'scale3d({{ scale }}, {{ scale }}, {{ scale }})' }),
style({ transform: 'scale3d(1, 1, 1)' }),
]),
),
{ params: { scale: 1.02, timing: 0.5, delay: 0 } },
);

@Component({
selector: 'ngd-stacked-example-block',
template: `
<div>
<ngd-tabbed-example-block [content]="content"
<div *ngIf="isLiveExample">
<ngd-live-example-block [hidden]="!isLive"
[@exampleState]="isLive ? 'live': 'code'"
[content]="content"
hasViewSwitch="true"
(changeView)="changeView($event)">
</ngd-live-example-block>

<ngd-tabbed-example-block [hidden]="isLive"
[@exampleState]="isLive ? 'live': 'code'"
[content]="content"
hasViewSwitch="true"
(changeView)="changeView($event)">
</ngd-tabbed-example-block>
</div>
<div *ngIf="!isLiveExample">
<ngd-overview-example [example]="content">
</ngd-overview-example>
</div>
`,
animations: [
trigger('exampleState', [
transition('live => code', [
useAnimation(pulse),
]),
transition('code => live', [
useAnimation(pulse),
]),
]),
],
})
export class NgdStackedExampleComponent {
export class NgdStackedExampleComponent implements OnInit {

content: any;
@Input() content: any;
isLive = true;
isLiveExample: boolean;

@Input('content')
set setContent(source: any) {
this.content = source;
ngOnInit(): void {
this.isLiveExample = this.content.hasOwnProperty('id');
}

isLive = false;

constructor(private analytics: NgdAnalytics) {
}

Expand Down
@@ -1,7 +1,13 @@
<button type="button"
*ngIf="hasViewSwitch"
class="btn action-item action-button"
(click)="switchToLiveView()">
<nb-icon icon="image-outline"></nb-icon>
<span class="text">Live view</span>
</button>

<nb-tabset class="tabs-container">
<nb-tab *ngFor="let example of examples"
tabTitle="{{ example.description }}"
[active]="example.active">
<ngd-code-block [path]="example.path" [code]="example.code"></ngd-code-block>
<nb-tab *ngFor="let example of examples" tabTitle="{{ example.extension }}" [active]="example.active">
<ngd-code-block [code]="example.code"></ngd-code-block>
</nb-tab>
</nb-tabset>
Expand Up @@ -6,6 +6,8 @@ import {
Output,
EventEmitter,
} from '@angular/core';
import { forkJoin, of as observableOf, Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { NgdCodeLoaderService } from '../../../@theme/services';
import { NgdExampleView } from '../../enum.example-view';

Expand All @@ -20,24 +22,27 @@ export class NgdTabbedExampleBlockComponent {

@Input() hasViewSwitch = false;
@Output() changeView = new EventEmitter<NgdExampleView>();
examples: any[];
examples = [];

@Input()
set content(content: any) {
this.examples = content;
this.examples.map((item: any) => {
item.code = this.prepareCode(item.code);
item.path = 'path';
return item;
});
set content({ files }) {
this.examples = files;
this.examples[0].active = true;
}

constructor(private codeLoader: NgdCodeLoaderService, private cd: ChangeDetectorRef) {
}

private prepareCode(code: string): string {
return code.replace(/`/g, '');
switchToLiveView() {
this.changeView.emit(NgdExampleView.LIVE);
}

private load(path): Observable<any> {
const extension = path.split('.').pop();
return this.codeLoader.load(path)
.pipe(
map(code => ({ code, path, extension })),
catchError(e => observableOf('')),
);
}
}