Skip to content

Commit 37abbfe

Browse files
committed
Fix dark mode in graph
1 parent 9246c4e commit 37abbfe

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/components/graph/RelationsGraph.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { buildGraphForReferences, getLayoutedElements } from "@/components/graph
22
import {
33
Background,
44
BackgroundVariant,
5+
ColorMode,
56
Controls,
67
MiniMap,
78
NodeProps,
@@ -12,7 +13,7 @@ import {
1213
useReactFlow,
1314
useUpdateNodeInternals
1415
} from "@xyflow/react"
15-
import { ComponentType, useCallback, useEffect, useMemo, useRef } from "react"
16+
import { ComponentType, useCallback, useEffect, useMemo, useRef, useState } from "react"
1617
import "@xyflow/react/dist/style.css"
1718
import { ResultViewWrapper } from "@/components/graph/ResultViewWrapper"
1819
import { ResultViewProps } from "@elastic/react-search-ui-views"
@@ -23,6 +24,14 @@ import { RelationsGraphOptions } from "@/components/graph/RelationsGraphOptions"
2324
* Renders an interactive graph for the specified results. Results will be fetched from cache via PID. Currently intended for internal use only.
2425
*/
2526
export function RelationsGraph(props: { nodes: GraphNode[]; options?: RelationsGraphOptions; resultView: ComponentType<ResultViewProps> }) {
27+
const [colorMode, setColorMode] = useState<ColorMode>("system")
28+
29+
useEffect(() => {
30+
const dark = document.querySelector("html")?.classList.contains("dark")
31+
if (dark === true) setColorMode("dark")
32+
else setColorMode("light")
33+
}, [])
34+
2635
const { initialEdges, initialNodes } = useMemo(() => {
2736
return buildGraphForReferences(props.nodes)
2837
}, [props.nodes])
@@ -77,6 +86,7 @@ export function RelationsGraph(props: { nodes: GraphNode[]; options?: RelationsG
7786
onNodesChange={onNodesChange}
7887
onEdgesChange={onEdgesChange}
7988
proOptions={{ hideAttribution: true }}
89+
colorMode={colorMode}
8090
>
8191
<Background color="hsl(var(--rfs-border))" variant={BackgroundVariant.Lines} />
8292
<Controls />

0 commit comments

Comments
 (0)