diff options
Diffstat (limited to 'packages/docs/app/components/mermaid.tsx')
| -rw-r--r-- | packages/docs/app/components/mermaid.tsx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/docs/app/components/mermaid.tsx b/packages/docs/app/components/mermaid.tsx new file mode 100644 index 0000000..bb25f2d --- /dev/null +++ b/packages/docs/app/components/mermaid.tsx @@ -0,0 +1,29 @@ +'use client'; + +import { useEffect, useRef } from 'react'; +import mermaid from 'mermaid'; + +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], + }); + } + }, [chart]); + + return ( + <div className="not-prose my-6"> + <div ref={ref} className="mermaid"> + {chart} + </div> + </div> + ); +} |