From 24dbdee853e5e0cba3a10cccb0a4356273203b55 Mon Sep 17 00:00:00 2001 From: matthiashader <144090716+matthiashader@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:00:33 +0200 Subject: [PATCH] docs(modal): adapted preview examples for angular modal (#1478) --- .../preview-examples/echarts-empty-state.ts | 2 +- .../modal-by-instance-content.ts | 2 +- .../src/preview-examples/modal-by-instance.ts | 2 +- .../src/preview-examples/modal-sizes.html | 21 +--------- packages/documentation/docs/controls/modal.md | 29 ++++++++++--- .../src/components/PlaygroundV3/index.tsx | 5 ++- .../documentation/src/utils/stackblitz.ts | 41 ++++++++++++++++++- 7 files changed, 70 insertions(+), 32 deletions(-) diff --git a/packages/angular-test-app/src/preview-examples/echarts-empty-state.ts b/packages/angular-test-app/src/preview-examples/echarts-empty-state.ts index bedd1f28b0..d17ca27d19 100644 --- a/packages/angular-test-app/src/preview-examples/echarts-empty-state.ts +++ b/packages/angular-test-app/src/preview-examples/echarts-empty-state.ts @@ -16,7 +16,7 @@ import { EChartsOption } from 'echarts'; @Component({ selector: 'app-example', templateUrl: './echarts-empty-state.html', - styleUrls: ["./styles/charts.css"], + styleUrls: ["./styles/charts-empty-state.css"], }) export default class EchartsLineSimple implements OnInit { theme = convertThemeName(themeSwitcher.getCurrentTheme()); diff --git a/packages/angular-test-app/src/preview-examples/modal-by-instance-content.ts b/packages/angular-test-app/src/preview-examples/modal-by-instance-content.ts index 38be1ab301..f97cfee5e3 100644 --- a/packages/angular-test-app/src/preview-examples/modal-by-instance-content.ts +++ b/packages/angular-test-app/src/preview-examples/modal-by-instance-content.ts @@ -11,7 +11,7 @@ import { Component } from '@angular/core'; import { IxActiveModal } from '@siemens/ix-angular'; @Component({ - selector: 'app-example', + selector: 'app-example-content', template: ` Message headline diff --git a/packages/angular-test-app/src/preview-examples/modal-by-instance.ts b/packages/angular-test-app/src/preview-examples/modal-by-instance.ts index ff0ce36332..df07d66b25 100644 --- a/packages/angular-test-app/src/preview-examples/modal-by-instance.ts +++ b/packages/angular-test-app/src/preview-examples/modal-by-instance.ts @@ -12,7 +12,7 @@ import { ModalService } from '@siemens/ix-angular'; import ModalByInstanceExample from './modal-by-instance-content'; @Component({ - selector: 'app-example-instance', + selector: 'app-example', template: 'Show modal', }) export default class ModalByInstance { diff --git a/packages/angular-test-app/src/preview-examples/modal-sizes.html b/packages/angular-test-app/src/preview-examples/modal-sizes.html index 3abc47c0c7..27dd76d489 100644 --- a/packages/angular-test-app/src/preview-examples/modal-sizes.html +++ b/packages/angular-test-app/src/preview-examples/modal-sizes.html @@ -20,24 +20,5 @@ -
- - -
- -
- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy - eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam - voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet - clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit - amet. - -
+ Modal with size {{ modal.data }}
diff --git a/packages/documentation/docs/controls/modal.md b/packages/documentation/docs/controls/modal.md index 9b553af2cc..11256776bd 100644 --- a/packages/documentation/docs/controls/modal.md +++ b/packages/documentation/docs/controls/modal.md @@ -38,18 +38,35 @@ Select the appropriate section below for the respective usage information. ### Angular +#### By template + + + + +#### By instance + +angular: [ +"modal-by-instance.ts", +"modal-by-instance-content.ts", +], +}}> `@siemens/ix-angular` provides an injectable service that allows to open modal dialogs based on a `ng-template` reference or by component type. diff --git a/packages/documentation/src/components/PlaygroundV3/index.tsx b/packages/documentation/src/components/PlaygroundV3/index.tsx index dea53c6a34..bcf5ed020d 100644 --- a/packages/documentation/src/components/PlaygroundV3/index.tsx +++ b/packages/documentation/src/components/PlaygroundV3/index.tsx @@ -204,6 +204,7 @@ function SnippetPreview(props: { snippets: Record }) { function ToolbarButtons(props: { name: string; + deviantRootFileName: string; activeFramework: TargetFramework; noMargin: boolean; snippets: Record; @@ -235,7 +236,7 @@ function ToolbarButtons(props: { baseUrl: baseUrl, framework: props.activeFramework, snippets: props.snippets, - name: props.name, + name: props.deviantRootFileName ? props.deviantRootFileName : props.name, version: 'latest', }) } @@ -272,6 +273,7 @@ export type PlaygroundV3Props = { frameworks?: TargetFramework[]; preventDefaultExample?: boolean; additionalFiles?: Record; + deviantRootFileName?: string; } & DemoProps; export default function PlaygroundV3(props: PlaygroundV3Props) { @@ -332,6 +334,7 @@ export default function PlaygroundV3(props: PlaygroundV3Props) { , + rootFileName: string +) { + const componentRegex = /@Component\(/; + + return Object.keys(snippets) + .filter((key) => { + return ( + key.endsWith('.ts') && + key !== `${rootFileName}.ts` && + componentRegex.test(snippets[key]) + ); + }) + .map((key) => key.replace('.ts', '')); +} + async function createAngularProjectFiles( baseUrl: string, snippets: Record, @@ -138,14 +155,34 @@ async function createAngularProjectFiles( project[`src/${key.replace('./', '')}`] = snippets[key]; }); + const additionalAngularComponents = getAdditionalAngularComponents( + snippets, + name + ); + + const importsString = additionalAngularComponents + .map( + (file) => `import ${fromKebabCaseToCamelCase(file)} from './../${file}';` + ) + .join('\n'); + project['src/app/app.module.ts'] = project['src/app/app.module.ts'].replace( "import ExampleComponent from './example.component';", - `import ${fromKebabCaseToCamelCase(name)} from './../${name}';` + [ + `import ${fromKebabCaseToCamelCase(name)} from './../${name}';`, + importsString, + ].join('\n') ); + const importComponent = additionalAngularComponents + .map((file) => fromKebabCaseToCamelCase(file)) + .join(', '); + project['src/app/app.module.ts'] = project['src/app/app.module.ts'].replace( 'declarations: [AppComponent, ExampleComponent],', - `declarations: [AppComponent, ${fromKebabCaseToCamelCase(name)}],` + `declarations: [AppComponent, ${fromKebabCaseToCamelCase( + name + )}, ${importComponent}],` ); return project;