diff --git a/packages/frontend/src/components/Node.tsx b/packages/frontend/src/components/Node.tsx new file mode 100644 index 00000000..133d4a77 --- /dev/null +++ b/packages/frontend/src/components/Node.tsx @@ -0,0 +1,111 @@ +/* eslint-disable no-undef */ +import { useEffect, useRef, useState } from "react"; +import { Circle, Group, Text } from "react-konva"; + +import Konva from "konva"; + +type NodeProps = { + x: number; + y: number; + draggable?: boolean; + children?: React.ReactNode; +} & Konva.GroupConfig; + +export default function Node({ + x, + y, + draggable, + children, + ...rest +}: NodeProps) { + return ( + + {children} + + ); +} + +type NodeCircleProps = { + radius: number; + fill: string; +}; + +Node.Circle = function NodeCircle({ radius, fill }: NodeCircleProps) { + return ; +}; + +type NodeTextProps = { + content: string; + fontSize?: number; + fontStyle?: string; + width?: number; +}; + +Node.Text = function NodeText({ + content, + fontSize, + fontStyle, + width, +}: NodeTextProps) { + const ref = useRef(null); + const [offset, setOffset] = useState(undefined); + + useEffect(() => { + if (!ref.current) { + return; + } + + setOffset({ x: ref.current.width() / 2, y: ref.current.height() / 2 }); + }, [content]); + + return ( + + ); +}; + +type HeadNodeProps = { + name: string; +}; + +export function HeadNode({ name }: HeadNodeProps) { + const radius = 64; + return ( + + + + + ); +} + +type NoteNodeProps = { + x: number; + y: number; + src: string; + name: string; +}; + +export function NoteNode({ x, y, name }: NoteNodeProps) { + // TODO: src 적용 필요 + const radius = 64; + return ( + + + + + ); +} diff --git a/packages/frontend/src/components/space/SpaceView.tsx b/packages/frontend/src/components/space/SpaceView.tsx index 101fba4b..5b8d4a56 100644 --- a/packages/frontend/src/components/space/SpaceView.tsx +++ b/packages/frontend/src/components/space/SpaceView.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from "react"; import { Layer, Stage } from "react-konva"; +import { HeadNode, NoteNode } from "../Node.tsx"; import SpaceNode from "./SpaceNode.tsx"; interface SpaceViewProps { @@ -42,7 +43,9 @@ export default function SpaceView({ autofitTo }: SpaceViewProps) { return ( - + {/* */} + + );