Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend): add Badge component (#10244)

Ubbe0b37263092c6
diff --git a/autogpt_platform/frontend/src/components/atoms/Badge/Badge.stories.tsx b/autogpt_platform/frontend/src/components/atoms/Badge/Badge.stories.tsx
new file mode 100644
index 0000000000..c502a85f3c
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/atoms/Badge/Badge.stories.tsx
@@ -0,0 +1,77 @@
+import type { Meta, StoryObj } from "@storybook/nextjs";
+import { Badge } from "./Badge";
+
+const meta: Meta<typeof Badge> = {
+ title: "Atoms/Badge",
+ tags: ["autodocs"],
+ component: Badge,
+ parameters: {
+ layout: "centered",
+ docs: {
+ description: {
+ component:
+ "Badge component for displaying status information with different variants for success, error, and info states.",
+ },
+ },
+ },
+ argTypes: {
+ variant: {
+ control: "select",
+ options: ["success", "error", "info"],
+ description: "Badge variant that determines color scheme",
+ },
+ children: {
+ control: "text",
+ description: "Badge content",
+ },
+ className: {
+ control: "text",
+ description: "Additional CSS classes",
+ },
+ },
+ args: {
+ variant: "success",
+ children: "Success",
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+export const Success: Story = {
+ args: {
+ variant: "success",
+ children: "Success",
+ },
+};
+
+export const Error: Story = {
+ args: {
+ variant: "error",
+ children: "Failed",
+ },
+};
+
+export const Info: Story = {
+ args: {
+ variant: "info",
+ children: "Stopped",
+ },
+};
+
+export const AllVariants: Story = {
+ render: renderAllVariants,
+};
+
+function renderAllVariants() {
+ return (
+ <div className="flex flex-wrap gap-4">
+ <Badge variant="success">Success</Badge>
+ <Badge variant="error">Failed</Badge>
+ <Badge variant="info">Stopped</Badge>
+ <Badge variant="info">Running</Badge>
+ <Badge variant="success">Completed</Badge>
+ <Badge variant="error">Error</Badge>
+ </div>
+ );
+}
diff --git a/autogpt_platform/frontend/src/components/atoms/Badge/Badge.test.tsx b/autogpt_platform/frontend/src/components/atoms/Badge/Badge.test.tsx
new file mode 100644
index 0000000000..cd8531375b
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/atoms/Badge/Badge.test.tsx
@@ -0,0 +1,81 @@
+// import { render, screen } from "@testing-library/react";
+// import { describe, expect, it } from "vitest";
+// import { Badge } from "./Badge";
+
+// describe("Badge Component", () => {
+// it("renders badge with content", () => {
+// render(<Badge variant="success">Success</Badge>);
+
+// expect(screen.getByText("Success")).toBeInTheDocument();
+// });
+
+// it("applies correct variant styles", () => {
+// const { rerender } = render(<Badge variant="success">Success</Badge>);
+// let badge = screen.getByText("Success");
+// expect(badge).toHaveClass("bg-green-100", "text-green-800");
+
+// rerender(<Badge variant="error">Error</Badge>);
+// badge = screen.getByText("Error");
+// expect(badge).toHaveClass("bg-red-100", "text-red-800");
+
+// rerender(<Badge variant="info">Info</Badge>);
+// badge = screen.getByText("Info");
+// expect(badge).toHaveClass("bg-slate-100", "text-slate-800");
+// });
+
+// it("applies custom className", () => {
+// render(
+// <Badge variant="success" className="custom-class">
+// Success
+// </Badge>,
+// );
+
+// const badge = screen.getByText("Success");
+// expect(badge).toHaveClass("custom-class");
+// });
+
+// it("renders as span element", () => {
+// render(<Badge variant="success">Success</Badge>);
+
+// const badge = screen.getByText("Success");
+// expect(badge.tagName).toBe("SPAN");
+// });
+
+// it("renders children correctly", () => {
+// render(
+// <Badge variant="success">
+// <span>Custom</span> Content
+// </Badge>,
+// );
+
+// expect(screen.getByText("Custom")).toBeInTheDocument();
+// expect(screen.getByText("Content")).toBeInTheDocument();
+// });
+
+// it("supports all badge variants", () => {
+// const variants = ["success", "error", "info"] as const;
+
+// variants.forEach((variant) => {
+// const { unmount } = render(
+// <Badge variant={variant} data-testid={`badge-${variant}`}>
+// {variant}
+// </Badge>,
+// );
+
+// expect(screen.getByTestId(`badge-${variant}`)).toBeInTheDocument();
+// unmount();
+// });
+// });
+
+// it("handles long text content", () => {
+// render(
+// <Badge variant="info">
+// Very long text that should be handled properly by the component
+// </Badge>,
+// );
+
+// const badge = screen.getByText(/Very long text/);
+// expect(badge).toBeInTheDocument();
+// expect(badge).toHaveClass("overflow-hidden", "text-ellipsis");
+// });
+// });
diff --git a/autogpt_platform/frontend/src/components/atoms/Badge/Badge.tsx b/autogpt_platform/frontend/src/components/atoms/Badge/Badge.tsx
new file mode 100644
index 0000000000..33e8ca6ab0
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/atoms/Badge/Badge.tsx
@@ -0,0 +1,35 @@
+import { cn } from "@/lib/utils";
+
+type BadgeVariant = "success" | "error" | "info";
+
+interface BadgeProps {
+ variant: BadgeVariant;
+ children: React.ReactNode;
+ className?: string;
+}
+
+const badgeVariants: Record<BadgeVariant, string> = {
+ success: "bg-green-100 text-green-800",
+ error: "bg-red-100 text-red-800",
+ info: "bg-slate-100 text-slate-800",
+};
+
+export function Badge({ variant, children, className }: BadgeProps) {
+ return (
+ <span
+ className={cn(
+ // Base styles from Figma
+ "inline-flex items-center gap-2 rounded-[45px] px-[9px] py-[3px]",
+ // Text styles
+ "font-['Geist'] text-xs font-medium leading-5",
+ // Text overflow handling
+ "overflow-hidden text-ellipsis",
+ // Variant styles
+ badgeVariants[variant],
+ className,
+ )}
+ >
+ {children}
+ </span>
+ );
+}