Skip to content

Commit

Permalink
docs(demo): display emission in @Output wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
demensky committed Dec 6, 2023
1 parent 95c92b9 commit 0dd7350
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
} from '@angular/core';
import {ActivatedRoute, Params, UrlSerializer, UrlTree} from '@angular/router';
import {TUI_DOC_URL_STATE_HANDLER} from '@taiga-ui/addon-doc/tokens';
import {tuiCoerceValue} from '@taiga-ui/addon-doc/utils';
import {tuiCoerceValue, tuiInspectAny} from '@taiga-ui/addon-doc/utils';
import {tuiIsNumber, TuiStringHandler} from '@taiga-ui/cdk';
import {TuiAlertService} from '@taiga-ui/core';
import {BehaviorSubject, Subject} from 'rxjs';

const SERIALIZED_SUFFIX = '$';
Expand Down Expand Up @@ -66,6 +67,7 @@ export class TuiDocDocumentationPropertyConnectorDirective<T>
@Inject(UrlSerializer) private readonly urlSerializer: UrlSerializer,
@Inject(TUI_DOC_URL_STATE_HANDLER)
private readonly urlStateHandler: TuiStringHandler<UrlTree>,
@Inject(TuiAlertService) private readonly alerts: TuiAlertService,
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -108,6 +110,14 @@ export class TuiDocDocumentationPropertyConnectorDirective<T>
console.info(this.attrName, event);

this.emits$.next(this.emits$.value + 1);

let content: string | undefined;

if (event !== undefined) {
content = tuiInspectAny(event, 2);
}

this.alerts.open(content, {label: this.attrName}).subscribe();
}

