-
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 #377 from boostcampwm-2024/feature-fe-#374
노드 색상 변경 기능 추가
- Loading branch information
Showing
10 changed files
with
129 additions
and
7 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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export { CursorButton } from "./ui/CursorButton"; | ||
export { CursorPreview } from "./ui/CursorPreview"; | ||
export { ProfileForm } from "./ui/ProfileForm"; | ||
export { ProfilePanel } from "./ui/ProfilePanel"; | ||
export { NewNodePanel } from "./ui/NewNodePanel"; | ||
export { NodePanel } from "./ui/NodePanel"; | ||
export { ProfilePanel } from "./ui/ProfilePanel"; |
45 changes: 45 additions & 0 deletions
45
apps/frontend/src/features/canvasTools/ui/NodeForm/index.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { usePopover } from "@/shared/model"; | ||
|
||
interface NodeFormProps { | ||
changeNodeColor: (color: string) => void; | ||
} | ||
|
||
export function NodeForm({ changeNodeColor }: NodeFormProps) { | ||
const { close } = usePopover(); | ||
|
||
const nodeBackgroundColors = { | ||
white: "#FFFFFF", | ||
grey: "#F1F1EF", | ||
brown: "#F4EEEE", | ||
orange: "#FBEBDD", | ||
yellow: "#FCF3DB", | ||
green: "#EDF3ED", | ||
blue: "#E7F3F8", | ||
purple: "#F7F3F8", | ||
pink: "#FBF2F5", | ||
red: "#FDEBEC", | ||
}; | ||
|
||
const handleButtonClick = (color: string) => { | ||
changeNodeColor(color); | ||
close(); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<p className="text-sm text-neutral-500">Background color</p> | ||
<div className="grid grid-cols-5 gap-4"> | ||
{Object.entries(nodeBackgroundColors).map(([key, color]) => { | ||
return ( | ||
<button | ||
key={key} | ||
onClick={() => handleButtonClick(color)} | ||
className="h-7 w-7 rounded-md border-[1px] border-neutral-300 hover:cursor-pointer" | ||
style={{ backgroundColor: color }} | ||
/> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
} |
47 changes: 47 additions & 0 deletions
47
apps/frontend/src/features/canvasTools/ui/NodePanel/index.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import { NodeForm } from "../NodeForm"; | ||
import { Node } from "@/entities/node"; | ||
import { useYDocStore } from "@/shared/model"; | ||
import { Popover } from "@/shared/ui"; | ||
|
||
interface NodePanelProps { | ||
currentPage: string; | ||
} | ||
|
||
export function NodePanel({ currentPage }: NodePanelProps) { | ||
const [currentColor, setCurrentColor] = useState("#ffffff"); | ||
const { ydoc } = useYDocStore(); | ||
|
||
const changeNodeColor = (color: string) => { | ||
const nodesMap = ydoc.getMap("nodes"); | ||
const id = currentPage.toString(); | ||
|
||
const existingNode = nodesMap.get(id) as Node; | ||
nodesMap.set(id, { | ||
...existingNode, | ||
data: { ...existingNode.data, color }, | ||
}); | ||
setCurrentColor(color); | ||
}; | ||
|
||
useEffect(() => { | ||
const nodesMap = ydoc.getMap("nodes"); | ||
const currentNode = nodesMap.get(currentPage.toString()) as Node; | ||
setCurrentColor(currentNode.data.color as string); | ||
}, [currentPage]); | ||
|
||
return ( | ||
<Popover placement="bottom" align="start" offset={{ x: -11, y: 16 }}> | ||
<Popover.Trigger> | ||
<button | ||
className="flex h-7 w-7 items-center justify-center rounded-md border-[1px] border-neutral-300" | ||
style={{ backgroundColor: currentColor }} | ||
/> | ||
</Popover.Trigger> | ||
<Popover.Content className="rounded-lg border bg-white p-3 shadow-md"> | ||
<NodeForm changeNodeColor={changeNodeColor} /> | ||
</Popover.Content> | ||
</Popover> | ||
); | ||
} |
3 changes: 2 additions & 1 deletion
3
apps/frontend/src/features/canvasTools/ui/ProfilePanel/index.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
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 @@ | ||
export { NodeToolsView } from "./ui"; |
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,14 @@ | ||
import { usePageStore } from "@/entities/page"; | ||
import { NodePanel } from "@/features/canvasTools/ui/NodePanel"; | ||
|
||
export function NodeToolsView() { | ||
const { currentPage } = usePageStore(); | ||
|
||
if (!currentPage) return null; | ||
|
||
return ( | ||
<div className="z-10 flex flex-row rounded-xl border-[1px] border-neutral-200 bg-white p-2.5 text-black shadow-md"> | ||
<NodePanel currentPage={currentPage.toString()} /> | ||
</div> | ||
); | ||
} |