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 1 commit
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
25 changes: 25 additions & 0 deletions src/shared/ui/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Badge } from './Badge';

export default {
title: 'Components/common/Badge',
component: Badge,
argTypes: {
isSubmited: { control: 'radio', options: [true, false, null] },
isProgress: { control: 'radio', options: [true, false, null] },
isRecriting: { control: 'boolean' },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

isRecriting 속성의 제어 타입이 일관성이 없습니다.

다른 상태 속성들은 radio 타입으로 null 옵션을 포함하고 있는데 반해, isRecriting 속성만 boolean 타입으로 되어있습니다. 일관성을 위해 다음과 같이 수정하는 것이 좋습니다.

-    isRecriting: { control: 'boolean' },
+    isRecriting: { control: 'radio', options: [true, false, null] },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
isRecriting: { control: 'boolean' },
isRecriting: { control: 'radio', options: [true, false, null] },

color: { control: 'radio', options: [true, false, undefined] },
text: { control: 'text' },
ujinsim marked this conversation as resolved.
Show resolved Hide resolved
},
} satisfies Meta<typeof Badge>;

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

type Props = {
/**
* 제출 여부를 나타냅니다.
* - `true`: 제출 완료 (green)
* - `false`: 미제출 (red)
* - `null`: 제출 전 (gray)
*/
isSubmited?: boolean | null;

/**
* 진행 상태를 나타냅니다.
* - `true`: 진행 중 (green)
* - `false`: 마감 (red)
* - `null`: 진행 전 (gray)
*/
isProgress?: boolean | null;

/**
* 모집 상태를 나타냅니다.
* - `true`: 모집 중 (green)
* - `false`: 모집 마감 (gray)
*/
isRecriting?: boolean;

/**
* - `true`: 초록색 (`bg-green-100 text-green-300`)
* - `false`: 빨간색 (`bg-red-100 text-red-300`)
* - `null`: 회색 (`bg-gray-100 text-gray-400`)
*
* @default null
*/
color?: boolean | null;

/**
* 특정 상태가 없을 경우, text값이 표시됩니다.
*
* @default '상태 없음'
*/
text?: string;
};
ujinsim marked this conversation as resolved.
Show resolved Hide resolved

/**
* `Badge` is a UI element that visually represents various statuses.
*/
export function Badge({ isSubmited, isProgress, isRecriting, color, text }: Props) {
let badgeColor = 'bg-gray-100 text-gray-400';
let badgeText = text ?? '상태 없음';

if (isRecriting !== undefined) {
badgeColor = isRecriting ? 'bg-green-100 text-green-300' : 'bg-gray-100 text-gray-400';
badgeText = isRecriting ? '모집 중' : '모집 마감';
} else if (isProgress !== undefined) {
if (isProgress === null) {
badgeColor = 'bg-gray-100 text-gray-400';
badgeText = '진행 전';
} else {
badgeColor = isProgress ? 'bg-green-100 text-green-300' : 'bg-red-100 text-red-300';
badgeText = isProgress ? '진행 중' : '마감';
}
} else if (isSubmited !== undefined) {
if (isSubmited === null) {
badgeColor = 'bg-gray-100 text-gray-400';
badgeText = '제출 전';
} else {
badgeColor = isSubmited ? 'bg-green-100 text-green-300' : 'bg-red-100 text-red-300';
badgeText = isSubmited ? '제출 완료' : '미제출';
}
} else if (color !== undefined) {
badgeColor =
color === true
? 'bg-green-100 text-green-300'
: color === false
? 'bg-red-100 text-red-300'
: 'bg-gray-100 text-gray-400';
}

return (
<div className={`w-min whitespace-nowrap rounded-xl p-1 px-2 font-semibold ${badgeColor}`}>
{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';