Skip to content

Commit 7fd78cf

Browse files
Merge pull request #164 from festim-dev/improve-drag-n-drop
Improve drag n drop
2 parents f6e0ac3 + d4b2d5d commit 7fd78cf

File tree

4 files changed

+83
-9
lines changed

4 files changed

+83
-9
lines changed

src/App.jsx

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const DnDFlow = () => {
4848
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
4949
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
5050
const [selectedNode, setSelectedNode] = useState(null);
51+
const [sidebarVisible, setSidebarVisible] = useState(true);
5152
const [activeTab, setActiveTab] = useState('graph');
5253
const [simulationResults, setSimulationResults] = useState(null);
5354
const [selectedEdge, setSelectedEdge] = useState(null);
@@ -957,9 +958,74 @@ const DnDFlow = () => {
957958
{/* Graph Editor Tab */}
958959
{activeTab === 'graph' && (
959960
<div style={{ display: 'flex', flex: 1, height: 'calc(100vh - 50px)', overflow: 'hidden' }}>
960-
<div style={{ width: 250, height: '100%', borderRight: '1px solid #ccc' }}>
961-
<Sidebar />
962-
</div>
961+
{/* Sidebar Toggle Button */}
962+
<button
963+
onClick={() => setSidebarVisible(!sidebarVisible)}
964+
style={{
965+
position: 'absolute',
966+
top: '60px',
967+
left: sidebarVisible ? '240px' : '10px',
968+
zIndex: 1000,
969+
backgroundColor: '#2c2c54',
970+
color: '#ffffff',
971+
border: '1px solid #555',
972+
borderRadius: '4px',
973+
width: '32px',
974+
height: '32px',
975+
cursor: 'pointer',
976+
display: 'flex',
977+
alignItems: 'center',
978+
justifyContent: 'center',
979+
transition: 'left 0.3s ease',
980+
boxShadow: '0 2px 4px rgba(0,0,0,0.3)',
981+
padding: '4px'
982+
}}
983+
onMouseEnter={(e) => {
984+
e.target.style.backgroundColor = '#3c3c64';
985+
e.target.style.borderColor = '#78A083';
986+
}}
987+
onMouseLeave={(e) => {
988+
e.target.style.backgroundColor = '#2c2c54';
989+
e.target.style.borderColor = '#555';
990+
}}
991+
title={sidebarVisible ? 'Hide Sidebar' : 'Show Sidebar'}
992+
>
993+
<svg
994+
width="20"
995+
height="20"
996+
viewBox="0 0 24 24"
997+
fill="none"
998+
xmlns="http://www.w3.org/2000/svg"
999+
>
1000+
{sidebarVisible ? (
1001+
// Hide sidebar icon (sidebar with left arrow)
1002+
<>
1003+
<rect x="2" y="3" width="6" height="18" rx="1" fill="currentColor" opacity="0.3" />
1004+
<rect x="10" y="3" width="12" height="18" rx="1" stroke="currentColor" strokeWidth="1.5" fill="none" />
1005+
<path d="M6 12L4 10M6 12L4 14M6 12H1" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
1006+
</>
1007+
) : (
1008+
// Show sidebar icon (sidebar with right arrow)
1009+
<>
1010+
<rect x="2" y="3" width="6" height="18" rx="1" stroke="currentColor" strokeWidth="1.5" fill="none" />
1011+
<rect x="10" y="3" width="12" height="18" rx="1" stroke="currentColor" strokeWidth="1.5" fill="none" />
1012+
<path d="M5 12L7 10M5 12L7 14M5 12H10" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
1013+
</>
1014+
)}
1015+
</svg>
1016+
</button>
1017+
1018+
{/* Sidebar */}
1019+
{sidebarVisible && (
1020+
<div style={{
1021+
width: 250,
1022+
height: '100%',
1023+
borderRight: '1px solid #ccc',
1024+
transition: 'width 0.3s ease'
1025+
}}>
1026+
<Sidebar />
1027+
</div>
1028+
)}
9631029

9641030
<GraphView
9651031
refEl={ref}

src/components/GraphView.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function FloatingButtons({
5757
<button
5858
style={{
5959
position: 'absolute',
60-
left: 20,
60+
left: 50,
6161
top: 70,
6262
zIndex: 10,
6363
padding: '8px 12px',
@@ -75,7 +75,7 @@ function FloatingButtons({
7575
<button
7676
style={{
7777
position: 'absolute',
78-
left: 20,
78+
left: 50,
7979
top: 120,
8080
zIndex: 10,
8181
padding: '8px 12px',
@@ -127,7 +127,7 @@ function FloatingButtons({
127127
<button
128128
style={{
129129
position: 'absolute',
130-
left: 20,
130+
left: 50,
131131
top: 20,
132132
zIndex: 10,
133133
padding: '8px 12px',

src/components/Sidebar.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ export default () => {
110110
cursor: 'grab',
111111
fontSize: '13px',
112112
transition: 'all 0.2s ease',
113-
display: 'block'
113+
display: 'flex',
114+
alignItems: 'center',
115+
justifyContent: 'space-between'
114116
}}
115117
onMouseEnter={(e) => {
116118
const currentBg = window.getComputedStyle(e.target).backgroundColor;
@@ -136,7 +138,13 @@ export default () => {
136138
e.target.style.cursor = 'grab';
137139
}}
138140
>
139-
{getNodeDisplayName(nodeType)}
141+
<span>{getNodeDisplayName(nodeType)}</span>
142+
<span style={{
143+
fontSize: '12px',
144+
color: '#888',
145+
}}>
146+
⋮⋮
147+
</span>
140148
</div>
141149
))}
142150
</div>

src/styles/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ aside .description {
300300
}
301301

302302
.dndnode {
303-
height: 50px;
303+
height: 15px;
304304
padding: 10px;
305305
border: 1px solid #78A083;
306306
border-radius: 5px;

0 commit comments

Comments
 (0)