From 8a45143d503acedfcd4771365ae04570fcc74069 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Mon, 9 Sep 2024 15:01:32 +0900 Subject: [PATCH] Refactor gitignore and package.json --- .gitignore | 3 +++ package.json | 1 + src/app/draggable/page.jsx | 23 +++++++++++++++++++ .../common/draggable/withDraggable.jsx | 22 ++++++++++++++++++ yarn.lock | 13 +++++++++++ 5 files changed, 62 insertions(+) create mode 100644 src/app/draggable/page.jsx create mode 100644 src/components/common/draggable/withDraggable.jsx diff --git a/.gitignore b/.gitignore index fd3dbb5..8386eda 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +.vscode +.idea \ No newline at end of file diff --git a/package.json b/package.json index 07cbd17..2667d94 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "react-colorful": "^5.6.1", "react-datepicker": "^7.3.0", "react-dom": "^18", + "react-draggable": "^4.4.6", "react-responsive-modal": "^6.4.2", "recoil": "^0.7.7" }, diff --git a/src/app/draggable/page.jsx b/src/app/draggable/page.jsx new file mode 100644 index 0000000..7b4996b --- /dev/null +++ b/src/app/draggable/page.jsx @@ -0,0 +1,23 @@ +'use client' + +import { useState } from 'react' +import WithDraggable from '@/components/common/draggable/withDraggable' + +export default function DraggablePage() { + const [divIsShow, setDivIsShow] = useState(true) + + return ( + <> + {!divIsShow ? : ''} + {/* WithDraggable 태그로 이동하고 싶은 컴포넌트나 엘리먼트등을 감싸주면 WithDraggable 컴포넌트가 드래그 가능하게 만들어줍니다. */} + +
+

test draggable div

+
+ +
+
+
+ + ) +} diff --git a/src/components/common/draggable/withDraggable.jsx b/src/components/common/draggable/withDraggable.jsx new file mode 100644 index 0000000..9f32258 --- /dev/null +++ b/src/components/common/draggable/withDraggable.jsx @@ -0,0 +1,22 @@ +'use client' + +import { useState } from 'react' +import Draggable from 'react-draggable' + +export default function WithDraggable({ isShow, children }) { + const [position, setPosition] = useState({ x: 0, y: 0 }) + + const handleOnDrag = (data) => { + setPosition({ x: data.x, y: data.y }) + } + + return ( + <> + {isShow && ( + handleOnDrag(data)}> + {children} + + )} + + ) +} diff --git a/yarn.lock b/yarn.lock index 90960ab..7004870 100644 --- a/yarn.lock +++ b/yarn.lock @@ -333,6 +333,11 @@ client-only@0.0.1: resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1" integrity sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA== +clsx@^1.1.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12" + integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg== + clsx@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999" @@ -840,6 +845,14 @@ react-dom@^18: loose-envify "^1.1.0" scheduler "^0.23.2" +react-draggable@^4.4.6: + version "4.4.6" + resolved "https://registry.yarnpkg.com/react-draggable/-/react-draggable-4.4.6.tgz#63343ee945770881ca1256a5b6fa5c9f5983fe1e" + integrity sha512-LtY5Xw1zTPqHkVmtM3X8MUOxNDOUhv/khTgBgrUvwaS064bwVvxT+q5El0uUFNx5IEPKXuRejr7UqLwBIg5pdw== + dependencies: + clsx "^1.1.1" + prop-types "^15.8.1" + react-is@^16.13.1: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"