-
Notifications
You must be signed in to change notification settings - Fork 6
refactor(badge): redesign badge component #195
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
Open
jiji-hoon96
wants to merge
1
commit into
release/v1
Choose a base branch
from
refactor/badge-design-system
base: release/v1
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.
+420
−201
Open
Changes from all commits
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 hidden or 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
This file contains hidden or 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,44 @@ | ||
| export const BadgeSize = { | ||
| small: 'small', | ||
| large: 'large', | ||
| } as const; | ||
|
|
||
| export const BadgeVariant = { | ||
| solid: 'solid', | ||
| default: 'default', | ||
| } as const; | ||
|
|
||
| export const BadgeColor = { | ||
| white: 'white', | ||
| gray: 'gray', | ||
| danger: 'danger', | ||
| general: 'general', | ||
| '1st': '1st', | ||
| '2nd': '2nd', | ||
| '3rd': '3rd', | ||
| '4th': '4th', | ||
| } as const; | ||
|
|
||
| export const BadgeIconPosition = { | ||
| none: 'none', | ||
| left: 'left', | ||
| right: 'right', | ||
| both: 'both', | ||
| } as const; | ||
|
|
||
| export type BadgeSize = (typeof BadgeSize)[keyof typeof BadgeSize]; | ||
| export type BadgeVariant = (typeof BadgeVariant)[keyof typeof BadgeVariant]; | ||
| export type BadgeColor = (typeof BadgeColor)[keyof typeof BadgeColor]; | ||
| export type BadgeIconPosition = (typeof BadgeIconPosition)[keyof typeof BadgeIconPosition]; | ||
|
|
||
| import type React from 'react'; | ||
|
|
||
| export interface BadgeProps extends React.ComponentPropsWithoutRef<'div'> { | ||
| size?: BadgeSize; | ||
| variant?: BadgeVariant; | ||
| color?: BadgeColor; | ||
| asChild?: boolean; | ||
| icon?: BadgeIconPosition; | ||
| leftIcon?: React.ReactNode; | ||
| rightIcon?: React.ReactNode; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,71 +1,177 @@ | ||
| import { style, styleVariants } from '@vanilla-extract/css'; | ||
| import { color as colorToken, fontSize as fontSizeToken } from '@sipe-team/tokens'; | ||
|
|
||
| // Define the types for our component | ||
| export const BadgeSize = { | ||
| small: 'small', | ||
| medium: 'medium', | ||
| large: 'large', | ||
| } as const; | ||
| import { recipe } from '@vanilla-extract/recipes'; | ||
|
|
||
| export const BadgeVariant = { | ||
| filled: 'filled', | ||
| outline: 'outline', | ||
| weak: 'weak', | ||
| } as const; | ||
| import { BadgeColor, BadgeSize, BadgeVariant } from './Badge.constants'; | ||
|
|
||
| // Base styles for the badge | ||
| export const root = style({ | ||
| borderRadius: 8, | ||
| display: 'inline-flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| }); | ||
|
|
||
| // Size variants | ||
| export const size = styleVariants({ | ||
| [BadgeSize.small]: { | ||
| padding: '4px 8px', | ||
| }, | ||
| [BadgeSize.medium]: { | ||
| padding: '8px 16px', | ||
| }, | ||
| [BadgeSize.large]: { | ||
| padding: '12px 24px', | ||
| }, | ||
| }); | ||
|
|
||
| // Font size by badge size | ||
| export const fontSize = styleVariants({ | ||
| [BadgeSize.small]: { | ||
| fontSize: fontSizeToken[12], | ||
| export const badge = recipe({ | ||
| base: { | ||
| display: 'inline-flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| borderRadius: 6, | ||
| fontWeight: 600, | ||
| whiteSpace: 'nowrap', | ||
| transition: 'all 0.2s ease-in-out', | ||
| userSelect: 'none', | ||
| gap: '4px', | ||
| }, | ||
| [BadgeSize.medium]: { | ||
| fontSize: fontSizeToken[14], | ||
| variants: { | ||
| size: { | ||
| [BadgeSize.small]: { | ||
| padding: '2px 8px', | ||
| fontSize: fontSizeToken[12], | ||
| lineHeight: '16px', | ||
| height: '20px', | ||
| }, | ||
| [BadgeSize.large]: { | ||
| padding: '4px 12px', | ||
| fontSize: fontSizeToken[14], | ||
| lineHeight: '20px', | ||
| height: '24px', | ||
| }, | ||
| }, | ||
| color: { | ||
| [BadgeColor.white]: {}, | ||
| [BadgeColor.gray]: {}, | ||
| [BadgeColor.danger]: {}, | ||
| [BadgeColor.general]: {}, | ||
| [BadgeColor['1st']]: {}, | ||
| [BadgeColor['2nd']]: {}, | ||
| [BadgeColor['3rd']]: {}, | ||
| [BadgeColor['4th']]: {}, | ||
| }, | ||
| variant: { | ||
| [BadgeVariant.solid]: {}, | ||
| [BadgeVariant.default]: {}, | ||
| }, | ||
| }, | ||
| [BadgeSize.large]: { | ||
| fontSize: fontSizeToken[18], | ||
| compoundVariants: [ | ||
| // White variants | ||
| { | ||
| variants: { color: BadgeColor.white, variant: BadgeVariant.solid }, | ||
| style: { | ||
| backgroundColor: colorToken.white, | ||
| color: colorToken.gray900, | ||
| }, | ||
| }, | ||
| { | ||
| variants: { color: BadgeColor.white, variant: BadgeVariant.default }, | ||
| style: { | ||
| backgroundColor: 'transparent', | ||
| color: colorToken.white, | ||
| border: `1px solid ${colorToken.white}`, | ||
| }, | ||
| }, | ||
| // Gray variants | ||
| { | ||
| variants: { color: BadgeColor.gray, variant: BadgeVariant.solid }, | ||
| style: { | ||
| backgroundColor: colorToken.gray700, | ||
| color: colorToken.white, | ||
| }, | ||
| }, | ||
| { | ||
| variants: { color: BadgeColor.gray, variant: BadgeVariant.default }, | ||
| style: { | ||
| backgroundColor: colorToken.gray100, | ||
| color: colorToken.gray700, | ||
| }, | ||
| }, | ||
| // Danger variants | ||
| { | ||
| variants: { color: BadgeColor.danger, variant: BadgeVariant.solid }, | ||
| style: { | ||
| backgroundColor: colorToken.red500, | ||
| color: colorToken.white, | ||
| }, | ||
| }, | ||
| { | ||
| variants: { color: BadgeColor.danger, variant: BadgeVariant.default }, | ||
| style: { | ||
| backgroundColor: colorToken.red100, | ||
| color: colorToken.red700, | ||
| }, | ||
| }, | ||
| // General variants | ||
| { | ||
| variants: { color: BadgeColor.general, variant: BadgeVariant.solid }, | ||
| style: { | ||
| backgroundColor: colorToken.blue500, | ||
| color: colorToken.white, | ||
| }, | ||
| }, | ||
| { | ||
| variants: { color: BadgeColor.general, variant: BadgeVariant.default }, | ||
| style: { | ||
| backgroundColor: colorToken.blue100, | ||
| color: colorToken.blue700, | ||
| }, | ||
| }, | ||
| // 1st variants | ||
| { | ||
| variants: { color: BadgeColor['1st'], variant: BadgeVariant.solid }, | ||
| style: { | ||
| backgroundColor: colorToken.green500, | ||
| color: colorToken.white, | ||
| }, | ||
| }, | ||
| { | ||
| variants: { color: BadgeColor['1st'], variant: BadgeVariant.default }, | ||
| style: { | ||
| backgroundColor: colorToken.green100, | ||
| color: colorToken.green700, | ||
| }, | ||
| }, | ||
| // 2nd variants | ||
| { | ||
| variants: { color: BadgeColor['2nd'], variant: BadgeVariant.solid }, | ||
| style: { | ||
| backgroundColor: colorToken.purple500, | ||
| color: colorToken.white, | ||
| }, | ||
| }, | ||
| { | ||
| variants: { color: BadgeColor['2nd'], variant: BadgeVariant.default }, | ||
| style: { | ||
| backgroundColor: colorToken.purple100, | ||
| color: colorToken.purple700, | ||
| }, | ||
| }, | ||
| // 3rd variants | ||
| { | ||
| variants: { color: BadgeColor['3rd'], variant: BadgeVariant.solid }, | ||
| style: { | ||
| backgroundColor: colorToken.orange500, | ||
| color: colorToken.white, | ||
| }, | ||
| }, | ||
| { | ||
| variants: { color: BadgeColor['3rd'], variant: BadgeVariant.default }, | ||
| style: { | ||
| backgroundColor: colorToken.orange100, | ||
| color: colorToken.orange700, | ||
| }, | ||
| }, | ||
| // 4th variants | ||
| { | ||
| variants: { color: BadgeColor['4th'], variant: BadgeVariant.solid }, | ||
| style: { | ||
| backgroundColor: colorToken.cyan500, | ||
| color: colorToken.white, | ||
| }, | ||
| }, | ||
| { | ||
| variants: { color: BadgeColor['4th'], variant: BadgeVariant.default }, | ||
| style: { | ||
| backgroundColor: colorToken.cyan100, | ||
| color: colorToken.cyan700, | ||
| }, | ||
| }, | ||
|
Comment on lines
+120
to
+170
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 색상이 어떤기준으로 잡힌지 모르겠어요 ~
디자인 이슈라면 디자이너 호출 필요할듯 |
||
| ], | ||
| defaultVariants: { | ||
| size: BadgeSize.small, | ||
| color: BadgeColor.gray, | ||
| variant: BadgeVariant.default, | ||
| }, | ||
| }); | ||
|
|
||
| // Variant styles | ||
| export const variant = styleVariants({ | ||
| [BadgeVariant.filled]: { | ||
| backgroundColor: colorToken.cyan900, | ||
| border: 'none', | ||
| }, | ||
| [BadgeVariant.outline]: { | ||
| backgroundColor: 'transparent', | ||
| border: `2px solid ${colorToken.cyan900}`, | ||
| }, | ||
| [BadgeVariant.weak]: { | ||
| backgroundColor: colorToken.gray200, | ||
| border: 'none', | ||
| }, | ||
| }); | ||
|
|
||
| // Text style | ||
| export const text = style({ | ||
| color: colorToken.cyan300, | ||
| fontWeight: 600, | ||
| }); | ||
Oops, something went wrong.
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.
react-slot가 devDependencies에 들어가있네욤