-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] 모달 공통 컴포넌트 분리 및 레이아웃 구조화 #53
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 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a7924f9
feat: 모달 공통 컴포넌트 분리 및 레이아웃 구조화
jeonghwanJay faee521
refactor: 중복된 Modal.tsx 파일 제거
jeonghwanJay 94fb9a8
Merge branch 'dev' into COMPONENT-28-JI
jeonghwanJay 96d6f00
refactor : zustand 기반 전역 상태 관리
jeonghwanJay b5f5ade
refactor : Modal 버튼 텍스트 수정 및 전역 컴포넌트 등록
jeonghwanJay 4f1deda
refactor : Modal 공통 컴포넌트 개선
jeonghwanJay 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import Button from "../Button"; | ||
|
|
||
| import { Check, Notice } from "@/assets/icon"; | ||
|
|
||
| interface ModalButton { | ||
| label: string; | ||
| style: "primary" | "white"; | ||
| onClick: () => void; | ||
| } | ||
|
|
||
| interface Props { | ||
| iconType?: "check" | "warning" | "none"; | ||
| message: string; | ||
| button: ModalButton; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| const ICONS = { | ||
| check: Check, | ||
| warning: Notice, | ||
| }; | ||
|
|
||
| export default function AlertModalLayout({ | ||
| iconType = "none", | ||
| message, | ||
| button, | ||
| onClose, | ||
| }: Props) { | ||
| const Icon = iconType !== "none" ? ICONS[iconType] : null; | ||
|
|
||
| return ( | ||
| <div | ||
| className="bg-white p-7 rounded-lg text-center w-[18.625rem] h-[11.5rem] flex flex-col justify-between items-center" | ||
| onClick={(e) => e.stopPropagation()} | ||
| > | ||
| {Icon && <Icon className="w-6 h-6 mb-3" />} | ||
| <p className="text-base text-black font-normal mb-5">{message}</p> | ||
| <Button | ||
| variant={button.style} | ||
| onClick={() => { | ||
| button.onClick(); | ||
| onClose(); | ||
| }} | ||
| textSize="sm" | ||
| className="py-2 px-4 cursor-pointer" | ||
| > | ||
| {button.label} | ||
| </Button> | ||
| </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,33 @@ | ||
| interface ConfirmModalLayoutProps { | ||
| message: string; | ||
| onClose: () => void; | ||
| onConfirm: () => void; | ||
| } | ||
|
|
||
| export default function ConfirmModalLayout({ | ||
| message, | ||
| onClose, | ||
| onConfirm, | ||
| }: ConfirmModalLayoutProps) { | ||
| return ( | ||
| <div className="w-[18.625rem] md:w-[18.625rem] bg-white rounded-lg p-6 text-center"> | ||
| <p className="text-gray-900 text-base md:text-lg font-normal mb-6"> | ||
| {message} | ||
| </p> | ||
| <div className="flex justify-end gap-3"> | ||
| <button | ||
| onClick={onClose} | ||
| className="w-[7.5rem] h-[3rem] border border-red-500 text-red-500 rounded" | ||
| > | ||
| 아니오 | ||
| </button> | ||
| <button | ||
| onClick={onConfirm} | ||
| className="w-[7.5rem] h-[3rem] bg-red-500 text-white rounded" | ||
| > | ||
| 예 | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
jeonghwanJay marked this conversation as resolved.
Show resolved
Hide resolved
|
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,55 @@ | ||
| import AlertModalLayout from "./AlertModalLayout"; | ||
| import ConfirmModalLayout from "./ConfirmModalLayout"; | ||
|
|
||
| import { useModalStore } from "@/store/useModalStore"; | ||
|
|
||
| export default function Modal() { | ||
| const { isOpen, options, closeModal } = useModalStore(); | ||
|
|
||
| if (!isOpen || !options) return null; | ||
|
|
||
| const handleClose = () => { | ||
| options.onClose?.(); | ||
| closeModal(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/50"> | ||
| {options.type === "alert" && ( | ||
| <AlertModalLayout | ||
| message={options.message} | ||
| onClose={handleClose} | ||
| iconType={options.iconType ?? "none"} | ||
| button={{ | ||
| label: "확인", | ||
| style: "primary", | ||
| onClick: handleClose, | ||
| }} | ||
| /> | ||
| )} | ||
|
|
||
| {options.type === "confirm" && ( | ||
| <ConfirmModalLayout | ||
| message={options.message} | ||
| onClose={handleClose} | ||
| onConfirm={() => { | ||
| options.onConfirm?.(); | ||
| closeModal(); | ||
| }} | ||
| /> | ||
| )} | ||
|
|
||
| {options.type === "message" && ( | ||
| <AlertModalLayout | ||
| message={options.message} | ||
| onClose={handleClose} | ||
| button={{ | ||
| label: "확인", | ||
| style: "primary", | ||
| onClick: handleClose, | ||
| }} | ||
| /> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
Empty file.
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,32 @@ | ||
| import { create } from "zustand"; | ||
|
|
||
| export type ModalType = "alert" | "confirm" | "message"; | ||
|
|
||
| export interface ModalButton { | ||
| label: string; | ||
| style: "primary" | "white"; | ||
| onClick: () => void; | ||
| } | ||
|
|
||
| export interface ModalOptions { | ||
| type: "alert" | "confirm" | "message"; | ||
| message: string; | ||
| iconType?: "check" | "warning" | "none"; | ||
| buttons?: ModalButton[]; | ||
| onClose?: () => void; | ||
| onConfirm?: () => void; | ||
| } | ||
|
|
||
| interface ModalState { | ||
| isOpen: boolean; | ||
| options: ModalOptions | null; | ||
| openModal: (options: ModalOptions) => void; | ||
| closeModal: () => void; | ||
| } | ||
|
|
||
| export const useModalStore = create<ModalState>((set) => ({ | ||
| isOpen: false, | ||
| options: null, | ||
| openModal: (options) => set({ isOpen: true, options }), | ||
| closeModal: () => set({ isOpen: false, options: null }), | ||
| })); |
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,10 @@ | ||
| declare module "*.svg?react" { | ||
| import * as React from "react"; | ||
| const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>; | ||
| export default ReactComponent; | ||
| } | ||
|
|
||
| declare module "*.svg" { | ||
| const content: string; | ||
| export default content; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.