Unverified Commit 94517490 authored by Query&mut NinjaStyle, &Ryder's avatar Query&mut NinjaStyle, &Ryder Committed by GitHub

fix: mermaid diagrams in dark mode (#4289)

* fix #4257 fixed ui for mermaid diagrams in dark mode

* fixed linting issues

* added dynamic color theme for mermaid diagrams

* now mermaid block uses theme according to the system as well when 'follow system' is selected

* refactored code for mermaid theme logic

* refactored mermaid code to use const instead of function call

---------
Co-authored-by: 's avatarroot <root@DESKTOP-G3MCU14>
parent d050a6fd
import { useColorScheme } from "@mui/joy";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
interface Props { interface Props {
...@@ -6,12 +7,15 @@ interface Props { ...@@ -6,12 +7,15 @@ interface Props {
const MermaidBlock: React.FC<Props> = ({ content }: Props) => { const MermaidBlock: React.FC<Props> = ({ content }: Props) => {
const mermaidDockBlock = useRef<null>(null); const mermaidDockBlock = useRef<null>(null);
const { mode } = useColorScheme();
const mermaidTheme = mode == "dark" ? "dark" : "default";
useEffect(() => { useEffect(() => {
// Dynamically import mermaid to ensure compatibility with Vite // Dynamically import mermaid to ensure compatibility with Vite
const initializeMermaid = async () => { const initializeMermaid = async () => {
const mermaid = (await import("mermaid")).default; const mermaid = (await import("mermaid")).default;
mermaid.initialize({ startOnLoad: false, theme: "default" }); mermaid.initialize({ startOnLoad: false, theme: mermaidTheme });
if (mermaidDockBlock.current) { if (mermaidDockBlock.current) {
mermaid.run({ mermaid.run({
nodes: [mermaidDockBlock.current], nodes: [mermaidDockBlock.current],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment