-
Notifications
You must be signed in to change notification settings - Fork 1
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
[#364] Badge 컴포넌트 #396
Merged
[#364] Badge 컴포넌트 #396
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,56 @@ | ||
import Badge from '@/ui/Base/Badge'; | ||
import { IconHeart } from '@public/icons'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta: Meta<typeof Badge> = { | ||
title: 'Base/Badge', | ||
component: Badge, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Badge>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
size: 'small', | ||
colorScheme: 'main-light', | ||
fontWeight: 'bold', | ||
}, | ||
render: args => <Badge {...args}>프론트엔드 개발자</Badge>, | ||
}; | ||
|
||
export const BookshelfLike: Story = { | ||
args: { | ||
size: 'small', | ||
colorScheme: 'red', | ||
fontWeight: 'bold', | ||
}, | ||
render: args => ( | ||
<Badge {...args}> | ||
<div className="h-[1.3rem] w-[1.3rem] fill-white"> | ||
<IconHeart /> | ||
</div> | ||
99 | ||
</Badge> | ||
), | ||
}; | ||
|
||
export const GroupProgress: Story = { | ||
args: { | ||
size: 'large', | ||
colorScheme: 'main', | ||
fontWeight: 'bold', | ||
}, | ||
render: args => <Badge {...args}>진행중</Badge>, | ||
}; | ||
|
||
export const GroupDisclosure: Story = { | ||
args: { | ||
size: 'medium', | ||
colorScheme: 'grey', | ||
fontWeight: 'normal', | ||
}, | ||
render: args => <Badge {...args}>공개</Badge>, | ||
}; |
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,93 @@ | ||
import { PropsWithChildren, useMemo } from 'react'; | ||
|
||
type Size = 'small' | 'medium' | 'large'; | ||
type ColorScheme = 'main' | 'main-light' | 'grey' | 'red'; | ||
type FontWeight = 'thin' | 'normal' | 'bold'; | ||
|
||
type BadgeProps = PropsWithChildren<{ | ||
size?: Size; | ||
colorScheme?: ColorScheme; | ||
fontWeight?: FontWeight; | ||
isFilled?: boolean; | ||
}>; | ||
|
||
const getSizeClasses = (size: Size) => { | ||
switch (size) { | ||
case 'small': { | ||
return 'h-[1.8rem] text-2xs'; | ||
} | ||
case 'medium': { | ||
return 'h-[1.9rem] text-xs'; | ||
} | ||
case 'large': { | ||
return 'h-[2.1rem] text-xs'; | ||
} | ||
} | ||
}; | ||
|
||
const getSchemeClasses = (colorScheme: ColorScheme, isFilled: boolean) => { | ||
switch (colorScheme) { | ||
case 'main': { | ||
return isFilled | ||
? 'border-main-900 bg-main-900 text-white' | ||
: 'border-main-900 text-main-900'; | ||
} | ||
case 'main-light': { | ||
return isFilled | ||
? 'border-main-600 bg-main-600 text-white' | ||
: 'border-main-600 text-main-600'; | ||
} | ||
case 'grey': { | ||
return isFilled | ||
? 'border-black-100 bg-black-100 text-black-500' | ||
: 'border-black-500 text-black-500'; | ||
} | ||
case 'red': { | ||
return isFilled | ||
? 'border-warning-800 bg-warning-800 text-white' | ||
: 'border-warning-800 text-warning-800'; | ||
} | ||
} | ||
}; | ||
|
||
const getFontWeightClasses = (fontWeight: FontWeight) => { | ||
switch (fontWeight) { | ||
case 'thin': { | ||
return 'font-thin'; | ||
} | ||
case 'normal': { | ||
return 'font-normal'; | ||
} | ||
case 'bold': { | ||
return 'font-bold'; | ||
} | ||
} | ||
}; | ||
|
||
const Badge = ({ | ||
size = 'medium', | ||
colorScheme = 'main', | ||
fontWeight = 'normal', | ||
isFilled = true, | ||
children, | ||
...props | ||
}: BadgeProps) => { | ||
const computedClasses = useMemo(() => { | ||
const sizeClass = getSizeClasses(size); | ||
const schemeClass = getSchemeClasses(colorScheme, isFilled); | ||
const fontWeightClass = getFontWeightClasses(fontWeight); | ||
|
||
return [sizeClass, schemeClass, fontWeightClass].join(' '); | ||
}, [size, colorScheme, isFilled, fontWeight]); | ||
|
||
return ( | ||
<div | ||
className={`m-0 flex w-fit items-center justify-center gap-[0.4rem] rounded-[0.5rem] border-[0.05rem] px-[0.8rem] py-[0.25rem] ${computedClasses}`} | ||
{...props} | ||
> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default 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.
피그마 기준으로 thin은 사용하지 않는 것 같은데, 제가 놓친 부분이 있을까요?
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.
comment; @minjongbaek
이후 확장성을 고려해서 작성하긴했는데 지금 생각해보니 굳이 필요한가 싶긴하네요 ㅋㅋㅋ