sample-ui-component-library 0.0.2-dev → 0.0.3-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sample-ui-component-library",
3
- "version": "0.0.2-dev",
3
+ "version": "0.0.3-dev",
4
4
  "description": "A library which contains sample UI elements that can be used for populating layouts.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -27,6 +27,7 @@
27
27
  "@babel/preset-env": "^7.26.9",
28
28
  "@babel/preset-react": "^7.26.3",
29
29
  "@chromatic-com/storybook": "^3.2.6",
30
+ "@dnd-kit/core": "^6.3.1",
30
31
  "@rollup/plugin-babel": "^6.0.4",
31
32
  "@rollup/plugin-commonjs": "^28.0.3",
32
33
  "@rollup/plugin-json": "^6.1.0",
@@ -63,7 +64,6 @@
63
64
  },
64
65
  "dependencies": {
65
66
  "@dagrejs/dagre": "^1.1.4",
66
- "@dnd-kit/core": "^6.3.1",
67
67
  "@monaco-editor/react": "^4.7.0",
68
68
  "@xyflow/react": "^12.6.0",
69
69
  "bootstrap": "^5.3.4",
@@ -2,6 +2,12 @@ import { useEffect } from "react";
2
2
  import { Editor } from "../components/Editor";
3
3
  import { useArgs } from "@storybook/preview-api";
4
4
  import { action } from "@storybook/addon-actions";
5
+ import {
6
+ DndContext,
7
+ DragOverlay,
8
+ useDraggable,
9
+ useDroppable,
10
+ } from "@dnd-kit/core";
5
11
 
6
12
  import fileTrees from "./data/filetree.json";
7
13
 
@@ -13,6 +19,38 @@ export default {
13
19
  argTypes: {}
14
20
  };
15
21
 
22
+ /**
23
+ * Preview for the div being dragged.
24
+ * @returns
25
+ */
26
+ function DragPreview({ label }) {
27
+ return (
28
+ <div
29
+ style={{
30
+ padding: "6px 12px",
31
+ background: "#2d2d2d",
32
+ color: "white",
33
+ boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
34
+ opacity:0.3
35
+ }}
36
+ >
37
+ {label}
38
+ </div>
39
+ );
40
+ }
41
+
42
+ /**
43
+ * Offset for the drag overlay.
44
+ * @returns
45
+ */
46
+ const offsetOverlay = ({ transform }) => {
47
+ return {
48
+ ...transform,
49
+ x: transform.x + 20,
50
+ y: transform.y + 20
51
+ };
52
+ };
53
+
16
54
  const Template = (args) => {
17
55
  const [, updateArgs] = useArgs();
18
56
 
@@ -24,10 +62,40 @@ const Template = (args) => {
24
62
  updateArgs({onFileSelect : onFileSelect});
25
63
  }, []);
26
64
 
65
+ /**
66
+ * Callback for when drag ends.
67
+ */
68
+ const handleDragEnd = (event) =>{
69
+ const { active, over } = event;
70
+ console.log("Drag Ended");
71
+ const rect = event.activatorEvent;
72
+
73
+ console.log(over );
74
+
75
+ if (over) {
76
+ console.log("Dragged item:", active.id);
77
+ console.log("Dropped on:", over.id);
78
+ } else {
79
+ console.log("Dropped outside any droppable");
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Callback for when drag is started.
85
+ */
86
+ const onDragStart = (event) => {
87
+ console.log("Drag Started");
88
+ }
89
+
27
90
  return (
28
- <div className="editorStoryWrapper">
29
- <Editor {...args} />
30
- </div>
91
+ <DndContext onDragStart={onDragStart} onDragEnd={handleDragEnd}>
92
+ <div className="editorStoryWrapper">
93
+ <Editor {...args} />
94
+ </div>
95
+ <DragOverlay modifiers={[offsetOverlay]} dropAnimation={null}>
96
+ <DragPreview label={"preview"}/>
97
+ </DragOverlay>
98
+ </DndContext>
31
99
  )
32
100
  }
33
101