Skip to content

Commit b568987

Browse files
feat: badge component (#53)
1 parent 5c583ff commit b568987

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

.changeset/swift-games-study.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zenml-io/react-component-library": minor
3+
---
4+
5+
add badge component
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Meta } from "@storybook/react";
2+
import { Badge } from "./index";
3+
import { StoryObj } from "@storybook/react";
4+
5+
const meta = {
6+
title: "Elements/Badge",
7+
component: Badge,
8+
argTypes: {
9+
color: {
10+
control: "select",
11+
defaultValue: "green",
12+
options: [
13+
"green",
14+
"yellow",
15+
"light-purple",
16+
"purple",
17+
"blue",
18+
"light-grey",
19+
"grey",
20+
"red",
21+
"orange",
22+
"lime",
23+
"teal",
24+
"turquoise",
25+
"magenta"
26+
]
27+
},
28+
size: {
29+
control: "select",
30+
defaultValue: "sm",
31+
options: ["xs", "sm", "md"]
32+
},
33+
rounded: {
34+
control: "boolean",
35+
defaultValue: true
36+
}
37+
},
38+
parameters: {
39+
layout: "centered"
40+
},
41+
42+
tags: ["autodocs"]
43+
} satisfies Meta<typeof Badge>;
44+
45+
export default meta;
46+
47+
type Story = StoryObj<typeof meta>;
48+
49+
export const defaultVariant: Story = {
50+
name: "Default",
51+
args: {
52+
rounded: true,
53+
color: "green",
54+
size: "sm",
55+
children: "Badge"
56+
}
57+
};

src/components/Badge/Badge.tsx

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { cva, VariantProps } from "class-variance-authority";
2+
import React, { HTMLAttributes } from "react";
3+
import { cn } from "../../utilities";
4+
5+
export const badgeVariants = cva("inline-flex items-center", {
6+
variants: {
7+
rounded: {
8+
true: "rounded-rounded",
9+
false: "rounded-sm"
10+
},
11+
size: {
12+
xs: "text-text-xs px-0.5",
13+
sm: "text-text-xs py-0.5 px-2 h-5",
14+
md: "text-text-sm py-0.5 px-2 h-6"
15+
},
16+
color: {
17+
green: "bg-success-100 text-success-800",
18+
yellow: "bg-warning-200 text-warning-900",
19+
"light-purple": "bg-primary-25 text-primary-500",
20+
purple: "bg-primary-50 text-primary-500",
21+
blue: "bg-blue-50 text-blue-600",
22+
"light-grey": "bg-neutral-100 text-theme-text-secondary",
23+
grey: "bg-neutral-200 text-theme-text-primary",
24+
red: "bg-error-100 text-error-700",
25+
orange: "bg-orange-100 text-orange-700",
26+
lime: "bg-lime-100 text-lime-800",
27+
teal: "bg-teal-100 text-teal-700",
28+
turquoise: "bg-turquoise-100 text-turquoise-700",
29+
magenta: "bg-magenta-100 text-magenta-700"
30+
}
31+
},
32+
defaultVariants: {
33+
color: "purple",
34+
rounded: true,
35+
size: "md"
36+
}
37+
});
38+
39+
interface ButtonVariants
40+
extends Omit<HTMLAttributes<HTMLDivElement>, "color">,
41+
VariantProps<typeof badgeVariants> {}
42+
43+
export function Badge({ children, className, color, rounded, size, ...rest }: ButtonVariants) {
44+
return (
45+
<div {...rest} className={cn(badgeVariants({ color, rounded, size }), className)}>
46+
{children}
47+
</div>
48+
);
49+
}

src/components/Badge/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Badge";

src/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from "./Skeleton";
77
export * from "./Dropdown";
88
export * from "./Table";
99
export * from "./Tag";
10+
export * from "./Badge";

0 commit comments

Comments
 (0)