-
Notifications
You must be signed in to change notification settings - Fork 2
[#41] ✨ 공통 컴포넌트 Chip 개발 #82
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
eb8b65b
[#41] ✨ add label types to team.d.ts and community.d.ts
KingNono1030 077bf22
Merge branch 'dev' of https://github.com/DevFDev/frontend into feat/c…
KingNono1030 e5e2597
[#41] 🚚 move chip components in components directory
KingNono1030 0282b31
[#41] 🚚 move chip in common/chip
KingNono1030 6a88fd1
[#41] 💄 correct few styles along to its label
KingNono1030 ec0343d
[#41] ✅ add Chip story
KingNono1030 b57c3d3
[#41] ✅ add chip test codes
KingNono1030 9ff72e5
[#41] 🐛 fix twMerge class name merging issues along to the test result
KingNono1030 abbdda1
[#20] 💄 add lineheight and letter spacing to fontPallete
KingNono1030 afd0de1
[#41] 🗑️ remove unused package
KingNono1030 f37d24b
[#41] 💄 roll back default bg text styles to base style
KingNono1030 33a5ed1
[#41] ✨ add deletable chip component
KingNono1030 64bb986
[#41] ✨ add module bridge index.ts
KingNono1030 4f059e5
[#41] 💄 turn ic close svg into currentColor
KingNono1030 220ffeb
[#41] ✅ add deletable story
KingNono1030 d07816a
[#41] ✅ add deletable test + mock jest with svg
KingNono1030 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 @@ | ||
module.exports = 'test-file-stub' |
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 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,67 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
|
||
import { Chip } from './Chip' | ||
|
||
describe('Chip Component', () => { | ||
test('renders the Chip component with correct label', () => { | ||
// Chip 컴포넌트가 올바른 라벨을 렌더링하는지 확인합니다. | ||
render(<Chip label='모집 중' />) | ||
const chipElement = screen.getByText(/모집 중/i) | ||
expect(chipElement).toBeInTheDocument() | ||
}) | ||
|
||
test('applies correct styles for each label', () => { | ||
// 각 라벨에 대해 올바른 스타일이 적용되는지 확인합니다. | ||
const labelStyles = { | ||
'모집 중': 'bg-blue-100 text-blue-500', | ||
'모집 완료': 'bg-gray-200 text-gray-600', | ||
스터디: 'bg-green-100 text-green-500', | ||
프로젝트: 'bg-purple-100 text-purple-500', | ||
멘토링: 'bg-red-100 text-red-500', | ||
기술: 'bg-blue-100 text-blue-500', | ||
커리어: 'bg-pink-100 text-pink-500', | ||
기타: 'bg-orange-100 text-orange-500', | ||
} | ||
|
||
Object.entries(labelStyles).forEach(([label, expectedClasses]) => { | ||
render(<Chip label={label} />) | ||
const chipElement = screen.getByText(label) | ||
|
||
// expectedClasses에 포함된 각 클래스가 chipElement에 포함되는지 확인합니다. | ||
expectedClasses.split(' ').forEach(className => { | ||
expect(chipElement).toHaveClass(className) | ||
}) | ||
}) | ||
}) | ||
|
||
test('applies additional className passed as prop', () => { | ||
// className prop을 통해 추가된 클래스가 Chip 컴포넌트에 적용되는지 확인합니다. | ||
render(<Chip label='기술' className='custom-class' />) | ||
const chipElement = screen.getByText(/기술/i) | ||
expect(chipElement).toHaveClass('custom-class') | ||
}) | ||
|
||
test('applies base styles correctly', () => { | ||
// 기본 스타일이 Chip 컴포넌트에 올바르게 적용되는지 확인합니다. | ||
render(<Chip label='커리어' />) | ||
const chipElement = screen.getByText(/커리어/i) | ||
expect(chipElement).toHaveClass( | ||
'flex', | ||
'h-28', | ||
'items-center', | ||
'justify-center', | ||
'rounded-4', | ||
'px-6', | ||
'text-body3', | ||
'font-medium' | ||
) | ||
}) | ||
|
||
test('applies default styles when label is not in styleByLabel', () => { | ||
// styleByLabel에 없는 라벨에 대해 기본 스타일이 적용되는지 확인합니다. | ||
render(<Chip label='기타 라벨' />) | ||
const chipElement = screen.getByText(/기타 라벨/i) | ||
expect(chipElement).toHaveClass('bg-gray-200', 'text-gray-500') | ||
}) | ||
}) |
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,26 @@ | ||
import clsx from 'clsx' | ||
|
||
type ChipProps = { | ||
label: string | ||
className?: string | ||
} | ||
|
||
const baseStyle = | ||
'flex h-28 items-center justify-center rounded-4 bg-gray-200 px-6 text-body3 font-medium text-gray-500' | ||
|
||
const styleByLabel: Record<string, string> = { | ||
'모집 중': 'bg-blue-100 text-blue-500', | ||
'모집 완료': 'bg-gray-200 text-gray-600', | ||
스터디: 'bg-green-100 text-green-500', | ||
프로젝트: 'bg-purple-100 text-purple-500', | ||
멘토링: 'bg-red-100 text-red-500', | ||
기술: 'bg-blue-100 text-blue-500', | ||
커리어: 'bg-pink-100 text-pink-500', | ||
기타: 'bg-orange-100 text-orange-500', | ||
} | ||
|
||
export const Chip = ({ label, className = '' }: ChipProps): JSX.Element => { | ||
const labelStyle = styleByLabel[label] || '' | ||
const chipStyle = clsx(baseStyle, labelStyle, className) | ||
return <span className={chipStyle}>{label}</span> | ||
} |
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,62 @@ | ||
import '@testing-library/jest-dom' | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
|
||
import { DeletableChip } from './DeletableChip' | ||
|
||
describe('DeletableChip Component', () => { | ||
test('renders the chip with correct label', () => { | ||
// 올바른 label이 렌더링되는지 확인합니다. | ||
render(<DeletableChip label='스터디' onDelete={() => {}} />) | ||
const chipElement = screen.getByText(/스터디/i) | ||
expect(chipElement).toBeInTheDocument() | ||
}) | ||
|
||
test('renders with the default blue color style', () => { | ||
// 기본 색상이 blue로 렌더링되는지 확인합니다. | ||
render(<DeletableChip label='스터디' onDelete={() => {}} />) | ||
const chipElement = screen.getByText(/스터디/i) | ||
expect(chipElement).toHaveClass('bg-blue-800', 'text-common-white') | ||
}) | ||
|
||
test('renders with the gray color style when specified', () => { | ||
// gray 색상이 지정되었을 때 올바르게 스타일링되는지 확인합니다. | ||
render(<DeletableChip label='스터디' color='gray' onDelete={() => {}} />) | ||
const chipElement = screen.getByText(/스터디/i) | ||
expect(chipElement).toHaveClass( | ||
'border-1', | ||
'border-solid', | ||
'border-gray-200', | ||
'bg-gray-100', | ||
'text-gray-700' | ||
) | ||
}) | ||
|
||
test('renders delete button with gray color style when chip color is gray', () => { | ||
// chip이 gray일 때 delete 버튼이 gray 스타일을 가지는지 확인합니다. | ||
render(<DeletableChip label='스터디' color='gray' onDelete={() => {}} />) | ||
const buttonElement = screen.getByRole('button', { name: /스터디 삭제/i }) | ||
expect(buttonElement).toHaveClass('text-gray-400') | ||
}) | ||
|
||
test('calls onDelete when delete button is clicked', () => { | ||
// 삭제 버튼 클릭 시 onDelete가 호출되는지 확인합니다. | ||
const handleDelete = jest.fn() | ||
render(<DeletableChip label='스터디' onDelete={handleDelete} />) | ||
const buttonElement = screen.getByRole('button', { name: /스터디 삭제/i }) | ||
fireEvent.click(buttonElement) | ||
expect(handleDelete).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('applies additional className when specified', () => { | ||
// 추가된 className이 적용되는지 확인합니다. | ||
render( | ||
<DeletableChip | ||
label='스터디' | ||
onDelete={() => {}} | ||
className='custom-class' | ||
/> | ||
) | ||
const chipElement = screen.getByText(/스터디/i) | ||
expect(chipElement).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,42 @@ | ||
import { IcClose } from '@/assets/IconList' | ||
import clsx from 'clsx' | ||
|
||
type Color = 'blue' | 'gray' | ||
|
||
type ChipProps = { | ||
onDelete: () => void | ||
color?: Color | ||
label: string | ||
className?: string | ||
} | ||
|
||
const baseStyle = | ||
'flex h-36 items-center justify-center gap-4 rounded-4 px-8 text-body2 font-medium' | ||
|
||
const styleByColor = { | ||
blue: 'bg-blue-800 text-common-white', | ||
gray: 'border-1 border-solid border-gray-200 bg-gray-100 text-gray-700', | ||
} | ||
|
||
export const DeletableChip = ({ | ||
onDelete, | ||
label, | ||
color = 'blue', | ||
className = '', | ||
}: ChipProps): JSX.Element => { | ||
const chipStyle = clsx(baseStyle, styleByColor[color], className) | ||
const buttonStyle = clsx({ 'text-gray-400': color === 'gray' }) | ||
return ( | ||
<span className={chipStyle}> | ||
{label} | ||
<button | ||
onClick={onDelete} | ||
className={buttonStyle} | ||
type='button' | ||
aria-label={`${label} 삭제`} | ||
> | ||
<IcClose /> | ||
</button> | ||
</span> | ||
) | ||
} |
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,4 @@ | ||
import { Chip } from './Chip' | ||
import { DeletableChip } from './DeletableChip' | ||
|
||
export { Chip, DeletableChip } |
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,39 @@ | ||
import { fn } from '@storybook/test' | ||
|
||
import { Chip } from '@/components/common/chip' | ||
|
||
export default { | ||
title: 'Common/Chip/Chip', | ||
component: Chip, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['common', 'chip'], | ||
argTypes: { | ||
label: { | ||
control: 'radio', | ||
options: [ | ||
'모집 중', | ||
'모집 완료', | ||
'스터디', | ||
'프로젝트', | ||
'멘토링', | ||
'기술', | ||
'커리어', | ||
'기타', | ||
'프론트엔드', | ||
'#Spring', | ||
], | ||
description: '문자열만 받습니다.', | ||
}, | ||
}, | ||
args: { | ||
onClick: fn(), | ||
}, | ||
} | ||
|
||
export const Default = { | ||
args: { | ||
label: '스터디', | ||
}, | ||
} |
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,43 @@ | ||
import { fn } from '@storybook/test' | ||
|
||
import { DeletableChip } from '@/components/common/chip' | ||
|
||
export default { | ||
title: 'Common/Chip/DeletableChip', | ||
component: DeletableChip, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['common', 'chip', 'deletable'], | ||
argTypes: { | ||
label: { | ||
control: 'radio', | ||
options: [ | ||
'Spring', | ||
'ReactNative', | ||
'MongoDB', | ||
'TypeScript', | ||
'프론트엔드', | ||
'풀스택', | ||
'DevOps 엔지니어', | ||
], | ||
description: '문자열만 받습니다.', | ||
}, | ||
}, | ||
args: { | ||
onDelete: fn(), | ||
}, | ||
} | ||
|
||
export const Default = { | ||
args: { | ||
label: '스터디', | ||
}, | ||
} | ||
|
||
export const Gray = { | ||
args: { | ||
label: '기술', | ||
color: 'gray', | ||
}, | ||
} |
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,4 @@ | ||
declare module '*.svg' { | ||
const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>> | ||
export default ReactComponent | ||
} |
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
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.
아앗..!!!