Skip to content

Commit

Permalink
feat: Badge component
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Jul 8, 2024
1 parent da54c40 commit 25c0d32
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/v2/components/ui/Badge.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { Meta, StoryObj } from "@storybook/react"
import { Badge, BadgeProps } from "./Badge"

const meta: Meta<typeof Badge> = {
title: "Design system/Badge",
component: Badge,
}

export default meta

type Story = StoryObj<typeof Badge>

export const Default: Story = {
args: {
children: "Default",
variant: "default",
size: "md",
},
argTypes: {
variant: {
control: {
disable: true,
},
},
size: {
type: "string",
control: "radio",
options: ["sm", "md", "lg"] satisfies BadgeProps["size"][],
},
},
}

export const Secondary: Story = {
args: {
...Default.args,
children: "Secondary",
variant: "secondary",
},
argTypes: Default.argTypes,
}

export const Destructive: Story = {
args: {
...Default.args,
children: "Destructive",
variant: "destructive",
},
argTypes: Default.argTypes,
}

export const Outline: Story = {
args: {
...Default.args,
children: "Outline",
variant: "outline",
},
argTypes: Default.argTypes,
}
39 changes: 39 additions & 0 deletions src/v2/components/ui/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { cn } from "@/lib/utils"
import { cva, type VariantProps } from "class-variance-authority"
import { HTMLAttributes } from "react"

const badgeVariants = cva(
"inline-flex items-center rounded-md border-2 px-2 transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default: "border-transparent bg-primary text-primary-foreground shadow",
secondary: "border-transparent bg-secondary text-secondary-foreground",
destructive:
"border-transparent bg-destructive text-destructive-foreground shadow",
outline: "text-foreground",
},
size: {
sm: "text-xs h-5",
md: "text-sm h-6",
lg: "text-base h-8",
},
},
defaultVariants: {
variant: "default",
size: "md",
},
}
)

export interface BadgeProps
extends HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, size, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant, size }), className)} {...props} />
)
}

export { Badge, badgeVariants }

0 comments on commit 25c0d32

Please sign in to comment.