-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat/#60] 게시물 삭제 모달 구현
- Loading branch information
Showing
8 changed files
with
210 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,2 @@ | ||
import { style } from "@vanilla-extract/css"; | ||
import { color } from "@style/styles.css.ts"; |
This file contains 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 |
---|---|---|
@@ -1,5 +1,25 @@ | ||
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} | ||
iconSize={2} | ||
onEdit={() => alert("수정하기")} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PostDetail; |
This file contains 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,92 @@ | ||
import { createVar, 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 iconSizeVar = createVar(); | ||
|
||
export const container = style({ | ||
position: "relative", | ||
width: iconSizeVar, | ||
height: iconSizeVar, | ||
}); | ||
|
||
export const moreIcon = style({ | ||
width: iconSizeVar, | ||
height: iconSizeVar, | ||
}); | ||
|
||
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 = 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", | ||
}); |
This file contains 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,67 @@ | ||
import React from "react"; | ||
import { IcEllipses } from "@asset/svg"; | ||
import { | ||
container, | ||
iconSizeVar, | ||
moreIcon, | ||
moreModal, | ||
moreModalDivider, | ||
moreModalItem, | ||
} from "@shared/component/MoreModal/MoreModal.css.ts"; | ||
import { assignInlineVars } from "@vanilla-extract/dynamic"; | ||
|
||
interface MoreModalParams { | ||
isOpen: boolean; | ||
onToggleModal: () => void; | ||
onDelete: () => void; | ||
iconSize: number; | ||
onEdit?: () => void; | ||
} | ||
|
||
const MoreModal = ({ | ||
isOpen, | ||
onToggleModal, | ||
onDelete, | ||
iconSize, | ||
onEdit, | ||
}: MoreModalParams) => { | ||
return ( | ||
<div | ||
className={container} | ||
style={assignInlineVars({ [iconSizeVar]: `${iconSize}rem` })} | ||
> | ||
<IcEllipses | ||
className={moreIcon} | ||
style={assignInlineVars({ [iconSizeVar]: `${iconSize}rem` })} | ||
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.
Empty file.
This file contains 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,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; |