Skip to content

Commit fa44a5b

Browse files
committed
refactor: migration to signal inputs, host bindings, cleanups
1 parent 62eecb2 commit fa44a5b

File tree

13 files changed

+85
-111
lines changed

13 files changed

+85
-111
lines changed

src/app/views/notifications/toasters/toast-simple/toast.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<ng-container>
2-
<c-toast-header [closeButton]="closeButton">
2+
<c-toast-header [closeButton]="closeButton()">
33
<svg class="rounded me-2" focusable="false" height="20" preserveAspectRatio="xMidYMid slice"
44
role="img" width="20" xmlns="http://www.w3.org/2000/svg">
55
<rect fill="#007aff" height="100%" width="100%"></rect>
66
</svg>
7-
<strong>{{ title }}</strong>
7+
<strong>{{ title() }}</strong>
88
</c-toast-header>
99
<c-toast-body #toastBody [cToastClose]="toastBody.toast ?? undefined">
1010
<p class="mb-1">This is a dynamic toast no {{ toastBody.toast?.index() }} {{ toastBody.toast?.clock }}</p>

src/app/views/notifications/toasters/toast-simple/toast.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, forwardRef, Input } from '@angular/core';
1+
import { Component, forwardRef, input } from '@angular/core';
22

33
import { ProgressComponent, ToastBodyComponent, ToastCloseDirective, ToastComponent, ToastHeaderComponent } from '@coreui/angular';
44

@@ -15,6 +15,6 @@ export class AppToastComponent extends ToastComponent {
1515
super();
1616
}
1717

18-
@Input() closeButton = true;
19-
@Input() title = '';
18+
readonly closeButton = input(true);
19+
readonly title = input('');
2020
}

src/app/views/theme/colors.component.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { AfterViewInit, Component, HostBinding, Input, OnInit, Renderer2, forwardRef, DOCUMENT, inject } from '@angular/core';
1+
import { AfterViewInit, Component, computed, DOCUMENT, forwardRef, inject, input, OnInit, Renderer2 } from '@angular/core';
22
import { NgClass } from '@angular/common';
33

44
import { getStyle, rgbToHex } from '@coreui/utils';
5-
import { TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, RowComponent, ColComponent } from '@coreui/angular';
5+
import { CardBodyComponent, CardComponent, CardHeaderComponent, ColComponent, RowComponent } from '@coreui/angular';
66