private parseParams(params: Params): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Inject} from '@angular/core';
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiDocExample} from '@taiga-ui/addon-doc';
import {
Expand All @@ -11,7 +11,6 @@ import {
TuiMonthRange,
TuiYear,
} from '@taiga-ui/cdk';
import {TuiAlertService} from '@taiga-ui/core';

@Component({
selector: 'example-tui-calendar-month',
Expand Down Expand Up @@ -68,13 +67,4 @@ export class ExampleTuiCalendarMonthComponent {
];

year = this.yearVariants[0];

constructor(
@Inject(TuiAlertService)
private readonly alerts: TuiAlertService,
) {}

onMonthClick(month: TuiMonth): void {
this.alerts.open(String(month)).subscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
[min]="min"
[value]="value"
[year]="year"
(monthClick)="onMonthClick($event)"
(monthClick)="documentationPropertyMonthClick.emitEvent($event)"
></tui-calendar-month>
</tui-doc-demo>
<tui-doc-documentation>
Expand Down Expand Up @@ -91,6 +91,7 @@
Current year
</ng-template>
<ng-template
#documentationPropertyMonthClick="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="monthClick"
documentationPropertyType="TuiMonth"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Inject} from '@angular/core';
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiDocExample} from '@taiga-ui/addon-doc';
import {
Expand All @@ -10,11 +10,7 @@ import {
TuiDayRange,
TuiMonth,
} from '@taiga-ui/cdk';
import {
TUI_DEFAULT_MARKER_HANDLER,
TuiAlertService,
TuiMarkerHandler,
} from '@taiga-ui/core';
import {TUI_DEFAULT_MARKER_HANDLER, TuiMarkerHandler} from '@taiga-ui/core';

const TWO_DOTS: [string, string] = ['var(--tui-primary)', 'var(--tui-info-fill)'];
const ONE_DOT: [string] = ['var(--tui-success-fill)'];
Expand Down Expand Up @@ -123,13 +119,4 @@ export class ExampleTuiCalendarComponent {
month = TuiMonth.currentLocal();

hoveredItem: TuiDay | null = null;

constructor(
@Inject(TuiAlertService)
private readonly alerts: TuiAlertService,
) {}

onDayClick(day: TuiDay): void {
this.alerts.open(String(day)).subscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
[value]="value"
[(hoveredItem)]="hoveredItem"
[(month)]="month"
(dayClick)="onDayClick($event)"
(dayClick)="documentationPropertyDayClick.emitEvent($event)"
></tui-calendar>
</tui-doc-demo>
<tui-doc-documentation>
Expand Down Expand Up @@ -204,6 +204,7 @@
Selected day or range
</ng-template>
<ng-template
#documentationPropertyDayClick="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="dayClick"
documentationPropertyType="TuiDay"
Expand Down
13 changes: 2 additions & 11 deletions projects/demo/src/modules/components/filter/filter.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, Inject} from '@angular/core';
import {Component} from '@angular/core';
import {FormControl} from '@angular/forms';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiDocExample} from '@taiga-ui/addon-doc';
import {ALWAYS_FALSE_HANDLER, TuiBooleanHandler, TuiHandler} from '@taiga-ui/cdk';
import {TuiAlertService, TuiSizeL, TuiSizeXS} from '@taiga-ui/core';
import {TuiSizeL, TuiSizeXS} from '@taiga-ui/core';

class ItemWithBadge {
constructor(
Expand Down Expand Up @@ -86,13 +86,4 @@ export class ExampleTuiFilterComponent {
readonly sizeVariants: ReadonlyArray<TuiSizeL | TuiSizeXS> = ['xs', 's', 'm', 'l'];

size = this.sizeVariants[2];

constructor(
@Inject(TuiAlertService)
private readonly alerts: TuiAlertService,
) {}

onToggledItemChange(item: unknown): void {
this.alerts.open(String(item)).subscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
[formControl]="control"
[items]="items"
[size]="size"
(toggledItem)="onToggledItemChange($event)"
(toggledItem)="documentationPropertyToggledItem.emitEvent($event)"
></tui-filter>
</ng-template>
</tui-doc-demo>
Expand Down Expand Up @@ -118,6 +118,7 @@
Size
</ng-template>
<ng-template
#documentationPropertyToggledItem="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="toggledItem"
documentationPropertyType="T"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {Component, forwardRef, Inject} from '@angular/core';
import {Component, forwardRef} from '@angular/core';
import {FormControl} from '@angular/forms';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiCodeCVCLength} from '@taiga-ui/addon-commerce';
import {TuiDocExample} from '@taiga-ui/addon-doc';
import {tuiIsString} from '@taiga-ui/cdk';
import {TuiAlertService} from '@taiga-ui/core';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

import {ABSTRACT_PROPS_ACCESSOR} from '../abstract/inherited-documentation/abstract-props-accessor';
Expand Down Expand Up @@ -77,13 +76,6 @@ export class ExampleTuiInputCardGroupedComponent extends AbstractExampleTuiInter

control = new FormControl();

constructor(
@Inject(TuiAlertService)
private readonly alerts: TuiAlertService,
) {
super();
}

get cardSrc(): PolymorpheusContent {
return tuiIsString(this.cardSrcSelected)
? this.cards[this.cardSrcSelected]
Expand All @@ -102,10 +94,6 @@ export class ExampleTuiInputCardGroupedComponent extends AbstractExampleTuiInter
}
}

onBinChange(bin: string | null): void {
this.alerts.open(`bin: ${bin}`).subscribe();
}

getContentVariants(
template: PolymorpheusContent,
): readonly PolymorpheusContent[] | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
[pseudoHover]="pseudoHovered"
[pseudoInvalid]="pseudoInvalid"
[readOnly]="readOnly"
(binChange)="onBinChange($event)"
(binChange)="documentationPropertyBinChange.emitEvent($event)"
></tui-input-card-grouped>
</ng-template>
</tui-doc-demo>
Expand Down Expand Up @@ -131,6 +131,7 @@
Code length
</ng-template>
<ng-template
#documentationPropertyBinChange="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="binChange"
documentationPropertyType="string | null"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {Component, forwardRef, Inject} from '@angular/core';
import {Component, forwardRef, ViewChild} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiCodeCVCLength, tuiCreateLuhnValidator} from '@taiga-ui/addon-commerce';
import {TuiDocExample} from '@taiga-ui/addon-doc';
import {TuiAlertService, TuiHintOptions} from '@taiga-ui/core';
import {
TuiDocDocumentationPropertyConnectorDirective,
TuiDocExample,
} from '@taiga-ui/addon-doc';
import {TuiHintOptions} from '@taiga-ui/core';

import {AbstractExampleTuiControl} from '../abstract/control';
import {ABSTRACT_PROPS_ACCESSOR} from '../abstract/inherited-documentation/abstract-props-accessor';
Expand All @@ -21,6 +24,11 @@ import {ABSTRACT_PROPS_ACCESSOR} from '../abstract/inherited-documentation/abstr
],
})
export class ExampleTuiInputCardComponent extends AbstractExampleTuiControl {
@ViewChild('documentationPropertyBinChange', {
read: TuiDocDocumentationPropertyConnectorDirective,
})
binChangeProperty?: TuiDocDocumentationPropertyConnectorDirective<unknown>;

readonly exampleModule = import('./examples/import/import-module.md?raw');
readonly exampleHtml = import('./examples/import/insert-template.md?raw');

Expand Down Expand Up @@ -73,13 +81,6 @@ export class ExampleTuiInputCardComponent extends AbstractExampleTuiControl {
cvc: new FormControl('', Validators.required),
});

constructor(
@Inject(TuiAlertService)
private readonly alerts: TuiAlertService,
) {
super();
}

get cardSrc(): string | null {
return this.cardSrcSelected === null ? null : this.cards[this.cardSrcSelected];
}
Expand Down Expand Up @@ -121,8 +122,4 @@ export class ExampleTuiInputCardComponent extends AbstractExampleTuiControl {

this.control.get(control)!.enable();
}

onBinChange(bin: string | null): void {
this.alerts.open(`bin: ${bin}`).subscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
[tuiTextfieldCleaner]="cleaner"
[tuiTextfieldLabelOutside]="labelOutside"
[tuiTextfieldSize]="size"
(binChange)="onBinChange($event)"
(binChange)="binChangeProperty?.emitEvent($event)"
>
Card number
</tui-input-card>
Expand Down Expand Up @@ -135,6 +135,7 @@
SVG card icon
</ng-template>
<ng-template
#documentationPropertyBinChange
documentationPropertyMode="output"
documentationPropertyName="binChange"
documentationPropertyType="string | null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
[pseudoActive]="pseudoPressed"
[pseudoFocus]="pseudoFocused"
[pseudoHover]="pseudoHovered"
(reject)="updateRejected($event)"
(reject)="updateRejected($event); documentationPropertyReject.emitEvent($event)"
>
<input
tuiInputFiles
Expand All @@ -94,7 +94,7 @@
[showDelete]="showDelete"
[showSize]="showSize"
[size]="size"
(removed)="removeFile(file)"
(removed)="removeFile(file); documentationPropertyRemoved.emitEvent($event)"
></tui-file>
</ng-container>
</ng-container>
Expand Down Expand Up @@ -161,6 +161,7 @@
Max file size in bytes (30 MB by default — 30 * 1000 * 1000)
</ng-template>
<ng-template
#documentationPropertyReject="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="reject"
documentationPropertyType="TuiFileLike"
Expand Down Expand Up @@ -263,6 +264,7 @@
Component size
</ng-template>
<ng-template
#documentationPropertyRemoved="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="removed"
documentationPropertyType="TuiFileLike"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
[lineHeight]="lineHeight"
[linesLimit]="linesLimit"
[style.maxWidth.px]="maxWidth"
(overflownChange)="documentationPropertyOverflownChange.emitEvent($event)"
></tui-line-clamp>
<ng-template #defaultExampleContent>
Lorem ipsum
Expand Down Expand Up @@ -91,6 +92,7 @@
Number of visible lines
</ng-template>
<ng-template
#documentationPropertyOverflownChange="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="overflownChange"
documentationPropertyType="boolean"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
[max]="max"
[min]="min"
[single]="single"
(cancel)="documentationPropertyCancel.emitEvent($event)"
(confirm)="documentationPropertyConfirm.emitEvent($event)"
></tui-mobile-calendar>
</tui-doc-demo>

Expand Down Expand Up @@ -119,13 +121,15 @@
Single date or a range
</ng-template>
<ng-template
#documentationPropertyCancel="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="cancel"
documentationPropertyType="void"
>
"Cancel" clicked
</ng-template>
<ng-template
#documentationPropertyConfirm="documentationProperty"
documentationPropertyMode="output"
documentationPropertyName="confirm"
documentationPropertyType="TuiDayRange | TuiDay"
Expand Down
11 changes: 1 addition & 10 deletions projects/demo/src/modules/components/push/push.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {Component, Inject} from '@angular/core';
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
import {TuiDocExample} from '@taiga-ui/addon-doc';
import {TuiAlertService} from '@taiga-ui/core';

@Component({
selector: 'example-tui-push',
Expand Down Expand Up @@ -34,12 +33,4 @@ export class ExampleTuiPushComponent {
heading = '';
type = '';
timestamp = 0;

constructor(@Inject(TuiAlertService) private readonly alert: TuiAlertService) {}

onClose(): void {
this.alert
.open('Close button is visible when you subscribe to (close) output')
.subscribe();
}
}
Loading

0 comments on commit 0dd7350

Please sign in to comment.