1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 23:33:31 +00:00

[CL-160] Rename BadgeType to BadgeVariant (#7244)

We're establishing a common language for the Component Library. As part of this work we're renaming componentType to variant. Starting with badges.
This commit is contained in:
Oscar Hinton
2023-12-19 19:22:37 +01:00
committed by GitHub
parent 6122dbf96f
commit 017da06f9a
30 changed files with 91 additions and 93 deletions

View File

@@ -1,8 +1,8 @@
import { Directive, ElementRef, HostBinding, Input } from "@angular/core";
export type BadgeTypes = "primary" | "secondary" | "success" | "danger" | "warning" | "info";
export type BadgeVariant = "primary" | "secondary" | "success" | "danger" | "warning" | "info";
const styles: Record<BadgeTypes, string[]> = {
const styles: Record<BadgeVariant, string[]> = {
primary: ["tw-bg-primary-500"],
secondary: ["tw-bg-text-muted"],
success: ["tw-bg-success-500"],
@@ -11,7 +11,7 @@ const styles: Record<BadgeTypes, string[]> = {
info: ["tw-bg-info-500"],
};
const hoverStyles: Record<BadgeTypes, string[]> = {
const hoverStyles: Record<BadgeVariant, string[]> = {
primary: ["hover:tw-bg-primary-700"],
secondary: ["hover:tw-bg-secondary-700"],
success: ["hover:tw-bg-success-700"],
@@ -44,15 +44,22 @@ export class BadgeDirective {
"focus:tw-ring-offset-2",
"focus:tw-ring-primary-700",
]
.concat(styles[this.badgeType])
.concat(this.hasHoverEffects ? hoverStyles[this.badgeType] : [])
.concat(styles[this.variant])
.concat(this.hasHoverEffects ? hoverStyles[this.variant] : [])
.concat(this.truncate ? ["tw-truncate", "tw-max-w-40"] : []);
}
@HostBinding("attr.title") get title() {
return this.truncate ? this.el.nativeElement.textContent.trim() : null;
}
@Input() badgeType: BadgeTypes = "primary";
/**
* Variant, sets the background color of the badge.
*/
@Input() variant: BadgeVariant = "primary";
/**
* Truncate long text
*/
@Input() truncate = true;
private hasHoverEffects = false;

View File

@@ -13,7 +13,7 @@ export default {
}),
],
args: {
badgeType: "primary",
variant: "primary",
truncate: false,
},
parameters: {
@@ -30,11 +30,11 @@ export const Primary: Story = {
render: (args) => ({
props: args,
template: `
<span class="tw-text-main">Span </span><span bitBadge [badgeType]="badgeType" [truncate]="truncate">Badge containing lengthy text</span>
<span class="tw-text-main">Span </span><span bitBadge [variant]="variant" [truncate]="truncate">Badge containing lengthy text</span>
<br><br>
<span class="tw-text-main">Link </span><a href="#" bitBadge [badgeType]="badgeType" [truncate]="truncate">Badge</a>
<span class="tw-text-main">Link </span><a href="#" bitBadge [variant]="variant" [truncate]="truncate">Badge</a>
<br><br>
<span class="tw-text-main">Button </span><button bitBadge [badgeType]="badgeType" [truncate]="truncate">Badge</button>
<span class="tw-text-main">Button </span><button bitBadge [variant]="variant" [truncate]="truncate">Badge</button>
`,
}),
};
@@ -42,35 +42,35 @@ export const Primary: Story = {
export const Secondary: Story = {
...Primary,
args: {
badgeType: "secondary",
variant: "secondary",
},
};
export const Success: Story = {
...Primary,
args: {
badgeType: "success",
variant: "success",
},
};
export const Danger: Story = {
...Primary,
args: {
badgeType: "danger",
variant: "danger",
},
};
export const Warning: Story = {
...Primary,
args: {
badgeType: "warning",
variant: "warning",
},
};
export const Info: Story = {
...Primary,
args: {
badgeType: "info",
variant: "info",
},
};

View File

@@ -1,2 +1,2 @@
export { BadgeDirective, BadgeTypes } from "./badge.directive";
export { BadgeDirective, BadgeVariant } from "./badge.directive";
export * from "./badge.module";