Skip to content

Commit

Permalink
test: storybook에서 konva node를 감싸는 Stage 크기 반응형으로 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
hoqn committed Nov 7, 2024
1 parent beb2b7f commit 325099a
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/frontend/src/components/space/SpaceNode.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from "react";
import { Layer, Stage } from "react-konva";

import type { Meta, StoryObj } from "@storybook/react";
Expand All @@ -8,10 +9,26 @@ export default {
component: SpaceNode,
tags: ["autodocs"],
decorators: [
(Story) => {
// TODO: Konva를 위한 decorator 별도로 분리 작성 必
const width = 1000;
const height = 1000;
(Story, { canvasElement }) => {
// TODO: Konva Node를 위한 decorator 별도로 분리 必
const [size, setSize] = useState(() => ({
width: Math.max(canvasElement.clientWidth, 256),
height: Math.max(canvasElement.clientHeight, 256),
}));

const { width, height } = size;

useEffect(() => {
const observer = new ResizeObserver((entries) => {
entries.forEach((entry) => {
const { width, height } = entry.contentRect;
setSize({ width, height });
});
});

observer.observe(canvasElement);
return () => observer.unobserve(canvasElement);
}, [canvasElement]);

return (
<Stage width={width} height={height} draggable>
Expand Down

0 comments on commit 325099a

Please sign in to comment.