Skip to content
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

[Feat/#60] 게시물 삭제 모달 구현 #64

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/common/component/BottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ interface BottomSheetPropTypes {
}

//화면 전체를 차지하는 바텀시트 틀 (children 필요)
const BottomSheet = ({ isOpen, children, handleOpen }: BottomSheetPropTypes) => {
const BottomSheet = ({
isOpen,
children,
handleOpen,
}: BottomSheetPropTypes) => {
if (!isOpen) return;

const handleClose = () => {
Expand All @@ -20,12 +24,19 @@ const BottomSheet = ({ isOpen, children, handleOpen }: BottomSheetPropTypes) =>
};

return (
<div className={styles.overlay} onClick={handleClose} onKeyDown={handleClose}>
<div
className={styles.overlay}
onClick={handleClose}
onKeyDown={handleClose}
>
<div className={styles.bottomSheet} onClick={handleBottomSheetClick}>
<div className={styles.bottomTabBar}>
<div className={styles.bar} onClick={handleClose} onKeyDown={handleClose} />
<div
className={styles.bar}
onClick={handleClose}
onKeyDown={handleClose}
/>
</div>

{children}
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/page/community/[postId]/Post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { style } from "@vanilla-extract/css";
import { color } from "@style/styles.css.ts";
27 changes: 26 additions & 1 deletion src/page/community/[postId]/Post.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import MoreModal from "@shared/component/MoreModal/MoreModal.tsx";
import useMoreModal from "@shared/hook/useMoreModal";

const PostDetail = () => {
return <div>Postid</div>;
const { isOpen, openModal, closeModal, toggleModal } = useMoreModal();

const handleDelete = () => {
alert("삭제되었습니다!");
toggleModal();
};

return (
<div>
<MoreModal
isOpen={isOpen}
onToggleModal={toggleModal}
onDelete={handleDelete}
/>
<MoreModal
isOpen={isOpen}
onToggleModal={toggleModal}
onDelete={handleDelete}
iconSize="20"
onEdit={() => alert("수정하기")}
/>
</div>
);
};

export default PostDetail;
140 changes: 140 additions & 0 deletions src/shared/component/MoreModal/MoreModal.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { style } from "@vanilla-extract/css";
import { recipe, RecipeVariants } from "@vanilla-extract/recipes";
import { button } from "@common/component/Button/styles.css.ts";
import { color, font } from "@style/styles.css.ts";

export const container = recipe({
base: {
margin: "20rem",
position: "relative",
width: "2.4rem",
},
variants: {
iconSize: {
"24": {
width: "2.4rem",
height: "2.4rem",
},
"20": {
width: "2.0rem",
height: "2.0rem",
},
},
},
});

export const moreIcon = recipe({
base: {
width: "2.4rem",
height: "2.4rem",
},
variants: {
iconSize: {
"24": {
width: "2.4rem",
height: "2.4rem",
},
"20": {
width: "2.0rem",
height: "2.0rem",
},
},
},
});

export type MoreIconProps = RecipeVariants<typeof moreIcon>;

export const moreModal = recipe({
base: {
position: "absolute",
top: "calc(100% + 0.8rem)",
left: "-16rem",
display: "flex",
flexDirection: "column",
borderRadius: "1.2rem",
backgroundColor: "white",
boxShadow: "0px 2px 10px 0px rgba(0, 0, 0, 0.15)",
width: "18.4rem",
zIndex: 10,
},
variants: {
onEdit: {
true: {
// 수정하기가 있을 때
height: "11.2rem",
},
false: {
// 수정하기가 없을 때
height: "5.6rem",
},
},
},
defaultVariants: {
onEdit: false, // 기본값
},
});

// export const moreModalItem = style([
// font.body01,
// {
// background: "none",
// border: "none",
// borderRadius: "1.2rem",
// textAlign: "left",
// width: "100%",
// padding: "1.8rem 3.2rem",
// color: color.red.warning_red200,
// ":hover": {
// borderRadius: "unset",
// backgroundColor: color.gray.gray300,
// },
// ":active": {
// backgroundColor: color.gray.gray300,
// },
// },
// ]);

export const moreModalItem = recipe({
base: [
font.body01,
{
background: "none",
border: "none",
textAlign: "left",
width: "100%",
padding: "1.8rem 3.2rem",
color: color.red.warning_red200,
":hover": {
backgroundColor: color.gray.gray300,
},
":active": {
backgroundColor: color.gray.gray300,
},
},
],
variants: {
position: {
first: {
// 수정하기가 들어간 경우의 삭제하기 border
borderRadius: "1.2rem 1.2rem 0 0",
},
last: {
// 수정하기가 들어간 경우의 수정하기 border
borderRadius: "0 0 1.2rem 1.2rem",
},
default: {
// 수정하기가 없는 경우의 border
borderRadius: "1.2rem",
},
},
},
defaultVariants: {
position: "default",
},
});

export const moreModalDivider = style({
height: "1px",
backgroundColor: color.gray.gray300,
margin: "0",
});
60 changes: 60 additions & 0 deletions src/shared/component/MoreModal/MoreModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from "react";
import { IcEllipses } from "@asset/svg";
import {
container,
moreIcon,
MoreIconProps,
moreModal,
moreModalDivider,
moreModalItem,
} from "@shared/component/MoreModal/MoreModal.css.ts";

interface MoreModalParams {
isOpen: boolean;
onToggleModal: () => void;
onDelete: () => void;
onEdit?: () => void; // 선택적 수정하기 동작
}

type MoreModalProps = MoreModalParams & MoreIconProps;

const MoreModal = ({
isOpen,
onToggleModal,
onDelete,
iconSize,
onEdit,
}: MoreModalProps) => {
return (
<div className={container({ iconSize })}>
<IcEllipses className={moreIcon({ iconSize })} onClick={onToggleModal} />
{isOpen && (
<div className={moreModal({ onEdit: !!onEdit })}>
<button
className={moreModalItem({
position: !!onEdit ? "first" : "default",
})}
onClick={onDelete}
>
삭제하기
</button>
{onEdit && (
<>
<div className={moreModalDivider} />
<button
className={moreModalItem({
position: !!onEdit ? "last" : "default",
})}
onClick={onEdit}
>
수정하기
</button>
</>
)}
</div>
)}
</div>
);
};

export default MoreModal;
Empty file removed src/shared/constant/.gitkeep
Empty file.
Empty file removed src/shared/hook/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions src/shared/hook/useMoreModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useState } from "react";

const useMoreModal = () => {
const [isOpen, setIsOpen] = useState(false);

const openModal = () => setIsOpen(true);
const closeModal = () => setIsOpen(false);
const toggleModal = () => setIsOpen((prev) => !prev);

return { isOpen, openModal, closeModal, toggleModal };
};

export default useMoreModal;
Loading