Skip to content

Commit

Permalink
chore: fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Mar 21, 2024
1 parent 78ff774 commit 5eab859
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
19 changes: 5 additions & 14 deletions projects/addon-doc/components/example/example.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {Clipboard} from '@angular/cdk/clipboard';
import type {Type} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
HostBinding,
inject,
Input,
} from '@angular/core';
import type {DefaultExport} from '@angular/router';
import {LOCATION} from '@ng-web-apis/common';
import type {TuiDocExample} from '@taiga-ui/addon-doc/interfaces';
import {
Expand All @@ -24,7 +22,7 @@ import {TUI_COPY_TEXTS} from '@taiga-ui/kit';
import type {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus';
import type {Observable} from 'rxjs';
import {BehaviorSubject, map, ReplaySubject, Subject, switchMap} from 'rxjs';
import {BehaviorSubject, map, ReplaySubject, Subject, switchAll, switchMap} from 'rxjs';

import {TUI_DOC_EXAMPLE_OPTIONS} from './example.options';

Expand Down Expand Up @@ -85,12 +83,8 @@ export class TuiDocExampleComponent {
);

protected readonly lazyComponent$ = this.lazyLoader$$.pipe(
switchMap(async lazyImport =>
lazyImport.then(
(module: DefaultExport<Type<any>>) =>
new PolymorpheusComponent(module.default),
),
),
switchAll(),
map(module => new PolymorpheusComponent(module.default)),
);

protected readonly loading$ = new Subject<boolean>();
Expand Down Expand Up @@ -121,11 +115,8 @@ export class TuiDocExampleComponent {

protected edit(files: Record<string, string>): void {
this.loading$.next(true);
this.codeEditor
void this.codeEditor
?.edit(this.componentName, this.id || '', files)
// TODO: replace lines below with `finally` when we bump Firefox to 58+
// TODO: Add `es2018.promise` to `tsconfig.json` => `compilerOptions.lib`.
.then(() => this.loading$.next(false))
.catch(() => this.loading$.next(false));
.finally(() => this.loading$.next(false));
}
}
12 changes: 6 additions & 6 deletions projects/demo/src/modules/components/avatar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<tui-doc-example
id="content"
heading="Content types"
[component]="example1"
[component]="1 | tuiComponent"
[content]="1 | tuiExample"
>
<tui-notification class="tui-space_bottom-4">
Expand All @@ -19,7 +19,7 @@
<tui-doc-example
id="color"
heading="Colors"
[component]="example2"
[component]="2 | tuiComponent"
[content]="2 | tuiExample"
>
<tui-notification class="tui-space_bottom-4">
Expand All @@ -31,14 +31,14 @@
<tui-doc-example
id="size"
heading="Sizes"
[component]="example3"
[component]="3 | tuiComponent"
[content]="3 | tuiExample"
/>

<tui-doc-example
id="stacking"
heading="Stacking"
[component]="example4"
[component]="4 | tuiComponent"
[content]="4 | tuiExample: 'html,ts'"
>
<tui-notification class="tui-space_bottom-4">
Expand All @@ -50,14 +50,14 @@
<tui-doc-example
id="options"
heading="Options with DI"
[component]="example5"
[component]="5 | tuiComponent"
[content]="5 | tuiExample: 'html,ts'"
/>

<tui-doc-example
id="labeled"
heading="Labeled"
[component]="example6"
[component]="6 | tuiComponent"
[content]="6 | tuiExample"
/>
</ng-template>
Expand Down
9 changes: 2 additions & 7 deletions projects/demo/src/modules/components/avatar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Component, inject} from '@angular/core';
import type {SafeResourceUrl} from '@angular/platform-browser';
import {DomSanitizer} from '@angular/platform-browser';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiExamplePipe} from '@demo/utils';
import {TuiComponentPipe, TuiExamplePipe} from '@demo/utils';
import {TuiAddonDocModule} from '@taiga-ui/addon-doc';
import type {TuiSizeXS, TuiSizeXXL} from '@taiga-ui/core';
import {TuiNotificationModule} from '@taiga-ui/core';
Expand All @@ -19,6 +19,7 @@ import {PolymorpheusModule} from '@tinkoff/ng-polymorpheus';
TuiExamplePipe,
PolymorpheusModule,
AsyncPipe,
TuiComponentPipe,
],
templateUrl: './index.html',
changeDetection,
Expand All @@ -27,12 +28,6 @@ export default class ExampleComponent {
private readonly sanitizer = inject(DomSanitizer);
protected readonly exampleModule = import('./examples/import/module.md?raw');
protected readonly exampleHtml = import('./examples/import/template.md?raw');
protected readonly example1 = import('./examples/1');
protected readonly example2 = import('./examples/2');
protected readonly example3 = import('./examples/3');
protected readonly example4 = import('./examples/4');
protected readonly example5 = import('./examples/5');
protected readonly example6 = import('./examples/6');

protected readonly sizes: ReadonlyArray<TuiSizeXS | TuiSizeXXL> = [
'xs',
Expand Down
16 changes: 16 additions & 0 deletions projects/demo/src/utils/component.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {PipeTransform} from '@angular/core';
import {inject, Pipe} from '@angular/core';
import {TuiDocPageComponent} from '@taiga-ui/addon-doc';

import {toKebab} from './example.pipe';

@Pipe({name: 'tuiComponent', standalone: true})
export class TuiComponentPipe implements PipeTransform {
protected docPage = inject(TuiDocPageComponent);

public async transform(index: number): Promise<{readonly default: any}> {
return import(
`../modules/${this.docPage.type}/${toKebab(this.docPage.header)}/examples/${index}/index.ts`
);
}
}
2 changes: 1 addition & 1 deletion projects/demo/src/utils/example.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {inject, Pipe} from '@angular/core';
import type {TuiDocExample} from '@taiga-ui/addon-doc';
import {TuiDocPageComponent} from '@taiga-ui/addon-doc';

const toKebab: (str: string) => string = str =>
export const toKebab: (str: string) => string = str =>
str.replaceAll(
/[A-Z]+(?![a-z])|[A-Z]/g,
($, ofs) => (ofs ? '-' : '') + $.toLowerCase(),
Expand Down
1 change: 1 addition & 0 deletions projects/demo/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './component.pipe';
export * from './example.pipe';
export * from './load-assets';
export * from './setup.component';

0 comments on commit 5eab859

Please sign in to comment.