1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/common/Mermaid/Mermaid.tsx

44 lines
1.0 KiB
TypeScript
Raw Normal View History

import { styled } from '@mui/material';
import mermaid from 'mermaid';
import { useEffect } from 'react';
const StyledMermaid = styled('div')(({ theme }) => ({
display: 'flex',
justifyContent: 'center',
'#mermaid .edgeLabel': {
backgroundColor: theme.palette.background.paper,
},
}));
mermaid.initialize({
theme: 'default',
themeCSS: `
.clusters #_ rect {
fill: transparent;
stroke: transparent;
}
`,
});
interface IMermaidProps {
className?: string;
children: string;
}
export const Mermaid = ({ className = '', children }: IMermaidProps) => {
useEffect(() => {
mermaid.render('mermaid', children, (svgCode: string) => {
const mermaidDiv = document.querySelector('.mermaid');
if (mermaidDiv) {
mermaidDiv.innerHTML = svgCode;
}
});
}, [children]);
return (
<StyledMermaid className={`mermaid ${className}`}>
{children}
</StyledMermaid>
);
};