Skip to content

Commit

Permalink
🎉 Badge 컴포넌트 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeon-park committed Oct 29, 2023
1 parent 67b2ee8 commit 1f9fe9e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/ui/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Badge } from './Badge'

const meta = {
title: 'UI/Badge',
component: Badge,
tags: ['autodocs'],
argTypes: {},
} satisfies Meta<typeof Badge>

export default meta
type Story = StoryObj<typeof meta>

export const Normal: Story = {
args: {
variant: 'gradation',
size: 'sm',
children: '거래성사',
},
}
42 changes: 42 additions & 0 deletions src/components/ui/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from 'react'
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from '@/utils'

const badgeVariants = cva(
'inline-flex items-center rounded-full px-2 font-medium',
{
variants: {
variant: {
primary: 'bg-primary-color text-white',
secondary: 'bg-secondary-color text-white',
gradation: 'bg-gradient-primary text-white',
information: 'bg-background-secondary-color text-black',
},
size: {
sm: 'h-[18px] text-xs',
lg: 'h-6 text-sm',
},
},
defaultVariants: {
variant: 'information',
size: 'sm',
},
},
)

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

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

Badge.displayName = 'Badge'

export { Badge, badgeVariants }
3 changes: 3 additions & 0 deletions src/components/ui/Badge/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Badge } from './Badge'

export default Badge

0 comments on commit 1f9fe9e

Please sign in to comment.