Skip to content

Commit

Permalink
fix(addon-commerce): InputCard icon to signal (#9421)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlufy authored Oct 9, 2024
1 parent 0d9ac9d commit 41270d6
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
inject,
Input,
Output,
signal,
ViewEncapsulation,
} from '@angular/core';
import {toObservable, toSignal} from '@angular/core/rxjs-interop';
Expand Down Expand Up @@ -54,6 +55,8 @@ export class TuiInputCard implements OnInit {
{initialValue: ''},
);

private readonly icon = signal<string | null>(this.options.icon);

private readonly accessor = inject(DefaultValueAccessor, {
self: true,
optional: true,
Expand All @@ -63,17 +66,14 @@ export class TuiInputCard implements OnInit {
protected readonly image = computed(() => {
const system = this.options.paymentSystemHandler(this.value());
const icon = system && this.icons[system] && this.resolver(this.icons[system]);
const url = this.icon || icon;
const url = this.icon() || icon;

return url && this.icon !== '' ? url : null;
return url && this.icon() !== '' ? url : null;
});

@Input()
public autocomplete = this.options.autocomplete;

@Input()
public icon = this.options.icon;

@Output()
public readonly binChange = toObservable(this.value).pipe(
map((value) => (value.length < 6 ? null : value.replace(' ', '').slice(0, 6))),
Expand All @@ -82,6 +82,11 @@ export class TuiInputCard implements OnInit {
skip(1),
);

@Input('icon')
public set iconValue(icon: string | null) {
this.icon.set(icon);
}

public ngOnInit(): void {
if (!this.accessor) {
return;
Expand Down

0 comments on commit 41270d6

Please sign in to comment.