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

chore(demo): InputCard add API page #9420

Merged
merged 7 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion projects/addon-doc/components/api/api-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {
inject,
Input,
Output,
signal,
} from '@angular/core';
import {FormsModule} from '@angular/forms';
import type {Params} from '@angular/router';
import {ActivatedRoute, UrlSerializer} 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} from '@taiga-ui/cdk/utils/miscellaneous';
import {TuiAlertService} from '@taiga-ui/core/components/alert';
import {TuiIcon} from '@taiga-ui/core/components/icon';
import {TuiTextfield} from '@taiga-ui/core/components/textfield';
import {TuiDataListWrapper} from '@taiga-ui/kit/components/data-list-wrapper';
Expand Down Expand Up @@ -48,13 +50,15 @@ const SERIALIZED_SUFFIX = '$';
],
templateUrl: './api-item.template.html',
styleUrls: ['./api-item.style.less'],
exportAs: 'docAPIItem',
waterplea marked this conversation as resolved.
Show resolved Hide resolved
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TuiDocAPIItem<T> implements OnInit {
private readonly locationRef = inject(Location);
private readonly activatedRoute = inject(ActivatedRoute);
private readonly urlSerializer = inject(UrlSerializer);
private readonly urlStateHandler = inject(TUI_DOC_URL_STATE_HANDLER);
private readonly alerts = inject(TuiAlertService);

@Input()
public name = '';
Expand All @@ -71,6 +75,8 @@ export class TuiDocAPIItem<T> implements OnInit {
@Output()
public readonly valueChange = new EventEmitter<T>();

public readonly emits = signal(1);

public ngOnInit(): void {
this.parseParams(this.activatedRoute.snapshot.queryParams);
}
Expand All @@ -81,6 +87,18 @@ export class TuiDocAPIItem<T> implements OnInit {
this.setQueryParam(value);
}

public emitEvent(event: unknown): void {
this.emits.update((x) => ++x);
splincode marked this conversation as resolved.
Show resolved Hide resolved

let content: string | undefined;
waterplea marked this conversation as resolved.
Show resolved Hide resolved

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

this.alerts.open(content, {label: this.name}).subscribe();
waterplea marked this conversation as resolved.
Show resolved Hide resolved
}

private clearBrackets(value: string): string {
return value.replaceAll(/[()[\]]/g, '');
}
Expand Down
73 changes: 72 additions & 1 deletion projects/demo/src/modules/components/input-card/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,76 @@
</tui-doc-example>
</ng-template>

<tui-setup *pageTab="'Setup'" />
<ng-template pageTab>
<tui-doc-demo>
<tui-textfield
[iconEnd]="icons.iconEnd"
[iconStart]="icons.iconStart"
[tuiTextfieldCleaner]="textfield.cleaner"
[tuiTextfieldSize]="textfield.size"
>
<label tuiLabel>Card number</label>
<input
tuiInputCard
waterplea marked this conversation as resolved.
Show resolved Hide resolved
tuiTextfield
[autocomplete]="autocomplete"
[disabled]="control.disabled"
[icon]="icon"
[invalid]="control.invalid"
[readOnly]="control.readonly"
[(ngModel)]="card"
(binChange)="docAPIItemBinChange.emitEvent($event)"
/>
</tui-textfield>
</tui-doc-demo>
<table tuiDocAPI>
<tr
name="[(ngModel)]"
tuiDocAPIItem
type="string"
[(value)]="card"
>
Card number (also works with a reactive control)
</tr>
<tr
name="[autocomplete]"
tuiDocAPIItem
type="boolean"
[(value)]="autocomplete"
>
Browser autocomplete of card
</tr>
<tr
name="[icon]"
tuiDocAPIItem
type="string | null"
[items]="iconVariants"
[(value)]="iconSelected"
>
Card icon
</tr>
<tr
#docAPIItemBinChange="docAPIItem"
waterplea marked this conversation as resolved.
Show resolved Hide resolved
name="(binChange)"
tuiDocAPIItem
type="string | null"
>
BIN value (card first 6 symbols)
</tr>
<tbody
#control
tuiDocControl
></tbody>
<tbody
#textfield
tuiDocTextfield
></tbody>
<tbody
#icons
tuiDocIcons
></tbody>
</table>
</ng-template>

<tui-setup *pageTab />
</tui-doc-page>
36 changes: 34 additions & 2 deletions projects/demo/src/modules/components/input-card/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
import {Component} from '@angular/core';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {TuiDocControl} from '@demo/components/control';
import {TuiDocIcons} from '@demo/components/icons';
import {TuiDocTextfield} from '@demo/components/textfield';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiDemo} from '@demo/utils';
import {TuiInputCard} from '@taiga-ui/addon-commerce';
import {TuiTextfield} from '@taiga-ui/core';

@Component({
standalone: true,
imports: [TuiDemo],
imports: [
FormsModule,
ReactiveFormsModule,
TuiDemo,
TuiDocControl,
TuiDocIcons,
TuiDocTextfield,
TuiInputCard,
TuiTextfield,
],
templateUrl: './index.html',
changeDetection,
})
export default class Page {}
export default class Page {
protected card = '';
protected iconSelected: string | null = null;
protected autocomplete = false;

protected readonly cards: Record<string, string> = {
common: 'https://ng-web-apis.github.io/dist/assets/images/common.svg',
universal: 'https://ng-web-apis.github.io/dist/assets/images/universal.svg',
mutation:
'https://ng-web-apis.github.io/dist/assets/images/mutation-observer.svg',
};

protected readonly iconVariants: readonly string[] = Object.keys(this.cards);

protected get icon(): string | null {
return (this.iconSelected && this.cards[this.iconSelected]) || null;
waterplea marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading