-
Notifications
You must be signed in to change notification settings - Fork 1
♻️[Refactor] feature common popup #10 #133
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
10 commits
Select commit
Hold shift + click to select a range
3b27776
💄[Design] PopUp 컴포넌트 레이아웃 구현 #10
sunnwave a324e85
✨[Feat] PopUp의 Button 컴포넌트 구현, 스토리북 코드 작성 #31
sunnwave 9727e3c
💄[Design] 팝업창 css 구현 완료
sunnwave bcfec4e
✅[Test] 팝업창 스토리북 테스트코드 타입별 코드 추가 #26
sunnwave b4fd84e
Merge branch 'develop' into 10-feature-common-popup
sunnwave 42a6464
Merge branch 'develop' into 10-feature-common-popup
sunnwave 744578e
♻️[Refactor] Button 컴포넌트 이용하여 PopUp 컴포넌트 리팩토링 #10
sunnwave 9f170b3
🔥[Remove] PopUpButton 컴포넌트 파일 삭제 #10
sunnwave 0ee879c
✅[Test] PopUp 컴포넌트 jest 테스트코드 수정 #10
sunnwave 9c67680
Merge branch 'develop' into 10-feature-common-popup
sunnwave 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
| import { SVGProps } from 'react'; | ||
|
|
||
| interface IcCloseProps extends SVGProps<SVGElement> { | ||
| width?: number; | ||
| height?: number; | ||
| isActive?: boolean; | ||
| color?: string; | ||
| } | ||
|
|
||
| function IcClose({ | ||
| width = 24, | ||
| height = 24, | ||
| isActive = false, | ||
| color, | ||
| }: IcCloseProps) { | ||
| return ( | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width={width} | ||
| height={height} | ||
| fill="none" | ||
| className={`${isActive ? color : 'stroke-gray-dark-02'}`} | ||
| > | ||
| <path | ||
| stroke={isActive ? color : '#909192'} | ||
| strokeLinecap="round" | ||
| strokeWidth="1.8" | ||
| d="m5 5 14.5 14.5M19.5 5 5 19.5" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } | ||
|
|
||
| export default IcClose; |
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,58 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
| import PopUp from './PopUp'; | ||
|
|
||
| const POPUP_LABEL = { | ||
| large: `정말 나가시겠어요?\n작성된 내용이 모두 삭제됩니다.`, | ||
| small: `가입이 완료되었습니다!`, | ||
| }; | ||
|
|
||
| const meta: Meta<typeof PopUp> = { | ||
| title: 'components/PopUp', | ||
| component: PopUp, | ||
| parameters: { | ||
| layout: 'centerd', | ||
| }, | ||
| }; | ||
|
|
||
| type Story = StoryObj<typeof PopUp>; | ||
| export const LargeOneButton: Story = { | ||
| args: { | ||
| isOpen: true, | ||
| isLarge: true, | ||
| label: POPUP_LABEL.large, | ||
| handlePopUpClose: (e) => alert(e), | ||
| handlePopUpConfirm: (e) => alert(e), | ||
| }, | ||
| }; | ||
|
|
||
| export const LargeTwoButton: Story = { | ||
| args: { | ||
| isOpen: true, | ||
| isLarge: true, | ||
| isTwoButton: true, | ||
| label: POPUP_LABEL.large, | ||
| handlePopUpClose: (e) => alert(e), | ||
| handlePopUpConfirm: (e) => alert(e), | ||
| }, | ||
| }; | ||
|
|
||
| export const SmallOneButton: Story = { | ||
| args: { | ||
| isOpen: true, | ||
| label: POPUP_LABEL.small, | ||
| handlePopUpClose: (e) => alert(e), | ||
| handlePopUpConfirm: (e) => alert(e), | ||
| }, | ||
| }; | ||
|
|
||
| export const SmallTwoButton: Story = { | ||
| args: { | ||
| isOpen: true, | ||
| isTwoButton: true, | ||
| label: POPUP_LABEL.small, | ||
| handlePopUpClose: (e) => alert(e), | ||
| handlePopUpConfirm: (e) => alert(e), | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; |
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,82 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import PopUp from './PopUp'; | ||
|
|
||
| const POPUP_LABEL = { | ||
| large: `정말 나가시겠어요?\n작성된 내용이 모두 삭제됩니다.`, | ||
| small: `가입이 완료되었습니다!`, | ||
| }; | ||
|
|
||
| const mockHandlePopUpClose = jest.fn(); | ||
| const mockHandlePopUpConfirm = jest.fn(); | ||
|
|
||
| describe('PopUp 렌더링 테스트', () => { | ||
| it('small, single button 렌더링 테스트', () => { | ||
| render( | ||
| <PopUp | ||
| isOpen={true} | ||
| label={POPUP_LABEL.small} | ||
| handlePopUpClose={mockHandlePopUpClose} | ||
| handlePopUpConfirm={mockHandlePopUpConfirm} | ||
| />, | ||
| ); | ||
| const popUp = screen.getByRole('pop-up'); | ||
| const confirm = screen.getByText('확인'); | ||
| const cancel = screen.queryByText('취소'); | ||
| expect(popUp).toBeInTheDocument(); | ||
| expect(confirm).toBeInTheDocument(); | ||
| expect(cancel).not.toBeInTheDocument(); | ||
| }); | ||
| it('small, two button 렌더링 테스트', () => { | ||
| render( | ||
| <PopUp | ||
| isOpen={true} | ||
| isTwoButton={true} | ||
| label={POPUP_LABEL.small} | ||
| handlePopUpClose={mockHandlePopUpClose} | ||
| handlePopUpConfirm={mockHandlePopUpConfirm} | ||
| />, | ||
| ); | ||
| const popUp = screen.getByRole('pop-up'); | ||
| const confirm = screen.getByText('확인'); | ||
| const cancel = screen.getByText('취소'); | ||
| expect(popUp).toBeInTheDocument(); | ||
| expect(confirm).toBeInTheDocument(); | ||
| expect(cancel).toBeInTheDocument(); | ||
| }); | ||
| it('large, single button 렌더링 테스트', () => { | ||
| render( | ||
| <PopUp | ||
| isOpen={true} | ||
| isLarge={true} | ||
| label={POPUP_LABEL.large} | ||
| handlePopUpClose={mockHandlePopUpClose} | ||
| handlePopUpConfirm={mockHandlePopUpConfirm} | ||
| />, | ||
| ); | ||
| const popUp = screen.getByRole('pop-up'); | ||
| const confirm = screen.getByText('확인'); | ||
| const cancel = screen.queryByText('취소'); | ||
| expect(popUp).toBeInTheDocument(); | ||
| expect(confirm).toBeInTheDocument(); | ||
| expect(cancel).not.toBeInTheDocument(); | ||
| }); | ||
| it('large, two button 렌더링 테스트', () => { | ||
| render( | ||
| <PopUp | ||
| isOpen={true} | ||
| isLarge={false} | ||
| isTwoButton={true} | ||
| label={POPUP_LABEL.large} | ||
| handlePopUpClose={mockHandlePopUpClose} | ||
| handlePopUpConfirm={mockHandlePopUpConfirm} | ||
| />, | ||
| ); | ||
| const popUp = screen.getByRole('pop-up'); | ||
| const confirm = screen.getByText('확인'); | ||
| const cancel = screen.getByText('취소'); | ||
| expect(popUp).toBeInTheDocument(); | ||
| expect(confirm).toBeInTheDocument(); | ||
| expect(cancel).toBeInTheDocument(); | ||
| }); | ||
| }); |
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,75 @@ | ||
| import { IcClose } from '../../../public/icons'; | ||
| import Button from '../button/Button'; | ||
|
|
||
| interface PopUpProps { | ||
| isOpen: boolean; | ||
| label: string; | ||
| handlePopUpClose: (result: boolean) => void; | ||
| handlePopUpConfirm: (result: boolean) => void; | ||
| isLarge?: boolean; | ||
| isTwoButton?: boolean; | ||
| } | ||
|
|
||
| function PopUp({ | ||
| isOpen, | ||
| isLarge = false, | ||
| isTwoButton = false, | ||
| label, | ||
| handlePopUpClose, | ||
| handlePopUpConfirm, | ||
| }: PopUpProps) { | ||
| const onClickClose = () => { | ||
| if (handlePopUpClose) { | ||
| handlePopUpClose(false); | ||
| } | ||
| }; | ||
|
|
||
| const onClickConfirm = () => { | ||
| if (handlePopUpConfirm) { | ||
| handlePopUpConfirm(true); | ||
| } | ||
| }; | ||
| return ( | ||
| <> | ||
| <div className={`${isOpen ? 'block' : 'hidden'}`}> | ||
| <div | ||
| className={`fixed left-0 top-0 h-screen w-screen bg-black bg-opacity-50`} | ||
| > | ||
| <div | ||
| role="pop-up" | ||
| className={`absolute left-2/4 top-2/4 flex -translate-x-2/4 -translate-y-2/4 flex-col items-center justify-between rounded-lg border opacity-100 ${isLarge ? 'h-[212px] w-[450px]' : 'h-[199px] w-[300px]'} bg-white p-[24px]`} | ||
| > | ||
| <button className="ml-auto" onClick={onClickClose}> | ||
| <IcClose role="close-icon" className="ml-auto" /> | ||
| </button> | ||
| <div className="flex flex-col items-center whitespace-pre-wrap text-center text-[#111827]"> | ||
| {label} | ||
| </div> | ||
| <div | ||
| className={`${isLarge && !isTwoButton ? 'ml-auto' : 'flex items-center gap-2'} `} | ||
| > | ||
| {isTwoButton ? ( | ||
| <Button | ||
| text="취소" | ||
| size="modal" | ||
| fillType="outline" | ||
| themeColor="green-normal-01" | ||
| onClick={onClickClose} | ||
| /> | ||
| ) : null} | ||
| <Button | ||
| text="확인" | ||
| size="modal" | ||
| fillType="solid" | ||
| themeColor="green-normal-01" | ||
| onClick={onClickConfirm} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default PopUp; | ||
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.
p4: 이 부분은 혹시 그냥 props함수를 밑에 바로 버튼에 넘겨주면 동작을 안할까요? 그냥 넘겨주는거랑 현재 코드상의 로직이 어떤 차이인지 궁금합니다!
저는 이런식으로 사용하는걸 생각했는데
이렇게 사용한다 가정하면 props로 넘긴 함수를 버튼에 바로 넣어도 되지 않을까?라는 생각이 들어서 여쭤봤습니다!
Uh oh!
There was an error while loading. Please reload this page.
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.
이 부분은 저도 고민을 했는데 클릭 시 리턴하는 값은 팝업을 끄는 부분과는 별개로 클릭한 버튼에 따라 이후 부모 컴포넌트에서 동작하는 상황이 달라질 것 같아서 저렇게 구현했습니다
ex) 모임 만들기 페이지에서 정보를 입력하던 중 유저가 다른 페이지로 이동하면 '정말 나가시겠어요? 작성된 내용이 모두 삭제됩니다' 팝업창이 뜸