-
Notifications
You must be signed in to change notification settings - Fork 0
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
ujinsim
wants to merge
5
commits into
main
Choose a base branch
from
feat/#25-badge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+73
−0
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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' }, | ||
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: '상태 없음', | ||
}, | ||
}; |
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,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> | ||
); | ||
} |
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 @@ | ||
export { Badge } from './Badge'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
타입으로 되어있습니다. 일관성을 위해 다음과 같이 수정하는 것이 좋습니다.📝 Committable suggestion