forked from finos/architecture-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.tsx
More file actions
129 lines (124 loc) · 5.7 KB
/
Menu.tsx
File metadata and controls
129 lines (124 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import React, { useContext } from 'react';
import { ZoomContext } from '../zoom-context.provider.js';
interface MenuProps {
handleUpload: (instanceFile: File) => void;
isGraphRendered: boolean;
toggleConnectionDesc: () => void;
toggleNodeDesc: () => void;
isConDescActive?: boolean;
isNodeDescActive?: boolean;
}
export function Menu({
handleUpload,
isGraphRendered,
toggleConnectionDesc,
toggleNodeDesc,
isConDescActive,
isNodeDescActive,
}: MenuProps) {
const upload = (file: File) => {
handleUpload(file);
};
const { zoomLevel, updateZoom } = useContext(ZoomContext);
function zoomIn() {
//Obtain percentage as integer
const currentPercentageZoom = Math.round(zoomLevel * 100);
//Add 10% to the zoom or round to upper 10% interval
const newPercentageZoom = Math.floor(currentPercentageZoom / 10) * 10 + 10;
updateZoom(newPercentageZoom / 100);
}
function zoomOut() {
//Obtain percentage as integer
const currentPercentageZoom = Math.round(zoomLevel * 100);
//Subtract 10% from the zoom or round to lower 10% interval - but not less than zero
const newPercentageZoom = Math.max(Math.ceil(currentPercentageZoom / 10) * 10 - 10, 0);
updateZoom(newPercentageZoom / 100);
}
return (
<header className="bg-white shadow-xs">
<div className="mx-auto max-w-7xl flex justify-between items-center">
<div className="flex items-center space-x-4">
{isGraphRendered && (
<>
<label className="label cursor-pointer">
<span className="label label-text text-base-content">
Relationship Descriptions
</span>
<input
type="checkbox"
className="toggle"
name="connection-description"
aria-label="connection-description"
checked={isConDescActive}
onChange={toggleConnectionDesc}
/>
</label>
<label className="label cursor-pointer">
<span className="label label-text text-base-content">
Node Descriptions
</span>
<input
type="checkbox"
className="toggle"
aria-label="node-description"
checked={isNodeDescActive}
onChange={toggleNodeDesc}
/>
</label>
</>
)}
</div>
<div className="flex-1 flex justify-center">
{isGraphRendered && (
<div className="flex items-center space-x-4">
<div className="label">
<span className="label label-text text-base-content">
Zoom: {(zoomLevel * 100).toFixed(0)}%
</span>
<button
className={`btn btn-xs ms-1 ps-2 pe-2 ${zoomLevel >= 5 ? 'btn-disabled' : ''}`}
onClick={zoomIn}
disabled={zoomLevel >= 5}
>
+
</button>
<button
className={`btn btn-xs ms-1 ps-2 pe-2 ${zoomLevel <= 0.1 ? 'btn-disabled' : ''}`}
onClick={zoomOut}
disabled={zoomLevel <= 0.1}
>
-
</button>
</div>
</div>
)}
</div>
<div className="menu-end">
<ul className="menu menu-horizontal px-1" aria-label="navbar-menu-items">
<li>
<details>
<summary>Upload</summary>
<ul className="p-2 z-1" aria-label="upload-dropdown-items">
<li className="text-base-content">
<label>
Architecture
<input
id="file"
type="file"
aria-label="upload-architecture"
className="hidden"
onChange={(
e: React.ChangeEvent<HTMLInputElement>
) => e.target.files && upload(e.target.files[0])}
/>
</label>
</li>
</ul>
</details>
</li>
</ul>
</div>
</div>
</header>
);
}