-
Notifications
You must be signed in to change notification settings - Fork 1
✨[Feat] 검색창 구현 #120 #121
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
The head ref may contain hidden characters: "120-feature-\uAC80\uC0C9-\uCEF4\uD3EC\uB10C\uD2B8-\uAD6C\uD604"
Merged
✨[Feat] 검색창 구현 #120 #121
Changes from all commits
Commits
Show all changes
4 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { SVGProps } from 'react'; | ||
|
|
||
| interface SearchIconProps extends SVGProps<SVGSVGElement> { | ||
| width?: number; | ||
| height?: number; | ||
| } | ||
|
|
||
| function SearchIcon({ width = 12, height = 12, ...props }: SearchIconProps) { | ||
| return ( | ||
| <svg | ||
| width={width} | ||
| height={height} | ||
| viewBox="0 0 14 14" | ||
| fill="none" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| {...props} | ||
| > | ||
| <path | ||
| d="M13 13L10.1 10.1M11.6667 6.33333C11.6667 9.27885 9.27885 11.6667 6.33333 11.6667C3.38781 11.6667 1 9.27885 1 6.33333C1 3.38781 3.38781 1 6.33333 1C9.27885 1 11.6667 3.38781 11.6667 6.33333Z" | ||
| stroke="currentColor" | ||
| strokeWidth="1.4" | ||
| strokeLinecap="round" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } | ||
|
|
||
| export default SearchIcon; |
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,22 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
| import SearchBox from './SearchBox'; | ||
|
|
||
| const meta = { | ||
| title: 'Components/SearchBox', | ||
| component: SearchBox, | ||
| parameters: { | ||
| layout: 'centered', | ||
| }, | ||
| tags: ['autodocs'], | ||
| } satisfies Meta<typeof SearchBox>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof SearchBox>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| value: '', | ||
| onChange: (e) => console.log('Search value:', e.target.value), | ||
| placeholder: '검색어를 입력해주세요', | ||
| }, | ||
| }; |
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 @@ | ||
| import '@testing-library/jest-dom'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import SearchBox from './SearchBox'; | ||
|
|
||
| describe('SearchBox', () => { | ||
| const mockOnChange = jest.fn(); | ||
| const defaultProps = { | ||
| value: '', | ||
| onChange: mockOnChange, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| mockOnChange.mockClear(); | ||
| }); | ||
|
|
||
| it('기본 placeholder 텍스트가 올바르게 렌더링되는지 확인', () => { | ||
| render(<SearchBox {...defaultProps} />); | ||
| expect( | ||
| screen.getByPlaceholderText('검색어를 입력해주세요'), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('사용자 정의 placeholder가 올바르게 렌더링되는지 확인', () => { | ||
| const customPlaceholder = 'placeholder 테스트'; | ||
| render(<SearchBox {...defaultProps} placeholder={customPlaceholder} />); | ||
| expect(screen.getByPlaceholderText(customPlaceholder)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('입력값이 변경될 때 onChange 핸들러가 호출되는지 확인', () => { | ||
| render(<SearchBox {...defaultProps} />); | ||
| const input = screen.getByRole('textbox'); | ||
|
|
||
| fireEvent.change(input, { target: { value: '테스트 검색어' } }); | ||
| expect(mockOnChange).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('초기 value prop이 올바르게 설정되는지 확인', () => { | ||
| const initialValue = '초기 검색어'; | ||
| render(<SearchBox {...defaultProps} value={initialValue} />); | ||
|
|
||
| const input = screen.getByRole('textbox') as HTMLInputElement; | ||
| expect(input.value).toBe(initialValue); | ||
| }); | ||
| }); |
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,31 @@ | ||
| import React, { ChangeEvent } from 'react'; | ||
| import SearchIcon from '../../../public/icons/SearchIcon'; | ||
|
|
||
| interface SearchBoxProps { | ||
| value: string; | ||
| onChange: (e: ChangeEvent<HTMLInputElement>) => void; | ||
| placeholder?: string; | ||
| } | ||
|
|
||
| const SearchBox = ({ | ||
| value, | ||
| onChange, | ||
| placeholder = '검색어를 입력해주세요', | ||
| }: SearchBoxProps) => { | ||
| return ( | ||
| <div className="flex items-center gap-1 rounded-lg border border-gray-200 px-3 py-2"> | ||
| <div className="flex h-6 w-6 items-center justify-center text-gray-400"> | ||
| <SearchIcon /> | ||
| </div> | ||
| <input | ||
| type="text" | ||
| value={value} | ||
| onChange={onChange} | ||
| placeholder={placeholder} | ||
| className="w-full text-sm text-gray-darker placeholder:text-gray-normal-03" | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SearchBox; | ||
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.
p5: 위에서 아이콘 사이즈를 변동할 수 있게 설정해둔다면 추후 리팩토링시 검색창 사이즈가 지금과 달라져도 해당 파일에서 아이콘 파일을 재사용해서
variant로 검색창과 아이콘의 사이즈를 조절해서 한 파일내에서 처리가 가능할 것 같습니다~지금 당장은 필요없고 추후 리팩토링을 하게 된다면 이런 느낌으로 하면 좋을 것 같아요! :)