Skip to content

Commit

Permalink
fix(core): do not call resolver multiple time (#8578)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Aug 20, 2024
1 parent f50883e commit 6e5c9f4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions projects/core/components/icon/icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ViewEncapsulation,
} from '@angular/core';
import type {TuiStringHandler} from '@taiga-ui/cdk/types';
import {tuiPure} from '@taiga-ui/cdk/utils/miscellaneous';
import {TUI_ICON_END, TUI_ICON_START, tuiInjectIconResolver} from '@taiga-ui/core/tokens';

@Component({
Expand All @@ -16,8 +17,8 @@ import {TUI_ICON_END, TUI_ICON_START, tuiInjectIconResolver} from '@taiga-ui/cor
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'[style.--t-icon]': '"url(" + resolver(icon) + ")"',
'[style.--t-icon-bg]': 'background ? "url(" + resolver(background) + ")" : null',
'[style.--t-icon]': 'getUrl(icon)',
'[style.--t-icon-bg]': 'getBackground(background)',
},
})
export class TuiIcon {
Expand All @@ -31,4 +32,14 @@ export class TuiIcon {

@Input()
public background = '';

@tuiPure
protected getUrl(icon: string): string {
return `url(${this.resolver(icon)})`;
}

@tuiPure
protected getBackground(background: string): string | null {
return background ? `url(${this.resolver(background)})` : null;
}
}

0 comments on commit 6e5c9f4

Please sign in to comment.