1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-24 01:18:01 +02:00
unleash.unleash/frontend/src/component/common/Mermaid/Mermaid.tsx
Jaanus Sellin f3c01545f2
feat: application graph (#6279)
Basic graph, that works with mock data.
Next steps, work on backend and try to put more content and **styling to
nodes**.

![image](https://github.com/Unleash/unleash/assets/964450/545d6527-ecd8-4010-a0fe-8001bc8c1456)
2024-02-21 09:13:18 +02:00

60 lines
1.5 KiB
TypeScript

import { styled } from '@mui/material';
import mermaid from 'mermaid';
import { useRef, useEffect } from 'react';
const StyledMermaid = styled('div')(({ theme }) => ({
display: 'flex',
justifyContent: 'center',
'#mermaid': {
'.edgeLabel': {
backgroundColor: theme.palette.background.paper,
color: theme.palette.text.primary,
},
'.nodeLabel': {
color: theme.palette.secondary.dark,
},
'.edgePaths > path': {
stroke: theme.palette.secondary.dark,
},
'.arrowMarkerPath': {
fill: theme.palette.secondary.dark,
stroke: 'transparent',
},
},
'&&& #mermaid .node rect': {
stroke: theme.palette.secondary.border,
fill: theme.palette.secondary.light,
},
}));
mermaid.initialize({
startOnLoad: false,
theme: 'default',
securityLevel: 'loose',
themeCSS: `
.clusters #_ rect {
fill: transparent;
stroke: transparent;
}
`,
});
interface IMermaidProps {
children: string;
}
export const Mermaid = ({ children, ...props }: IMermaidProps) => {
const mermaidRef = useRef<HTMLDivElement>(null);
useEffect(() => {
mermaid.render('mermaid', children, (svgCode, bindFunctions) => {
if (mermaidRef.current) {
mermaidRef.current.innerHTML = svgCode;
bindFunctions?.(mermaidRef.current);
}
});
}, [children]);
return <StyledMermaid ref={mermaidRef} {...props} />;
};