1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-18 16:33:47 +00:00
Files
browser/libs/components/src/badge-list/badge-list.component.ts
2025-02-03 20:11:59 +01:00

44 lines
1.1 KiB
TypeScript

// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Component, Input, OnChanges } from "@angular/core";
import { I18nPipe } from "@bitwarden/ui-common";
import { BadgeModule, BadgeVariant } from "../badge";
@Component({
selector: "bit-badge-list",
templateUrl: "badge-list.component.html",
standalone: true,
imports: [BadgeModule, I18nPipe],
})
export class BadgeListComponent implements OnChanges {
private _maxItems: number;
protected filteredItems: string[] = [];
protected isFiltered = false;
@Input() variant: BadgeVariant = "primary";
@Input() items: string[] = [];
@Input() truncate = true;
@Input()
get maxItems(): number | undefined {
return this._maxItems;
}
set maxItems(value: number | undefined) {
this._maxItems = value == undefined ? undefined : Math.max(1, value);
}
ngOnChanges() {
if (this.maxItems == undefined || this.items.length <= this.maxItems) {
this.filteredItems = this.items;
} else {
this.filteredItems = this.items.slice(0, this.maxItems - 1);
}
this.isFiltered = this.items.length > this.filteredItems.length;
}
}