-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da54c40
commit 25c0d32
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |