aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/docs/app/components/mermaid.tsx
blob: 85ab342555b0c97f43e1f6f185b722bd58ed90b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use client";

import mermaid from "mermaid";
import { useEffect, useRef } from "react";

mermaid.initialize({
  startOnLoad: false,
  theme: "default",
});

export function Mermaid({ chart }: { chart: string }) {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (ref.current) {
      mermaid.run({
        nodes: [ref.current],
      });
    }
  }, []);

  return (
    <div className="not-prose my-6">
      <div ref={ref} className="mermaid">
        {chart}
      </div>
    </div>
  );
}