-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from ls1intum/26-show-class-component
- Loading branch information
Showing
21 changed files
with
901 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from "react" | ||
|
||
type Props = { | ||
children: React.ReactNode | ||
fill?: string | ||
x?: string | number | ||
y?: string | number | ||
dominantBaseline?: string | ||
textAnchor?: string | ||
fontWeight?: string | ||
pointerEvents?: string | ||
noX?: boolean | ||
noY?: boolean | ||
} | ||
|
||
export const Text: React.FC<Props & Record<string, unknown>> = ({ | ||
children, | ||
fill, | ||
x = "50%", | ||
y = "50%", | ||
dominantBaseline = "middle", | ||
textAnchor = "middle", | ||
fontWeight = "bold", | ||
pointerEvents = "none", | ||
noX = false, | ||
noY = false, | ||
...props | ||
}: Props) => { | ||
const pos: { x?: string | number; y?: string | number } = {} | ||
if (!noX) { | ||
pos.x = x | ||
} | ||
if (!noY) { | ||
pos.y = y | ||
} | ||
return ( | ||
<text | ||
{...pos} | ||
style={fill ? { fill } : {}} | ||
dominantBaseline={dominantBaseline} | ||
textAnchor={textAnchor} | ||
fontWeight={fontWeight} | ||
pointerEvents={pointerEvents} | ||
{...props} | ||
> | ||
{children} | ||
</text> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import baseStyled from "styled-components" | ||
|
||
// Default Colors | ||
const defaultStrokeColor = "black" | ||
const defaultFillColor = "white" | ||
const defaultPrimaryContrast = "#ffffff" // Example: white | ||
const defaultBackground = "#000000" // Example: black | ||
|
||
// Themed Polyline | ||
export const ThemedPolyline = baseStyled.polyline.attrs( | ||
(props: { fillColor?: string; strokeColor?: string }) => ({ | ||
fillColor: props.fillColor || defaultFillColor, | ||
strokeColor: props.strokeColor || defaultStrokeColor, | ||
stroke: props.strokeColor || defaultStrokeColor, | ||
fill: props.fillColor || defaultFillColor, | ||
}) | ||
)` | ||
fill: ${(props) => props.fillColor || defaultBackground}; | ||
stroke: ${(props) => props.strokeColor || defaultPrimaryContrast}; | ||
` | ||
|
||
// Themed Path | ||
export const ThemedPath = baseStyled.path.attrs( | ||
(props: { fillColor?: string; strokeColor?: string }) => ({ | ||
fillColor: props.fillColor || defaultFillColor, | ||
strokeColor: props.strokeColor || defaultStrokeColor, | ||
stroke: props.strokeColor || defaultStrokeColor, | ||
fill: props.fillColor || defaultFillColor, | ||
}) | ||
)` | ||
fill: ${(props) => props.fillColor || defaultBackground}; | ||
stroke: ${(props) => props.strokeColor || defaultPrimaryContrast}; | ||
` | ||
|
||
// Themed Path Contrast | ||
export const ThemedPathContrast = baseStyled.path.attrs( | ||
(props: { fillColor?: string; strokeColor?: string }) => ({ | ||
fillColor: props.fillColor || defaultBackground, | ||
strokeColor: props.strokeColor || defaultPrimaryContrast, | ||
stroke: props.strokeColor || defaultPrimaryContrast, | ||
fill: props.fillColor || defaultBackground, | ||
}) | ||
)` | ||
fill: ${(props) => props.fillColor || defaultPrimaryContrast}; | ||
stroke: ${(props) => props.strokeColor || defaultBackground}; | ||
` | ||
|
||
// Themed Rect | ||
export const ThemedRect = baseStyled.rect.attrs( | ||
(props: { fillColor?: string; strokeColor?: string }) => ({ | ||
fillColor: props.fillColor || defaultFillColor, | ||
strokeColor: props.strokeColor || defaultStrokeColor, | ||
stroke: props.strokeColor || defaultStrokeColor, | ||
fill: props.fillColor || defaultFillColor, | ||
}) | ||
)` | ||
fill: ${(props) => props.fillColor || defaultBackground}; | ||
stroke: ${(props) => props.strokeColor || defaultPrimaryContrast}; | ||
` | ||
|
||
// Themed Rect Contrast | ||
export const ThemedRectContrast = baseStyled.rect.attrs( | ||
(props: { fillColor?: string; strokeColor?: string }) => ({ | ||
fillColor: props.fillColor || defaultBackground, | ||
strokeColor: props.strokeColor || defaultPrimaryContrast, | ||
stroke: props.strokeColor || defaultPrimaryContrast, | ||
fill: props.fillColor || defaultBackground, | ||
}) | ||
)` | ||
fill: ${(props) => props.fillColor || defaultPrimaryContrast}; | ||
stroke: ${(props) => props.strokeColor || defaultBackground}; | ||
` | ||
|
||
// Themed Circle | ||
export const ThemedCircle = baseStyled.circle.attrs( | ||
(props: { fillColor?: string; strokeColor?: string }) => ({ | ||
fillColor: props.fillColor || defaultFillColor, | ||
strokeColor: props.strokeColor || defaultStrokeColor, | ||
stroke: props.strokeColor || defaultStrokeColor, | ||
fill: props.fillColor || defaultFillColor, | ||
}) | ||
)` | ||
fill: ${(props) => props.fillColor || defaultBackground}; | ||
stroke: ${(props) => props.strokeColor || defaultPrimaryContrast}; | ||
` | ||
|
||
// Themed Circle Contrast | ||
export const ThemedCircleContrast = baseStyled.circle.attrs( | ||
(props: { fillColor?: string; strokeColor?: string }) => ({ | ||
fillColor: props.fillColor || defaultBackground, | ||
strokeColor: props.strokeColor || defaultPrimaryContrast, | ||
stroke: props.strokeColor || defaultPrimaryContrast, | ||
fill: props.fillColor || defaultBackground, | ||
}) | ||
)` | ||
fill: ${(props) => props.fillColor || defaultPrimaryContrast}; | ||
stroke: ${(props) => props.strokeColor || defaultBackground}; | ||
` | ||
|
||
// Themed Ellipse | ||
export const ThemedEllipse = baseStyled.ellipse.attrs( | ||
(props: { fillColor?: string; strokeColor?: string }) => ({ | ||
fillColor: props.fillColor || defaultFillColor, | ||
strokeColor: props.strokeColor || defaultStrokeColor, | ||
stroke: props.strokeColor || defaultStrokeColor, | ||
fill: props.fillColor || defaultFillColor, | ||
}) | ||
)` | ||
fill: ${(props) => props.fillColor || defaultBackground}; | ||
stroke: ${(props) => props.strokeColor || defaultPrimaryContrast}; | ||
` | ||
|
||
// Themed Line | ||
export const ThemedLine = baseStyled.line.attrs( | ||
(props: { strokeColor?: string }) => ({ | ||
strokeColor: props.strokeColor || defaultStrokeColor, | ||
stroke: props.strokeColor || defaultStrokeColor, | ||
}) | ||
)` | ||
stroke: ${(props) => props.strokeColor || defaultPrimaryContrast}; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./Text" | ||
export * from "./ThemedElements" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { type Edge, type Node } from "@xyflow/react" | ||
|
||
export const defaultNodes: Node[] = [ | ||
{ | ||
id: "1", | ||
type: "package", | ||
position: { x: -100, y: 200 }, | ||
width: 200, | ||
height: 200, | ||
selected: false, | ||
data: { name: "Package" }, | ||
}, | ||
{ | ||
id: "2", | ||
type: "class", | ||
position: { x: 400, y: -100 }, | ||
width: 296, | ||
height: 170, | ||
selected: false, | ||
data: { | ||
name: "Class", | ||
methods: [ | ||
{ id: "1", name: "method1" }, | ||
{ id: "2", name: "method2" }, | ||
], | ||
attributes: [ | ||
{ id: "1", name: "attribute1" }, | ||
{ id: "2", name: "attribute2" }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: "3", | ||
type: "class", | ||
position: { x: 400, y: 100 }, | ||
width: 296, | ||
height: 170, | ||
selected: false, | ||
data: { | ||
stereotype: "abstract", | ||
name: "AbstractClass", | ||
methods: [ | ||
{ id: "1", name: "method1" }, | ||
{ id: "2", name: "method2" }, | ||
], | ||
attributes: [ | ||
{ id: "1", name: "attribute1" }, | ||
{ id: "2", name: "attribute2" }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: "4", | ||
type: "class", | ||
position: { x: 400, y: 300 }, | ||
width: 296, | ||
height: 170, | ||
selected: false, | ||
data: { | ||
name: "InterfaceClass", | ||
stereotype: "interface", | ||
methods: [ | ||
{ id: "1", name: "method1" }, | ||
{ id: "2", name: "method2" }, | ||
], | ||
attributes: [ | ||
{ id: "1", name: "attribute1" }, | ||
{ id: "2", name: "attribute2" }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: "5", | ||
type: "class", | ||
position: { x: 400, y: 500 }, | ||
width: 296, | ||
height: 170, | ||
selected: false, | ||
data: { | ||
name: "EnumerationClass", | ||
stereotype: "enumaration", | ||
methods: [ | ||
{ id: "1", name: "method1" }, | ||
{ id: "2", name: "method2" }, | ||
], | ||
attributes: [ | ||
{ id: "1", name: "attribute1" }, | ||
{ id: "2", name: "attribute2" }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: "6", | ||
type: "colorDescription", | ||
position: { x: -100, y: 600 }, | ||
width: 160, | ||
height: 50, | ||
selected: false, | ||
data: { | ||
description: "Color description", | ||
}, | ||
}, | ||
] | ||
|
||
export const defaultEdges: Edge[] = [ | ||
{ | ||
id: "1->2", | ||
source: "1", | ||
target: "2", | ||
sourceHandle: "right", | ||
targetHandle: "left", | ||
}, | ||
{ | ||
id: "2->3", | ||
source: "2", | ||
target: "3", | ||
sourceHandle: "bottom", | ||
targetHandle: "top", | ||
}, | ||
{ | ||
id: "2->4", | ||
source: "2", | ||
target: "4", | ||
sourceHandle: "right", | ||
targetHandle: "right", | ||
}, | ||
{ | ||
id: "5->3", | ||
source: "5", | ||
target: "3", | ||
sourceHandle: "left", | ||
targetHandle: "left", | ||
}, | ||
] |
Oops, something went wrong.