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

[FEAT] Badge 컴포넌트, 스토리북 #31

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions src/shared/ui/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Badge } from './Badge';

const meta = {
title: 'Components/common/Badge',
component: Badge,
argTypes: {
color: { control: 'radio', options: ['red', 'green', 'gray'] },
text: { control: 'text' },
},
parameters: {
docs: {
autodocs: true,
},
},
} satisfies Meta<typeof Badge>;

export default meta;

export const Default: StoryObj<typeof Badge> = {
args: {
color: undefined,
text: '상태 없음',
},
};
46 changes: 46 additions & 0 deletions src/shared/ui/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';

type Props = {
/**
* - `'green'`: 초록색 (`bg-green-100 text-green-300`)
* - `'red'`: 빨간색 (`bg-red-100 text-red-300`)
* - `'gray'`: 회색 (`bg-gray-100 text-gray-400`)
* - `null`: 기본값 (회색)
*
* @default null
*/
color?: 'red' | 'green' | 'gray' | null;

/**
* 특정 상태가 없을 경우
*
* @default '상태 없음'
*/
text?: string;
} & React.HTMLAttributes<HTMLDivElement>;

/**
* `Badge` is a UI element that visually represents various statuses.
*/
export function Badge({ color, text, ...props }: Props) {
let badgeColor = 'bg-gray-100 text-gray-400';

if (color === 'green') {
badgeColor = 'bg-green-100 text-green-300';
} else if (color === 'red') {
badgeColor = 'bg-red-100 text-red-300';
} else if (color === 'gray') {
badgeColor = 'bg-gray-100 text-gray-400';
}

const badgeText = text ?? '상태 없음';

return (
<div
className={`w-min whitespace-nowrap rounded-xl p-1 px-2 font-semibold ${badgeColor}`}
{...props}
>
{badgeText}
</div>
);
}
1 change: 1 addition & 0 deletions src/shared/ui/Badge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Badge } from './Badge';
Loading