-
Notifications
You must be signed in to change notification settings - Fork 1
✨ [Feature] chip 컴포넌트 리팩토링 & 모임 chip 구현 #129
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
Closed
The head ref may contain hidden characters: "126-feature-chip-\uCEF4\uD3EC\uB10C\uD2B8-\uB9AC\uD329\uD1A0\uB9C1"
Closed
Changes from all commits
Commits
Show all changes
5 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
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
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,48 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
| import ClubChip from './ClubChip'; | ||
|
|
||
| const meta = { | ||
| title: 'Components/Chip/ClubChip', | ||
| component: ClubChip, | ||
| parameters: { | ||
| layout: 'centered', | ||
| }, | ||
| } satisfies Meta<typeof ClubChip>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof ClubChip>; | ||
|
|
||
| export const Completed: Story = { | ||
| args: { | ||
| variant: 'completed', | ||
| }, | ||
| }; | ||
|
|
||
| export const Scheduled: Story = { | ||
| args: { | ||
| variant: 'scheduled', | ||
| }, | ||
| }; | ||
|
|
||
| export const Pending: Story = { | ||
| args: { | ||
| variant: 'pending', | ||
| }, | ||
| }; | ||
|
|
||
| export const Confirmed: Story = { | ||
| args: { | ||
| variant: 'confirmed', | ||
| }, | ||
| }; | ||
|
|
||
| export const AllStates: Story = { | ||
| render: () => ( | ||
| <div className="flex gap-2"> | ||
| <ClubChip variant="completed" /> | ||
| <ClubChip variant="scheduled" /> | ||
| <ClubChip variant="pending" /> | ||
| <ClubChip variant="confirmed" /> | ||
| </div> | ||
| ), | ||
| }; |
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,29 @@ | ||
| import ClubChip from './ClubChip'; | ||
| import '@testing-library/jest-dom'; | ||
| import { render, screen } from '@testing-library/react'; | ||
|
|
||
| describe('ClubChip', () => { | ||
| it('variant에 따라 올바른 텍스트가 렌더링되어야 한다', () => { | ||
| render(<ClubChip variant="completed" />); | ||
| expect(screen.getByText('참여완료')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('모든 variant가 올바르게 렌더링되어야 한다', () => { | ||
| const { rerender } = render(<ClubChip variant="completed" />); | ||
| expect(screen.getByText('참여완료')).toBeInTheDocument(); | ||
|
|
||
| rerender(<ClubChip variant="scheduled" />); | ||
| expect(screen.getByText('참여예정')).toBeInTheDocument(); | ||
|
|
||
| rerender(<ClubChip variant="pending" />); | ||
| expect(screen.getByText('개설대기')).toBeInTheDocument(); | ||
|
|
||
| rerender(<ClubChip variant="confirmed" />); | ||
| expect(screen.getByText('개설확정')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('className prop으로 스타일을 오버라이드할 수 있어야 한다', () => { | ||
| render(<ClubChip variant="completed" className="custom-class" />); | ||
| expect(screen.getByText('참여완료')).toHaveClass('custom-class'); | ||
| }); | ||
| }); |
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,54 @@ | ||
| import Chip from '../Chip'; | ||
| import { twMerge } from 'tailwind-merge'; | ||
|
|
||
| type ClubChipVariant = 'completed' | 'scheduled' | 'pending' | 'confirmed'; | ||
|
|
||
| const CLUB_CHIP_TEXT = { | ||
| completed: '참여완료', | ||
| scheduled: '참여예정', | ||
| pending: '개설대기', | ||
| confirmed: '개설확정', | ||
| } as const; | ||
|
|
||
| interface ClubChipProps { | ||
| variant: ClubChipVariant; | ||
| className?: string; | ||
| } | ||
|
|
||
| function ClubChip({ variant, className }: ClubChipProps) { | ||
| const getChipVariant = () => { | ||
| switch (variant) { | ||
| case 'completed': | ||
| return 'square-filled'; | ||
| case 'scheduled': | ||
| return 'square-filled'; | ||
| case 'pending': | ||
| return 'square-outlined'; | ||
| case 'confirmed': | ||
| return 'square-filled'; | ||
| } | ||
| }; | ||
|
|
||
| const getCustomClassName = () => { | ||
| switch (variant) { | ||
| case 'completed': | ||
| return 'bg-gray-normal-01 text-gray-dark-02'; | ||
| case 'scheduled': | ||
| return 'bg-green-normal-01 text-gray-white'; | ||
| case 'pending': | ||
| return 'border-blue-normal-01 text-blue-normal-01'; | ||
| case 'confirmed': | ||
| return 'bg-blue-normal-01 text-gray-white'; | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Chip | ||
| text={CLUB_CHIP_TEXT[variant]} | ||
| variant={getChipVariant()} | ||
| className={twMerge(getCustomClassName(), className)} | ||
|
Comment on lines
+48
to
+49
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. variant={CHIP_VARIANTS[variant]}
className={twMerge(CHIP_CLASSES[variant], className)} |
||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default ClubChip; | ||
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
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.
큰 차이는 없을 거 같긴한데 통일성 있게 객체화 시키는 방법은 어떤가요??
객체화 시켜서 사용하는 방법과 switch case 문을 같이 사용한 이유가 있으실까요?