77
@Component({
8-
templateUrl: 'colors.component.html',
9-
imports: [TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, RowComponent, forwardRef(() => ThemeColorComponent)]
8+
templateUrl: 'colors.component.html',
9+
imports: [CardComponent, CardHeaderComponent, CardBodyComponent, RowComponent, forwardRef(() => ThemeColorComponent)]
1010
})
1111
export class ColorsComponent implements OnInit, AfterViewInit {
1212
private document = inject<Document>(DOCUMENT);
1313
private renderer = inject(Renderer2);
1414

15-
1615
public themeColors(): void {
1716
Array.from(this.document.querySelectorAll('.theme-color')).forEach(
1817
(element: Element) => {
@@ -46,28 +45,28 @@ export class ColorsComponent implements OnInit, AfterViewInit {
4645
}
4746

4847
@Component({
49-
selector: 'app-theme-color',
50-
template: `
48+
selector: 'app-theme-color',
49+
template: `
5150
<c-col xl="2" md="4" sm="6" xs="12" class="my-4 ms-4">
52-
<div [ngClass]="colorClasses" style="padding-top: 75%;"></div>
51+
<div [ngClass]="colorClasses()" style="padding-top: 75%;"></div>
5352
<ng-content></ng-content>
5453
</c-col>
5554
`,
56-
imports: [ColComponent, NgClass]
55+
imports: [ColComponent, NgClass],
56+
host: {
57+
style: 'display: contents;'
58+
}
5759
})
58-
export class ThemeColorComponent implements OnInit {
59-
@Input() color = '';
60-
public colorClasses = {
61-
'theme-color w-75 rounded mb-3': true
62-
};
60+
export class ThemeColorComponent {
61+
readonly color = input('');
6362

64-
@HostBinding('style.display') display = 'contents';
65-
66-
ngOnInit(): void {
67-
this.colorClasses = {
68-
...this.colorClasses,
69-
[`bg-${this.color}`]: !!this.color
63+
readonly colorClasses = computed(() => {
64+
const color = this.color();
65+
return {
66+
'theme-color w-75 rounded mb-3': true,
67+
[`bg-${color}`]: !!color
7068
};
71-
}
69+
});
70+
7271
}
7372

src/app/views/widgets/widgets-brand/widgets-brand.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[values]="widget.values"
88
>
99
<svg [name]="widget.icon" cIcon class="my-4 text-white" height="52"></svg>
10-
@if (withCharts) {
10+
@if (withCharts()) {
1111
<c-chart
1212
#chart="cChart"
1313
[data]="widget.data"

src/app/views/widgets/widgets-brand/widgets-brand.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, inject } from '@angular/core';
1+
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, inject, input } from '@angular/core';
22
import { ChartjsComponent } from '@coreui/angular-chartjs';
33
import { IconDirective } from '@coreui/icons-angular';
44
import { ColComponent, RowComponent, WidgetStatDComponent } from '@coreui/angular';
@@ -24,7 +24,7 @@ export class WidgetsBrandComponent implements AfterContentInit {
2424
private changeDetectorRef = inject(ChangeDetectorRef);
2525

2626

27-
@Input() withCharts?: boolean;
27+
readonly withCharts = input<boolean>();
2828
// @ts-ignore
2929
chartOptions = {
3030
elements: {
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<c-callout class="bg-white:dark:bg-transparent" color="info">
2-
<ng-container *ngTemplateOutlet="default" />
2+
<ng-container *ngTemplateOutlet="defaultTpl" />
33
</c-callout>
44

5-
<ng-template #default>
6-
@if (!!name) {
5+
<ng-template #defaultTpl>
6+
@let componentName = name();
7+
@let isPlural = plural();
8+
@if (!!componentName) {
79
<p>
8-
An Angular {{ name }} component{{ plural ? 's' : '' }} {{ plural ? 'have' : 'has' }} been created as a native
10+
An Angular {{ componentName }} component{{ isPlural ? 's' : '' }} {{ isPlural ? 'have' : 'has' }} been created as a native
911
Angular
1012
version
11-
of Bootstrap {{ name }}. {{ name }} {{ plural ? 'are' : 'is' }} delivered with some new features,
13+
of Bootstrap {{ componentName }}. {{ componentName }} {{ isPlural ? 'are' : 'is' }} delivered with some new features,
1214
variants, and unique design that matches CoreUI Design System requirements.
1315
</p>
1416
}
1517

1618
<ng-content />
1719

1820
<br>
19-
For more information please visit our official <a href="{{href}}" target="_blank">documentation of CoreUI Components Library for Angular.</a>
21+
For more information please visit our official <a href="{{href()}}" target="_blank">documentation of CoreUI Components Library for Angular.</a>
2022
</ng-template>

src/components/docs-callout/docs-callout.component.scss

Whitespace-only changes.
Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
1-
import { Component, Input } from '@angular/core';
2-
import packageJson from '../../../package.json';
1+
import { Component, computed, input } from '@angular/core';
32
import { NgTemplateOutlet } from '@angular/common';
43
import { CalloutComponent } from '@coreui/angular';
4+
import packageJson from '../../../package.json';
55

66
@Component({
7-
selector: 'app-docs-callout',
8-
templateUrl: './docs-callout.component.html',
9-
styleUrls: ['./docs-callout.component.scss'],
10-
imports: [CalloutComponent, NgTemplateOutlet]
7+
selector: 'app-docs-callout',
8+
templateUrl: './docs-callout.component.html',
9+
imports: [CalloutComponent, NgTemplateOutlet]
1110
})
1211
export class DocsCalloutComponent {
1312

14-
@Input() name: string = '';
15-
16-
constructor() { }
13+
readonly name = input('');
1714

18-
private _href: string = 'https://coreui.io/angular/docs/';
15+
readonly hrefInput = input<string>('https://coreui.io/angular/docs/', { alias: 'href' });
1916

20-
get href(): string {
21-
return this._href;
22-
}
17+
readonly plural = computed(() => this.name()?.slice(-1) === 's');
2318

24-
@Input()
25-
set href(value: string) {
19+
readonly href = computed(() => {
2620
const version = packageJson?.config?.coreui_library_short_version;
2721
const docsUrl = packageJson?.config?.coreui_library_docs_url ?? 'https://coreui.io/angular/';
28-
// const path: string = version ? `${version}/${value}` : `${value}`;
29-
const path: string = value;
30-
this._href = `${docsUrl}${path}`;
31-
}
32-
33-
get plural() {
34-
return this.name?.slice(-1) === 's';
35-
}
36-
22+
const href = this.hrefInput();
23+
// const path: string = version ? `${version}/${href}` : `${href}`;
24+
const path: string = href;
25+
return `${docsUrl}${path}`;
26+
});
3727
}

src/components/docs-example/docs-example.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<c-nav variant="underline-border" class="border-bottom w-100">
22
<c-nav-item>
3-
<a [active]="true" [fragment]="fragment" [routerLink]="" cNavLink>
3+
<a [active]="true" [fragment]="fragment()" [routerLink]="" cNavLink>
44
<svg cIcon class="me-2" name="cilMediaPlay"></svg>
55
Preview
66
</a>
77
</c-nav-item>
88
<c-nav-item>
9-
<a [href]="href" cNavLink target="_blank">
9+
<a [href]="href()" cNavLink target="_blank">
1010
<svg cIcon class="me-2" name="cilCode"></svg>
1111
Code
1212
</a>
Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterContentInit, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, HostBinding, Input, inject } from '@angular/core';
1+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, computed, inject, input } from '@angular/core';
22

33
import packageJson from '../../../package.json';
44
import { IconDirective } from '@coreui/icons-angular';
@@ -10,38 +10,24 @@ import { NavComponent, NavItemComponent, NavLinkDirective } from '@coreui/angula
1010
templateUrl: './docs-example.component.html',
1111
styleUrls: ['./docs-example.component.scss'],
1212
changeDetection: ChangeDetectionStrategy.OnPush,
13-
imports: [NavComponent, NavItemComponent, NavLinkDirective, RouterLink, IconDirective]
13+
imports: [NavComponent, NavItemComponent, NavLinkDirective, RouterLink, IconDirective],
14+
host: {
15+
'class': 'example',
16+
}
1417
})
15-
export class DocsExampleComponent implements AfterContentInit, AfterViewInit {
16-
private changeDetectorRef = inject(ChangeDetectorRef);
18+
export class DocsExampleComponent {
19+
readonly #changeDetectorRef = inject(ChangeDetectorRef);
1720

21+
readonly hrefInput = input<string>('https://coreui.io/angular/docs/', { alias: 'href' });
22+
readonly fragment = input<string>();
1823

19-
@Input() fragment?: string;
20-
21-
@HostBinding('class.example')
22-
get exampleClass() {
23-
return true;
24-
};
25-
26-
private _href = 'https://coreui.io/angular/docs/';
27-
28-
get href(): string {
29-
return this._href;
30-
}
31-
32-
@Input()
33-
set href(value: string) {
24+
readonly href = computed(() => {
3425
const version = packageJson?.config?.coreui_library_short_version;
3526
const docsUrl = packageJson?.config?.coreui_library_docs_url ?? 'https://coreui.io/angular/';
36-
// const path: string = version ? `${version}/${value}` : '';
37-
this._href = `${docsUrl}${value}`;
38-
}
39-
40-
ngAfterContentInit(): void {
41-
// this.changeDetectorRef.detectChanges();
42-
}
43-
44-
ngAfterViewInit(): void {
45-
this.changeDetectorRef.markForCheck();
46-
}
27+
const href = this.hrefInput();
28+
// const path: string = version ? `${version}/${href}` : `${href}`;
29+
const path: string = href;
30+
this.#changeDetectorRef.markForCheck();
31+
return `${docsUrl}${path}`;
32+
});
4733
}

0 commit comments

Comments
 (0)