Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CL-553] Migrate CL to Control Flow syntax #12390

Merged
merged 11 commits into from
Feb 3, 2025
8 changes: 5 additions & 3 deletions libs/components/src/avatar/avatar.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { NgIf, NgClass } from "@angular/common";
import { NgClass } from "@angular/common";
import { Component, Input, OnChanges } from "@angular/core";
import { DomSanitizer, SafeResourceUrl } from "@angular/platform-browser";

Expand All @@ -18,9 +18,11 @@ const SizeClasses: Record<SizeTypes, string[]> = {

@Component({
selector: "bit-avatar",
template: `<img *ngIf="src" [src]="src" title="{{ title || text }}" [ngClass]="classList" />`,
template: `@if (src) {
<img [src]="src" title="{{ title || text }}" [ngClass]="classList" />
}`,
standalone: true,
imports: [NgIf, NgClass],
imports: [NgClass],
})
export class AvatarComponent implements OnChanges {
@Input() border = false;
Expand Down
16 changes: 10 additions & 6 deletions libs/components/src/badge-list/badge-list.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<div class="tw-inline-flex tw-flex-wrap tw-gap-2">
<ng-container *ngFor="let item of filteredItems; let last = last">
@for (item of filteredItems; track item; let last = $last) {
<span bitBadge [variant]="variant" [truncate]="truncate">
{{ item }}
</span>
<span class="tw-sr-only" *ngIf="!last || isFiltered">, </span>
</ng-container>
<span *ngIf="isFiltered" bitBadge [variant]="variant">
{{ "plusNMore" | i18n: (items.length - filteredItems.length).toString() }}
</span>
@if (!last || isFiltered) {
<span class="tw-sr-only">, </span>
}
}
@if (isFiltered) {
<span bitBadge [variant]="variant">
{{ "plusNMore" | i18n: (items.length - filteredItems.length).toString() }}
</span>
}
</div>
4 changes: 2 additions & 2 deletions libs/components/src/badge-list/badge-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { CommonModule } from "@angular/common";

import { Component, Input, OnChanges } from "@angular/core";

import { I18nPipe } from "@bitwarden/ui-common";
Expand All @@ -11,7 +11,7 @@ import { BadgeModule, BadgeVariant } from "../badge";
selector: "bit-badge-list",
templateUrl: "badge-list.component.html",
standalone: true,
imports: [CommonModule, BadgeModule, I18nPipe],
imports: [BadgeModule, I18nPipe],
})
export class BadgeListComponent implements OnChanges {
private _maxItems: number;
Expand Down
27 changes: 15 additions & 12 deletions libs/components/src/banner/banner.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
[attr.role]="useAlertRole ? 'status' : null"
[attr.aria-live]="useAlertRole ? 'polite' : null"
>
<i class="bwi tw-align-middle tw-text-base" [ngClass]="icon" *ngIf="icon" aria-hidden="true"></i>
@if (icon) {
<i class="bwi tw-align-middle tw-text-base" [ngClass]="icon" aria-hidden="true"></i>
}
<!-- Overriding focus-visible color for link buttons for a11y against colored background -->
<span class="tw-grow tw-text-base [&>button[bitlink]:focus-visible:before]:!tw-ring-text-main">
<ng-content></ng-content>
</span>
<!-- Overriding hover and focus-visible colors for a11y against colored background -->
<button
*ngIf="showClose"
class="hover:tw-border-text-main focus-visible:before:tw-ring-text-main"
type="button"
bitIconButton="bwi-close"
buttonType="main"
size="default"
(click)="onClose.emit()"
[attr.title]="'close' | i18n"
[attr.aria-label]="'close' | i18n"
></button>
@if (showClose) {
<button
class="hover:tw-border-text-main focus-visible:before:tw-ring-text-main"
type="button"
bitIconButton="bwi-close"
buttonType="main"
size="default"
(click)="onClose.emit()"
[attr.title]="'close' | i18n"
[attr.aria-label]="'close' | i18n"
></button>
}
</div>
5 changes: 4 additions & 1 deletion libs/components/src/breadcrumbs/breadcrumb.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<ng-template>
<i *ngIf="icon" class="bwi {{ icon }} !tw-mr-2" aria-hidden="true"></i><ng-content></ng-content>
@if (icon) {
<i class="bwi {{ icon }} !tw-mr-2" aria-hidden="true"></i>
}
<ng-content></ng-content>
</ng-template>
3 changes: 1 addition & 2 deletions libs/components/src/breadcrumbs/breadcrumb.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { NgIf } from "@angular/common";

import { Component, EventEmitter, Input, Output, TemplateRef, ViewChild } from "@angular/core";
import { QueryParamsHandling } from "@angular/router";

@Component({
selector: "bit-breadcrumb",
templateUrl: "./breadcrumb.component.html",
standalone: true,
imports: [NgIf],
})
export class BreadcrumbComponent {
@Input()
Expand Down
55 changes: 29 additions & 26 deletions libs/components/src/breadcrumbs/breadcrumbs.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-container *ngFor="let breadcrumb of beforeOverflow; let last = last">
<ng-container *ngIf="breadcrumb.route">
@for (breadcrumb of beforeOverflow; track breadcrumb; let last = $last) {
@if (breadcrumb.route) {
<a
bitLink
linkType="primary"
Expand All @@ -10,8 +10,8 @@
>
<ng-container [ngTemplateOutlet]="breadcrumb.content"></ng-container>
</a>
</ng-container>
<ng-container *ngIf="!breadcrumb.route">
}
@if (!breadcrumb.route) {
<button
type="button"
bitLink
Expand All @@ -21,24 +21,26 @@
>
<ng-container [ngTemplateOutlet]="breadcrumb.content"></ng-container>
</button>
</ng-container>
<i *ngIf="!last" class="bwi bwi-angle-right tw-mx-1.5 tw-text-main"></i>
</ng-container>

<ng-container *ngIf="hasOverflow">
<i *ngIf="beforeOverflow.length > 0" class="bwi bwi-angle-right tw-mx-1.5 tw-text-main"></i>
}
@if (!last) {
<i class="bwi bwi-angle-right tw-mx-1.5 tw-text-main"></i>
}
}

@if (hasOverflow) {
@if (beforeOverflow.length > 0) {
<i class="bwi bwi-angle-right tw-mx-1.5 tw-text-main"></i>
}
<button
type="button"
bitIconButton="bwi-ellipsis-h"
[bitMenuTriggerFor]="overflowMenu"
size="small"
aria-haspopup
></button>

<bit-menu #overflowMenu>
<ng-container *ngFor="let breadcrumb of overflow">
<ng-container *ngIf="breadcrumb.route">
@for (breadcrumb of overflow; track breadcrumb) {
@if (breadcrumb.route) {
<a
bitMenuItem
linkType="primary"
Expand All @@ -48,18 +50,17 @@
>
<ng-container [ngTemplateOutlet]="breadcrumb.content"></ng-container>
</a>
</ng-container>
<ng-container *ngIf="!breadcrumb.route">
}
@if (!breadcrumb.route) {
<button type="button" bitMenuItem linkType="primary" (click)="breadcrumb.onClick($event)">
<ng-container [ngTemplateOutlet]="breadcrumb.content"></ng-container>
</button>
</ng-container>
</ng-container>
}
}
</bit-menu>
<i class="bwi bwi-angle-right tw-mx-1.5 tw-text-main"></i>

<ng-container *ngFor="let breadcrumb of afterOverflow; let last = last">
<ng-container *ngIf="breadcrumb.route">
@for (breadcrumb of afterOverflow; track breadcrumb; let last = $last) {
@if (breadcrumb.route) {
<a
bitLink
linkType="primary"
Expand All @@ -70,8 +71,8 @@
>
<ng-container [ngTemplateOutlet]="breadcrumb.content"></ng-container>
</a>
</ng-container>
<ng-container *ngIf="!breadcrumb.route">
}
@if (!breadcrumb.route) {
<button
type="button"
bitLink
Expand All @@ -81,7 +82,9 @@
>
<ng-container [ngTemplateOutlet]="breadcrumb.content"></ng-container>
</button>
</ng-container>
<i *ngIf="!last" class="bwi bwi-angle-right tw-mx-1.5 tw-text-main"></i>
</ng-container>
</ng-container>
}
@if (!last) {
<i class="bwi bwi-angle-right tw-mx-1.5 tw-text-main"></i>
}
}
}
7 changes: 3 additions & 4 deletions libs/components/src/button/button.stories.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool that the migrator could link this if/else even though we were not already using NgIf's else syntax.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I manually migrated this. The migrator doesn't work in storybook.

Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ export const DisabledWithAttribute: Story = {
render: (args) => ({
props: args,
template: `
<ng-container *ngIf="disabled">
@if (disabled) {
<button bitButton disabled [loading]="loading" [block]="block" buttonType="primary" class="tw-mr-2">Primary</button>
<button bitButton disabled [loading]="loading" [block]="block" buttonType="secondary" class="tw-mr-2">Secondary</button>
<button bitButton disabled [loading]="loading" [block]="block" buttonType="danger" class="tw-mr-2">Danger</button>
</ng-container>
<ng-container *ngIf="!disabled">
} @else {
<button bitButton [loading]="loading" [block]="block" buttonType="primary" class="tw-mr-2">Primary</button>
<button bitButton [loading]="loading" [block]="block" buttonType="secondary" class="tw-mr-2">Secondary</button>
<button bitButton [loading]="loading" [block]="block" buttonType="danger" class="tw-mr-2">Danger</button>
</ng-container>
}
`,
}),
args: {
Expand Down
12 changes: 8 additions & 4 deletions libs/components/src/callout/callout.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
[ngClass]="calloutClass"
[attr.aria-labelledby]="titleId"
>
<header id="{{ titleId }}" class="tw-mb-1 tw-mt-0 tw-text-base tw-font-semibold" *ngIf="title">
<i class="bwi" [ngClass]="[icon, headerClass]" *ngIf="icon" aria-hidden="true"></i>
{{ title }}
</header>
@if (title) {
<header id="{{ titleId }}" class="tw-mb-1 tw-mt-0 tw-text-base tw-font-semibold">
@if (icon) {
<i class="bwi" [ngClass]="[icon, headerClass]" aria-hidden="true"></i>
}
{{ title }}
</header>
}
<div bitTypography="body2">
<ng-content></ng-content>
</div>
Expand Down
2 changes: 0 additions & 2 deletions libs/components/src/card/card.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { CommonModule } from "@angular/common";
import { ChangeDetectionStrategy, Component } from "@angular/core";

@Component({
selector: "bit-card",
standalone: true,
imports: [CommonModule],
template: `<ng-content></ng-content>`,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
Expand Down
Loading
Loading