Skip to content

Commit 0d26c63

Browse files
committed
chore: Bump package version to 1.0.221 and enhance Badge component
- Update package version in package.json to 1.0.221 - Introduce BadgeVariantEnum for variant management in Badge component - Refactor Badge component to apply styles based on variant - Add new stories for different badge variants in Badge.stories.tsx - Update tests to reflect changes in Badge component and its variants
1 parent f8ffb2d commit 0d26c63

File tree

6 files changed

+67
-9
lines changed

6 files changed

+67
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.220",
3+
"version": "1.0.221",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {

src/Components/Badge/Badge.stories.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22

33
import Badge from ".";
4+
import { BadgeVariantEnum } from "./types";
45

56
const meta = {
67
title: "Core/Badge",
@@ -15,9 +16,30 @@ const meta = {
1516
export default meta;
1617
type Story = StoryObj<typeof meta>;
1718

19+
export const Empty: Story = {
20+
args: {
21+
title: "Badge",
22+
variant: BadgeVariantEnum.PRIMARY
23+
}
24+
};
25+
1826
export const Filled: Story = {
1927
args: {
2028
title: "Badge",
21-
className: "yl:bg-primary-500"
29+
variant: BadgeVariantEnum.PRIMARY
30+
}
31+
};
32+
33+
export const Beta: Story = {
34+
args: {
35+
title: "Beta",
36+
variant: BadgeVariantEnum.BETA
37+
}
38+
};
39+
40+
export const New: Story = {
41+
args: {
42+
title: "New",
43+
variant: BadgeVariantEnum.NEW
2244
}
2345
};

src/Components/Badge/Badge.test.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import { render, screen } from "@testing-library/react";
22

33
import Badge from "./";
4+
import { BadgeVariantEnum } from "./types";
45

56
describe("Badge component", () => {
67
const testTitle = "Test Badge";
78

89
test("renders correctly - snapshot test", () => {
9-
const { asFragment } = render(<Badge title={testTitle} />);
10+
const { asFragment } = render(
11+
<Badge title={testTitle} variant={BadgeVariantEnum.PRIMARY} />
12+
);
1013
expect(asFragment()).toMatchSnapshot();
1114
});
1215

1316
test("renders the title correctly", () => {
14-
render(<Badge title={testTitle} />);
17+
render(<Badge title={testTitle} variant={BadgeVariantEnum.PRIMARY} />);
1518
const badgeElement = screen.getByText(testTitle);
1619
expect(badgeElement).toBeInTheDocument();
1720
});
1821

1922
test("applies custom class name", () => {
2023
const customClass = "custom-class";
21-
render(<Badge title={testTitle} className={customClass} />);
24+
render(
25+
<Badge
26+
title={testTitle}
27+
variant={BadgeVariantEnum.PRIMARY}
28+
className={customClass}
29+
/>
30+
);
2231
const badgeElement = screen.getByText(testTitle);
2332
expect(badgeElement).toHaveClass(customClass);
2433
});

src/Components/Badge/__snapshots__/Badge.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Badge component > renders correctly - snapshot test 1`] = `
44
<DocumentFragment>
55
<span
6-
class="yl:rounded yl:border yl:border-border yl:px-1 yl:pb-[2px] yl:pt-[1px] yl:text-[10px] yl:text-text"
6+
class="yl:rounded yl:border yl:border-border yl:px-2 yl:py-1 yl:text-[10px] yl:bg-primary"
77
>
88
Test Badge
99
</span>

src/Components/Badge/index.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import classNames from "classnames";
22
import { FC } from "react";
33

4-
import { IBadgeProps } from "./types";
4+
import { BadgeVariantEnum, IBadgeProps } from "./types";
5+
6+
const Badge: FC<IBadgeProps> = ({ title, className, variant }) => {
7+
const variants = {
8+
[BadgeVariantEnum.PRIMARY]: "yl:bg-primary",
9+
[BadgeVariantEnum.SECONDARY]: "yl:bg-secondary",
10+
[BadgeVariantEnum.SUCCESS]: "yl:bg-success",
11+
[BadgeVariantEnum.WARNING]: "yl:bg-warning",
12+
[BadgeVariantEnum.ERROR]: "yl:bg-error",
13+
[BadgeVariantEnum.BETA]: "yl:bg-violet-500",
14+
[BadgeVariantEnum.NEW]: "yl:bg-blue-500"
15+
};
16+
17+
const baseClassNames =
18+
"yl:rounded yl:border yl:border-border yl:px-2 yl:py-1 yl:text-[10px]";
519

6-
const Badge: FC<IBadgeProps> = ({ title, className }) => {
720
return (
821
<span
922
className={classNames(
10-
"yl:rounded yl:border yl:border-border yl:px-1 yl:pb-[2px] yl:pt-[1px] yl:text-[10px] yl:text-text",
23+
baseClassNames,
24+
{
25+
[variants[variant]]: variant
26+
},
1127
className
1228
)}
1329
>

src/Components/Badge/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1+
export enum BadgeVariantEnum {
2+
PRIMARY = "primary",
3+
SECONDARY = "secondary",
4+
SUCCESS = "success",
5+
WARNING = "warning",
6+
ERROR = "error",
7+
BETA = "beta",
8+
NEW = "new"
9+
}
10+
111
export interface IBadgeProps {
212
title: string;
313
className?: string;
14+
variant: BadgeVariantEnum;
415
}

0 commit comments

Comments
 (0)