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

노트 노드 UI 구현 #102

Merged
merged 3 commits into from
Nov 12, 2024
Merged
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
111 changes: 111 additions & 0 deletions packages/frontend/src/components/Node.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Group x={x} y={y} draggable={draggable} {...rest}>
{children}
</Group>
);
}

type NodeCircleProps = {
radius: number;
fill: string;
};

Node.Circle = function NodeCircle({ radius, fill }: NodeCircleProps) {
return <Circle x={0} y={0} radius={radius} fill={fill} />;
};

type NodeTextProps = {
content: string;
fontSize?: number;
fontStyle?: string;
width?: number;
};

Node.Text = function NodeText({
content,
fontSize,
fontStyle,
width,
}: NodeTextProps) {
const ref = useRef<Konva.Text>(null);
const [offset, setOffset] = useState<Konva.Vector2d | undefined>(undefined);

useEffect(() => {
if (!ref.current) {
return;
}

setOffset({ x: ref.current.width() / 2, y: ref.current.height() / 2 });
}, [content]);

return (
<Text
ref={ref}
fontSize={fontSize}
fontStyle={fontStyle}
offset={offset}
text={content}
width={width}
align="center"
wrap="none"
ellipsis
/>
);
};

type HeadNodeProps = {
name: string;
};

export function HeadNode({ name }: HeadNodeProps) {
const radius = 64;
return (
<Node x={0} y={0}>
<Node.Circle radius={radius} fill="#FFCC00" />
<Node.Text
width={radius * 2}
fontSize={16}
fontStyle="700"
content={name}
/>
</Node>
);
}

type NoteNodeProps = {
x: number;
y: number;
src: string;
name: string;
};

export function NoteNode({ x, y, name }: NoteNodeProps) {
// TODO: src 적용 필요
const radius = 64;
return (
<Node x={x} y={y}>
<Node.Circle radius={radius} fill="#FFF2CB" />
<Node.Text fontSize={16} content={name} />
</Node>
);
}
5 changes: 4 additions & 1 deletion packages/frontend/src/components/space/SpaceView.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -42,7 +43,9 @@ export default function SpaceView({ autofitTo }: SpaceViewProps) {
return (
<Stage width={stageSize.width} height={stageSize.height} draggable>
<Layer offsetX={-stageSize.width / 2} offsetY={-stageSize.height / 2}>
<SpaceNode label="HEAD NODE" x={0} y={0} />
{/* <SpaceNode label="HEAD NODE" x={0} y={0} /> */}
<HeadNode name="Hello World" />
<NoteNode x={100} y={100} src={""} name={"note"} />
</Layer>
</Stage>
);
Expand Down
Loading