diff --git a/libs/components/src/banner/banner.component.html b/libs/components/src/banner/banner.component.html
index 63b4bc96d5d..63b1126104c 100644
--- a/libs/components/src/banner/banner.component.html
+++ b/libs/components/src/banner/banner.component.html
@@ -4,8 +4,8 @@
[attr.role]="useAlertRole() ? 'status' : null"
[attr.aria-live]="useAlertRole() ? 'polite' : null"
>
- @if (icon(); as iconClass) {
-
+ @if (icon(); as icon) {
+
}
diff --git a/libs/components/src/callout/callout.component.html b/libs/components/src/callout/callout.component.html
index 1b61316e441..b990e57a767 100644
--- a/libs/components/src/callout/callout.component.html
+++ b/libs/components/src/callout/callout.component.html
@@ -3,12 +3,12 @@
[ngClass]="calloutClass"
[attr.aria-labelledby]="titleId"
>
- @if (title(); as title) {
+ @if (titleComputed(); as title) {
- @if (icon(); as icon) {
+ @if (iconComputed(); as icon) {
{
describe("default state", () => {
it("success", () => {
- component.type = "success";
+ fixture.componentRef.setInput("type", "success");
fixture.detectChanges();
- expect(component.title).toBeUndefined();
- expect(component.icon).toBe("bwi-check-circle");
+ expect(component.titleComputed()).toBeUndefined();
+ expect(component.iconComputed()).toBe("bwi-check-circle");
});
it("info", () => {
- component.type = "info";
+ fixture.componentRef.setInput("type", "info");
fixture.detectChanges();
- expect(component.title).toBeUndefined();
- expect(component.icon).toBe("bwi-info-circle");
+ expect(component.titleComputed()).toBeUndefined();
+ expect(component.iconComputed()).toBe("bwi-info-circle");
});
it("warning", () => {
- component.type = "warning";
+ fixture.componentRef.setInput("type", "warning");
fixture.detectChanges();
- expect(component.title).toBe("Warning");
- expect(component.icon).toBe("bwi-exclamation-triangle");
+ expect(component.titleComputed()).toBe("Warning");
+ expect(component.iconComputed()).toBe("bwi-exclamation-triangle");
});
it("danger", () => {
- component.type = "danger";
+ fixture.componentRef.setInput("type", "danger");
fixture.detectChanges();
- expect(component.title).toBe("Error");
- expect(component.icon).toBe("bwi-error");
+ expect(component.titleComputed()).toBe("Error");
+ expect(component.iconComputed()).toBe("bwi-error");
});
});
});
diff --git a/libs/components/src/callout/callout.component.ts b/libs/components/src/callout/callout.component.ts
index 03c1d8f4131..137c1f8fdaa 100644
--- a/libs/components/src/callout/callout.component.ts
+++ b/libs/components/src/callout/callout.component.ts
@@ -1,6 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
-import { Component, OnInit, input, model } from "@angular/core";
+import { Component, computed, input } from "@angular/core";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
@@ -34,23 +34,26 @@ let nextId = 0;
templateUrl: "callout.component.html",
imports: [SharedModule, TypographyModule],
})
-export class CalloutComponent implements OnInit {
+export class CalloutComponent {
readonly type = input("info");
- icon = model();
- title = model();
+ readonly icon = input();
+ readonly title = input();
readonly useAlertRole = input(false);
+ readonly iconComputed = computed(() => this.icon() ?? defaultIcon[this.type()]);
+ readonly titleComputed = computed(() => {
+ const title = this.title();
+ const type = this.type();
+ if (title == null && defaultI18n[type] != null) {
+ return this.i18nService.t(defaultI18n[type]);
+ }
+
+ return title;
+ });
+
protected titleId = `bit-callout-title-${nextId++}`;
constructor(private i18nService: I18nService) {}
- ngOnInit() {
- const type = this.type();
- this.icon.update((icon) => icon === null && defaultIcon[type]);
- if (this.title() == null && defaultI18n[type] != null) {
- this.title.set(this.i18nService.t(defaultI18n[type]));
- }
- }
-
get calloutClass() {
switch (this.type()) {
case "danger":
diff --git a/libs/components/src/callout/callout.stories.ts b/libs/components/src/callout/callout.stories.ts
index 5f66cf8453d..4ac4191ce7e 100644
--- a/libs/components/src/callout/callout.stories.ts
+++ b/libs/components/src/callout/callout.stories.ts
@@ -68,3 +68,18 @@ export const Danger: Story = {
type: "danger",
},
};
+
+export const CustomIcon: Story = {
+ ...Info,
+ args: {
+ ...Info.args,
+ icon: "bwi-star",
+ },
+};
+
+export const NoTitle: Story = {
+ ...Info,
+ args: {
+ icon: "bwi-star",
+ },
+};