-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from boostcampwm-2024/Feature/#162_블록_옵션창_구현
Feature/#162 블록 옵션창 구현
- Loading branch information
Showing
12 changed files
with
558 additions
and
20 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
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,39 @@ | ||
import { AnimationType, ElementType } from "@noctaCrdt/Interfaces"; | ||
|
||
export const OPTION_CATEGORIES = { | ||
TYPE: { | ||
id: "type", | ||
label: "전환", | ||
options: [ | ||
{ id: "p", label: "p" }, | ||
{ id: "h1", label: "h1" }, | ||
{ id: "h2", label: "h2" }, | ||
{ id: "h3", label: "h3" }, | ||
{ id: "ul", label: "ul" }, | ||
{ id: "ol", label: "ol" }, | ||
{ id: "checkbox", label: "checkbox" }, | ||
{ id: "blockquote", label: "blockquote" }, | ||
] as { id: ElementType; label: string }[], | ||
}, | ||
ANIMATION: { | ||
id: "animation", | ||
label: "애니메이션", | ||
options: [ | ||
{ id: "none", label: "없음" }, | ||
{ id: "highlight", label: "하이라이트" }, | ||
{ id: "gradation", label: "그라데이션" }, | ||
] as { id: AnimationType; label: string }[], | ||
}, | ||
DUPLICATE: { | ||
id: "duplicate", | ||
label: "복제", | ||
options: null, | ||
}, | ||
DELETE: { | ||
id: "delete", | ||
label: "삭제", | ||
options: null, | ||
}, | ||
}; | ||
|
||
export type OptionCategory = keyof typeof OPTION_CATEGORIES; |
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
78 changes: 75 additions & 3 deletions
78
client/src/features/editor/components/MenuBlock/MenuBlock.tsx
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,17 +1,89 @@ | ||
import { AnimationType, ElementType } from "@noctaCrdt/Interfaces"; | ||
import { useState, useRef } from "react"; | ||
import DraggableIcon from "@assets/icons/draggable.svg?url"; | ||
import { useModal } from "@src/components/modal/useModal"; | ||
import { OptionModal } from "../OptionModal/OptionModal"; | ||
import { menuBlockStyle, dragHandleIconStyle } from "./MenuBlock.style"; | ||
|
||
interface MenuBlockProps { | ||
export interface MenuBlockProps { | ||
attributes?: Record<string, any>; | ||
listeners?: Record<string, any>; | ||
onAnimationSelect: (animation: AnimationType) => void; | ||
onTypeSelect: (type: ElementType) => void; | ||
onCopySelect: () => void; | ||
onDeleteSelect: () => void; | ||
} | ||
|
||
export const MenuBlock = ({ attributes, listeners }: MenuBlockProps) => { | ||
export const MenuBlock = ({ | ||
attributes, | ||
listeners, | ||
onAnimationSelect, | ||
onTypeSelect, | ||
onCopySelect, | ||
onDeleteSelect, | ||
}: MenuBlockProps) => { | ||
const menuBlockRef = useRef<HTMLDivElement>(null); | ||
|
||
const [pressTime, setPressTime] = useState<NodeJS.Timeout | null>(null); | ||
const [isDragging, setIsDragging] = useState(false); | ||
const [menuBlockPosition, setMenuBlockPosition] = useState<{ top: number; right: number }>({ | ||
top: 0, | ||
right: 0, | ||
}); | ||
|
||
const { isOpen, openModal, closeModal } = useModal(); | ||
|
||
const handlePressStart = () => { | ||
const timer = setTimeout(() => { | ||
setIsDragging(true); | ||
}, 300); | ||
|
||
setPressTime(timer); | ||
}; | ||
|
||
const handlePressEnd = () => { | ||
if (pressTime) { | ||
clearTimeout(pressTime); | ||
setPressTime(null); | ||
} | ||
|
||
if (!isDragging) { | ||
if (menuBlockRef.current) { | ||
const { top, right } = menuBlockRef.current.getBoundingClientRect(); | ||
setMenuBlockPosition({ top, right }); | ||
} | ||
openModal(); | ||
} | ||
setIsDragging(false); | ||
}; | ||
|
||
const modifiedListeners = { | ||
...listeners, | ||
// dnd 이벤트 덮어쓰기 | ||
onMouseDown: (e: React.MouseEvent) => { | ||
handlePressStart(); | ||
listeners?.onMouseDown?.(e); | ||
}, | ||
onMouseUp: (e: React.MouseEvent) => { | ||
handlePressEnd(); | ||
listeners?.onMouseUp?.(e); | ||
}, | ||
}; | ||
|
||
return ( | ||
<div className={menuBlockStyle} {...attributes} {...listeners}> | ||
<div ref={menuBlockRef} className={menuBlockStyle} {...attributes} {...modifiedListeners}> | ||
<div className={dragHandleIconStyle}> | ||
<img src={DraggableIcon} alt="drag handle" width="10" height="10" /> | ||
</div> | ||
<OptionModal | ||
isOpen={isOpen} | ||
onClose={closeModal} | ||
menuBlockPosition={menuBlockPosition} | ||
onAnimationSelect={onAnimationSelect} | ||
onTypeSelect={onTypeSelect} | ||
onDeleteSelect={onDeleteSelect} | ||
onCopySelect={onCopySelect} | ||
/> | ||
</div> | ||
); | ||
}; |
10 changes: 10 additions & 0 deletions
10
client/src/features/editor/components/OptionModal/OptionModal.animaiton.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const modal = { | ||
initial: { | ||
opacity: 0, | ||
x: -5, | ||
}, | ||
animate: { | ||
opacity: 1, | ||
x: 0, | ||
}, | ||
}; |
29 changes: 29 additions & 0 deletions
29
client/src/features/editor/components/OptionModal/OptionModal.style.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { css } from "@styled-system/css"; | ||
|
||
export const optionModal = css({ | ||
zIndex: "10000", | ||
position: "fixed", | ||
borderRadius: "8px", | ||
width: "160px", | ||
padding: "8px", | ||
background: "white", | ||
boxShadow: "md", | ||
}); | ||
|
||
export const optionButton = css({ | ||
borderRadius: "8px", | ||
width: "100%", | ||
paddingBlock: "4px", | ||
paddingInline: "8px", | ||
textAlign: "left", | ||
_hover: { | ||
backgroundColor: "gray.100/40", | ||
cursor: "pointer", | ||
}, | ||
}); | ||
|
||
export const modalContainer = css({ | ||
display: "flex", | ||
gap: "1", | ||
flexDirection: "column", | ||
}); |
Oops, something went wrong.