mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix: set mermaid theme based on computed color scheme (#1438)
This commit is contained in:
committed by
GitHub
parent
74cd890bdd
commit
242fb6bb57
@@ -4,11 +4,7 @@ import mermaid from "mermaid";
|
|||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import classes from "./code-block.module.css";
|
import classes from "./code-block.module.css";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useComputedColorScheme } from "@mantine/core";
|
||||||
mermaid.initialize({
|
|
||||||
startOnLoad: false,
|
|
||||||
suppressErrorRendering: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
interface MermaidViewProps {
|
interface MermaidViewProps {
|
||||||
props: NodeViewProps;
|
props: NodeViewProps;
|
||||||
@@ -16,12 +12,22 @@ interface MermaidViewProps {
|
|||||||
|
|
||||||
export default function MermaidView({ props }: MermaidViewProps) {
|
export default function MermaidView({ props }: MermaidViewProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const computedColorScheme = useComputedColorScheme();
|
||||||
const { node } = props;
|
const { node } = props;
|
||||||
const [preview, setPreview] = useState<string>("");
|
const [preview, setPreview] = useState<string>("");
|
||||||
|
|
||||||
|
// Update Mermaid config when theme changes.
|
||||||
|
useEffect(() => {
|
||||||
|
mermaid.initialize({
|
||||||
|
startOnLoad: false,
|
||||||
|
suppressErrorRendering: true,
|
||||||
|
theme: computedColorScheme === "light" ? "default" : "dark",
|
||||||
|
});
|
||||||
|
}, [computedColorScheme]);
|
||||||
|
|
||||||
|
// Re-render the diagram whenever the node content or theme changes.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const id = `mermaid-${uuidv4()}`;
|
const id = `mermaid-${uuidv4()}`;
|
||||||
|
|
||||||
if (node.textContent.length > 0) {
|
if (node.textContent.length > 0) {
|
||||||
mermaid
|
mermaid
|
||||||
.render(id, node.textContent)
|
.render(id, node.textContent)
|
||||||
@@ -40,7 +46,7 @@ export default function MermaidView({ props }: MermaidViewProps) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [node.textContent]);
|
}, [node.textContent, computedColorScheme]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user