-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSidebar.tsx
More file actions
105 lines (99 loc) · 3.38 KB
/
Sidebar.tsx
File metadata and controls
105 lines (99 loc) · 3.38 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
import React from "react"
import {
ColorDescriptionConfig,
DROPS,
dropElementConfigs,
LAYOUT,
ZINDEX,
} from "@/constants"
import { DividerLine } from "./ui/DividerLine"
import { useMetadataStore } from "@/store/context"
import { useShallow } from "zustand/shallow"
import { DraggableGhost } from "./DraggableGhost"
/* ========================================================================
Sidebar Component
Renders the draggable elements based on the selected diagram type.
======================================================================== */
export const Sidebar = () => {
const diagramType = useMetadataStore(useShallow((state) => state.diagramType))
const labelPreviewTypes = new Set([
"sfcTransitionBranch",
"petriNetPlace",
"petriNetTransition",
])
if (dropElementConfigs[diagramType].length === 0) {
return null
}
return (
<aside
style={{
width: "180px",
minWidth: "180px",
height: "100%",
backgroundColor: "var(--apollon2-background)",
display: "flex",
flexDirection: "column",
padding: "10px",
gap: "15px",
alignItems: "center",
overflowY: "auto",
flexShrink: 0,
}}
>
{dropElementConfigs[diagramType].map((config, index) => {
const extraPreviewHeight =
labelPreviewTypes.has(config.type)
? LAYOUT.DEFAULT_ATTRIBUTE_HEIGHT
: 0
const previewScale = DROPS.SIDEBAR_PREVIEW_SCALE
const previewWidth = config.width * previewScale
const previewHeight = (config.height + extraPreviewHeight) * previewScale
return (
<React.Fragment key={`${config.type}_${config.defaultData?.name}`}>
<DraggableGhost dropElementConfig={config}>
<div
className="prevent-select"
style={{
width: previewWidth,
height: previewHeight,
zIndex: ZINDEX.DRAGGABLE_GHOST,
marginTop: config.marginTop,
}}
>
{React.createElement(config.svg, {
width: config.width,
height: config.height,
...config.defaultData,
data: config.defaultData,
SIDEBAR_PREVIEW_SCALE: previewScale,
id: `sidebarElement_${index}`,
})}
</div>
</DraggableGhost>
</React.Fragment>
)
})}
<DividerLine style={{ margin: "3px 0" }} />
<DraggableGhost dropElementConfig={ColorDescriptionConfig}>
<div
className="prevent-select"
style={{
width: ColorDescriptionConfig.width * DROPS.SIDEBAR_PREVIEW_SCALE,
height: ColorDescriptionConfig.height * DROPS.SIDEBAR_PREVIEW_SCALE,
zIndex: ZINDEX.DRAGGABLE_GHOST,
marginTop: ColorDescriptionConfig.marginTop,
}}
>
{React.createElement(ColorDescriptionConfig.svg, {
width: ColorDescriptionConfig.width,
height: ColorDescriptionConfig.height,
...ColorDescriptionConfig.defaultData,
data: ColorDescriptionConfig.defaultData,
SIDEBAR_PREVIEW_SCALE: DROPS.SIDEBAR_PREVIEW_SCALE,
id: "sidebarElement_ColorDescription",
})}
</div>
</DraggableGhost>
</aside>
)
}