Skip to content

Commit 8f8bf27

Browse files
authored
Merge pull request #47 from codeit9-temporary/feature/modalstore/link
Feature : modal store 세팅
2 parents 69550d6 + 6d9253f commit 8f8bf27

File tree

14 files changed

+222
-81
lines changed

14 files changed

+222
-81
lines changed

components/modal/AddFolderModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ const AddFolderModal = ({ folderName }: { folderName: string }) => {
88
</ModalContainer>
99
);
1010
};
11+
1112
export default AddFolderModal;

components/modal/AddModal.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1+
import { FolderItemType } from "@/types/modalTypes";
12
import FolderList from "./modalComponents/FolderList";
23
import ModalContainer from "./modalComponents/ModalContainer";
3-
interface ItemType {
4-
id: number;
5-
title: string;
6-
totalCount: number;
7-
}
8-
const list: ItemType[] = [
9-
{ id: 1, title: "코딩팁", totalCount: 7 },
10-
{ id: 2, title: "채용 사이트", totalCount: 7 },
11-
{ id: 3, title: "유용한 글", totalCount: 7 },
12-
{ id: 4, title: "나만의 장소", totalCount: 7 },
13-
];
144

15-
const AddModal = ({ list }: { list: ItemType[] }) => {
5+
const AddModal = ({ list }: { list: FolderItemType[] }) => {
166
return (
177
<ModalContainer
188
title="폴더에 추가"

components/modal/modalComponents/FolderItem.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { cls } from "@/lib/utils";
1+
import { bindCls } from "@/lib/utils";
2+
import { FolderItemType } from "@/types/modalTypes";
23
import { useState } from "react";
34
import { FaCheck } from "react-icons/fa6";
45

5-
interface ItemType {
6-
id: number;
7-
title: string;
8-
totalCount: number;
9-
}
10-
const FolderItem = ({ item }: { item: ItemType }) => {
6+
const FolderItem = ({ item }: { item: FolderItemType }) => {
117
const [selected, setSelected] = useState(false);
128

139
const bgColor = selected ? "bg-gray100" : "bg-white";
@@ -19,15 +15,15 @@ const FolderItem = ({ item }: { item: ItemType }) => {
1915
};
2016
return (
2117
<li
22-
className={cls(
18+
className={bindCls(
2319
bgColor,
2420
"w-full p-2 flex h-10 rounded-lg items-center justify-between"
2521
)}
2622
onClick={onClickFolder}
2723
>
2824
<div className="flex items-center gap-2">
2925
<div
30-
className={cls(
26+
className={bindCls(
3127
"text-base",
3228
selected ? "text-purple100" : "text-black300"
3329
)}

components/modal/modalComponents/FolderList.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1+
import { FolderItemType } from "@/types/modalTypes";
12
import FolderItem from "./FolderItem";
2-
interface ItemType {
3-
id: number;
4-
title: string;
5-
totalCount: number;
6-
}
73

8-
const list: ItemType[] = [
9-
{ id: 1, title: "코딩팁", totalCount: 7 },
10-
{ id: 2, title: "채용 사이트", totalCount: 7 },
11-
{ id: 3, title: "유용한 글", totalCount: 7 },
12-
{ id: 4, title: "나만의 장소", totalCount: 7 },
13-
];
14-
const FolderList = ({ list }: { list: ItemType[] }) => {
4+
const FolderList = ({ list }: { list: FolderItemType[] | undefined }) => {
155
return (
16-
<ul className="mb-6 flex flex-col gap-1 min-w-[280px] w-full">
17-
{list.map((item) => (
18-
<FolderItem key={item.id} item={item} />
19-
))}
6+
<ul className="mb-6 flex flex-col gap-1 w-full">
7+
{list?.map((item) => <FolderItem key={item.id} item={item} />)}
208
</ul>
219
);
2210
};

components/modal/modalComponents/ModalContainer.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
1-
import { MouseEvent, ReactNode } from "react";
21
import { IoIosClose } from "react-icons/io";
32
import Button from "../../Button";
3+
import { ModalPropType } from "@/types/modalTypes";
4+
import useModalStore from "@/store/useModalStore";
5+
import { MouseEvent, useRef } from "react";
46

57
const ModalContainer = ({
68
title,
79
subtitle,
810
children,
911
buttonText,
1012
buttonColor,
11-
onClick,
12-
}: {
13-
title: string;
14-
subtitle?: string;
15-
children?: ReactNode;
16-
buttonText?: string;
17-
buttonColor?: "positive" | "negative";
18-
onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
19-
}) => {
13+
}: ModalPropType) => {
14+
const { closeModal } = useModalStore();
15+
const modalRef = useRef<HTMLDivElement | null>(null);
16+
const onClickBackDrop = (e: MouseEvent<HTMLDivElement>) => {
17+
if (modalRef.current && !modalRef.current.contains(e.target as Node))
18+
closeModal();
19+
};
20+
2021
return (
21-
<div className="z-30 absolute top-0 left-0 flex justify-center items-center bg-black/40 h-screen w-screen">
22-
<div className="z-20 relative w-[360px] py-8 px-10 flex flex-col gap-6 bg-white rounded-[15px] border border-gray300">
22+
<div
23+
onClick={onClickBackDrop}
24+
className="z-30 absolute top-0 left-0 flex justify-center items-center bg-black/40 h-screen w-screen"
25+
>
26+
<div
27+
ref={modalRef}
28+
className="z-20 relative w-[300px] md:w-[360px] lg:w-[360px] py-8 px-10 flex flex-col gap-6 bg-white rounded-[15px] border border-gray300"
29+
>
2330
{/* 제목 + 부제목 */}
2431
<div className="flex flex-col items-center justify-center gap-2">
25-
<div className="text-center w-[280px] gap-2 text-black300 text-xl leading-6 font-bold">
26-
{title}
27-
</div>
32+
{title && (
33+
<div className="text-center w-[250px] md:w-[280px] lg:w-[280px] gap-2 text-black300 text-xl leading-6 font-bold">
34+
{title}
35+
</div>
36+
)}
2837
{subtitle && (
2938
<div className="text-sm leading-[22px] font-normal text-gray400">
3039
{subtitle}
@@ -51,7 +60,7 @@ const ModalContainer = ({
5160
{/* 모달 닫기 버튼 */}
5261
<button
5362
type="button"
54-
onClick={onClick}
63+
onClick={() => closeModal()}
5564
className="bg-gray200 absolute top-4 right-4 rounded-full size-6 flex justify-center items-center"
5665
>
5766
<IoIosClose className="text-gray400" strokeWidth={2} />

components/modal/modalComponents/ModalInput.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { cls } from "@/lib/utils";
1+
import { bindCls } from "@/lib/utils";
22

33
const ModalInput = ({
44
placeholder,
55
name,
66
}: {
7-
placeholder?: string;
7+
placeholder: string;
88
name: string;
99
}) => {
1010
return (
1111
<input
1212
type="text"
1313
name={name}
1414
id={name}
15-
className={cls(
15+
className={bindCls(
1616
"w-full rounded-lg border border-gray300 py-[18px] px-[15px] mb-6 text-black300",
1717
"placeholder:text-base placeholder:text-gray400",
1818
"focus:outline-1px focus:outline-purple100"

components/modal/modalComponents/ModalShareItem.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { cls } from "@/lib/utils";
21
import Image from "next/image";
32

43
const ModalShareItem = ({
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import useModalStore from "@/store/useModalStore";
2+
import AddModal from "../AddModal";
3+
import DeleteFolderModal from "../DeleteFolderModal";
4+
import AddFolderModal from "../AddFolderModal";
5+
import DeleteLinkModal from "../DeleteLinkModal";
6+
import EditModal from "../EditModal";
7+
import SNSModal from "../SNSModal";
8+
9+
export const ModalType = {
10+
AddFolderModal: "AddFolderModal",
11+
AddModal: "AddModal",
12+
DeleteFolderModal: "DeleteFolderModal",
13+
DeleteLinkModal: "DeleteLinkModal",
14+
EditModal: "EditModal",
15+
SNSModal: "SNSModal",
16+
} as const;
17+
18+
export type ModalKeysType = keyof typeof ModalType;
19+
20+
export const Modal = () => {
21+
const { modalType, isOpen, props } = useModalStore();
22+
23+
if (!modalType || !isOpen) return null;
24+
25+
switch (modalType) {
26+
case "AddFolderModal":
27+
return <AddFolderModal folderName={props.folderName || ""} />;
28+
case "AddModal":
29+
return (
30+
<AddModal
31+
list={
32+
props.list || [
33+
{ id: 1, title: "코딩팁", totalCount: 7 },
34+
{ id: 2, title: "채용 사이트", totalCount: 7 },
35+
{ id: 3, title: "유용한 글", totalCount: 7 },
36+
{ id: 4, title: "나만의 장소", totalCount: 7 },
37+
]
38+
}
39+
/>
40+
);
41+
case "DeleteFolderModal":
42+
return <DeleteFolderModal folderName={props.folderName || ""} />;
43+
case "DeleteLinkModal":
44+
return <DeleteLinkModal link={props.link || ""} />;
45+
case "EditModal":
46+
return <EditModal folderName={props.folderName || ""} />;
47+
case "SNSModal":
48+
return <SNSModal folderName={props.folderName || ""} />;
49+
}
50+
};

lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// tailwind 동적 스타일을 위한 함수
2-
export const cls = (...cls: string[]) => {
2+
export const bindCls = (...cls: string[]) => {
33
return cls.join(" ");
44
};

package-lock.json

Lines changed: 55 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)