Skip to content

Commit c7c4035

Browse files
committed
refactor(sidebar-brand): signal inputs, host bindings, cleanup
1 parent 65ff325 commit c7c4035

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

projects/coreui-angular/src/lib/sidebar/sidebar-brand/sidebar-brand.component.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@if (brandImg) {
2-
<a [routerLink]="routerLink">
3-
@if (brandFull) {
4-
<img [cHtmlAttr]="brandFull" [ngClass]="'sidebar-brand-full'">
1+
@if (brandImg()) {
2+
<a [routerLink]="routerLink()">
3+
@if (brandFull()) {
4+
<img [cHtmlAttr]="brandFull()" [ngClass]="'sidebar-brand-full'">
55
}
6-
@if (brandNarrow) {
7-
<img [cHtmlAttr]="brandNarrow" [ngClass]="'sidebar-brand-narrow'">
6+
@if (brandNarrow()) {
7+
<img [cHtmlAttr]="brandNarrow()" [ngClass]="'sidebar-brand-narrow'">
88
}
99
</a>
1010
} @else {
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
import { Component, HostBinding, Input, OnInit } from '@angular/core';
1+
import { Component, computed, input } from '@angular/core';
22
import { NgClass } from '@angular/common';
3-
import { RouterLink } from '@angular/router';
3+
import { RouterLink, type UrlTree } from '@angular/router';
44

55
import { HtmlAttributesDirective } from '../../shared';
66

77
@Component({
8-
selector: 'c-sidebar-brand',
9-
templateUrl: './sidebar-brand.component.html',
10-
imports: [RouterLink, HtmlAttributesDirective, NgClass]
8+
selector: 'c-sidebar-brand',
9+
templateUrl: './sidebar-brand.component.html',
10+
imports: [RouterLink, HtmlAttributesDirective, NgClass],
11+
host: { class: 'sidebar-brand' }
1112
})
12-
export class SidebarBrandComponent implements OnInit {
13+
export class SidebarBrandComponent {
14+
readonly brandFull = input<any>();
15+
readonly brandNarrow = input<any>();
1316

14-
@Input() brandFull?: any;
15-
@Input() brandNarrow?: any;
16-
@Input() routerLink?: any[] | string;
17+
readonly routerLink = input<string | any[] | UrlTree | null | undefined>();
1718

18-
@HostBinding('class.sidebar-brand') sidebarBrandClass = true;
19-
20-
brandImg = false;
21-
22-
ngOnInit(): void {
23-
this.brandImg = Boolean(this.brandFull || this.brandNarrow);
24-
}
19+
readonly brandImg = computed(() => Boolean(this.brandFull() || this.brandNarrow()));
2520
}

0 commit comments

Comments
 (0)