Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Badge 컴포넌트 구현 #13

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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