Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
feat(adoption): provide builder page to create StackBlitz demos
Browse files Browse the repository at this point in the history
Signed-off-by: Bozhidar Dryanovski <bozhidar.dryanovski@gmail.com>
  • Loading branch information
bdryanovski authored and bbogdanov committed Jan 5, 2022
1 parent 1be6169 commit dbeede0
Show file tree
Hide file tree
Showing 26 changed files with 685 additions and 131 deletions.
3 changes: 2 additions & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { LandingPage } from './pages/landing.page';
import { OverviewPage } from './pages/overview.page';
import { ApproachesPage } from './pages/approaches.page';
import { DifferencesPage } from './pages/differences.page';

import { TemplateBuilderPage } from './pages/template-builder.page';
export const componentRoutes = [
{ path: 'overview', component: OverviewPage },
{ path: 'accordion', component: AccordionPage },
Expand Down Expand Up @@ -88,6 +88,7 @@ export const getStartedRoutes = [
{ path: 'get-started', component: GettingStartedPage },
{ path: 'differences', component: DifferencesPage },
{ path: 'approaches', component: ApproachesPage },
{ path: 'builder', component: TemplateBuilderPage },
];

const routes: Routes = [
Expand Down
6 changes: 5 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import { ApproachesPage } from './pages/approaches.page';
import { MenuTitlePipe } from './pipes/menu-title.pipe';
import { OverviewPage } from './pages/overview.page';
import { DifferencesPage } from './pages/differences.page';
import { TemplateBuilderPage } from './pages/template-builder.page';
import { FormsModule } from '@angular/forms';

@NgModule({
declarations: [
Expand Down Expand Up @@ -105,6 +107,8 @@ import { DifferencesPage } from './pages/differences.page';
TooltipPage,
AdoptionToolingPage,

TemplateBuilderPage,

/* Interface Components */
EslintIntroBlockComponent,
SourceCodeComponent,
Expand All @@ -114,7 +118,7 @@ import { DifferencesPage } from './pages/differences.page';

MenuTitlePipe,
],
imports: [BrowserModule, BrowserAnimationsModule, CdsModule, AppRoutingModule, ClarityModule],
imports: [BrowserModule, BrowserAnimationsModule, FormsModule, CdsModule, AppRoutingModule, ClarityModule],
providers: [],
bootstrap: [AppComponent],
})
Expand Down
32 changes: 1 addition & 31 deletions src/app/components/demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,18 @@ import { SupportedTemplates } from '../templates';
// Icons
import {
ClarityIcons,
landscapeIcon,
boltIcon,
terminalIcon,
codeIcon,
betaIcon,
viewColumnsIcon,
} from '@cds/core/icon';

ClarityIcons.addIcons(landscapeIcon, boltIcon, terminalIcon, codeIcon, betaIcon, viewColumnsIcon);
ClarityIcons.addIcons(boltIcon);

export interface DemoTabData {
id?: string;
name: string;
files: { [filename: string]: string };
language?: SourceCodeLanguages;
template: SupportedTemplates;
}

// Generate Preview IDs
let PreviewID = 0;

@Component({
selector: 'demo',
template: `
Expand All @@ -60,31 +51,10 @@ let PreviewID = 0;
providers: [StackblitzService],
})
export class Demo {
inOverflow = true;

@Input('tabs') tabs: DemoTabData[] = [];

constructor(private stackblitz: StackblitzService) {}

ngOnInit(): void {
if (Array.isArray(this.tabs)) {
// auto attach unique id for every tab - later used for embedding the preview
this.tabs = this.tabs.map(tab => {
tab.id = this.generateId();
return tab;
});
}
}

/**
* Generate hash key for attaching preview container
*
* @returns number
*/
public generateId(): string {
return PreviewID++ + '';
}

public async openStackblitz(tab: DemoTabData): Promise<void> {
await this.stackblitz.open(tab.template, tab.files);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/sourcecode.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type SourceCodeLanguages = 'ts' | 'js' | 'html' | 'bash' | 'json' | undef
export class SourceCodeComponent {
@Input() content: string | null = '';
@Input() language: SourceCodeLanguages = 'ts';
@Input() src = '';
@Input() src: string = '' ;
formattedContent = '';

ngOnInit() {
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/accordion.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { DemoTabData } from '../components/demo.component';
</status-block>
<demo [tabs]="demo1">
<h3 cds-text="section">With expanded, disabled and exapandable panels</h3>
<h3 cds-text="section">With expanded, disabled and expandable panels</h3>
</demo>
`,
})
Expand All @@ -37,15 +37,15 @@ export class AccordionPage {
files: {
'src/app/app.component.ts': 'accordion/accordion.1.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'accordion/accordion.1.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand Down
12 changes: 6 additions & 6 deletions src/app/pages/alert.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export class AlertPage {
files: {
'src/app/app.component.ts': 'alert/alert.1.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'alert/alert.1.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -61,15 +61,15 @@ export class AlertPage {
files: {
'src/app/app.component.ts': 'alert/alert.2.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'alert/alert.2.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -80,15 +80,15 @@ export class AlertPage {
files: {
'src/app/app.component.ts': 'alert/alert.3.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'alert/alert.3.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/badge.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export class BadgePage {
files: {
'src/app/app.component.ts': 'badges/badge.1.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'badges/badge.1.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -50,15 +50,15 @@ export class BadgePage {
files: {
'src/app/app.component.ts': 'badges/badge.2.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'badges/badge.2.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand Down
24 changes: 12 additions & 12 deletions src/app/pages/button.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export class ButtonPage {
files: {
'src/app/app.component.ts': 'button/button.1.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'button/button.1.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -68,15 +68,15 @@ export class ButtonPage {
files: {
'src/app/app.component.ts': 'button/button.2.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'button/button.2.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -87,15 +87,15 @@ export class ButtonPage {
files: {
'src/app/app.component.ts': 'button/button.3.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'button/button.3.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -106,15 +106,15 @@ export class ButtonPage {
files: {
'src/app/app.component.ts': 'button/button.4.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'button/button.4.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -125,15 +125,15 @@ export class ButtonPage {
files: {
'src/app/app.component.ts': 'button/button.5.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'button/button.5.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -144,15 +144,15 @@ export class ButtonPage {
files: {
'src/app/app.component.ts': 'button/button.6.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'button/button.6.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/card.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export class CardPage {
files: {
'src/app/app.component.ts': 'card/card.1.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'card/card.1.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand All @@ -42,15 +42,15 @@ export class CardPage {
files: {
'src/app/app.component.ts': 'card/card.2.angular.txt',
},
language: 'ts',

template: 'angular',
},
{
name: 'Core',
files: {
'src/app/app.component.ts': 'card/card.2.core.txt',
},
language: 'ts',

template: 'core',
},
];
Expand Down
Loading

0 comments on commit dbeede0

Please sign in to comment.