diff --git a/packages/ui/src/components/SourceEditor.tsx b/packages/ui/src/components/SourceEditor.tsx index 33e8f9f..19b545e 100644 --- a/packages/ui/src/components/SourceEditor.tsx +++ b/packages/ui/src/components/SourceEditor.tsx @@ -28,6 +28,7 @@ export function SourceEditor({ onSave: (source: string, sourceType: SourceType) => void; }) { const [height, setHeight] = useState(0); + const [isDarkMode, setIsDarkMode] = useState(false); const [code, setCode] = useState(source); @@ -55,6 +56,31 @@ export function SourceEditor({ setCode(source); }, [source]); + useEffect(() => { + const observer = new MutationObserver((mutationList, observer) => { + for (const mutation of mutationList) { + if (mutation.type === "attributes") { + console.log(`The ${mutation.attributeName} attribute was modified.`); + if (mutation.attributeName === "class") { + setIsDarkMode( + (mutation.target as HTMLElement).classList.contains( + "pf-v6-theme-dark" + ) + ); + } + } + } + }); + observer.observe(document.getElementsByTagName("html")[0], { + attributes: true, + subtree: false, + childList: false, + }); + return () => { + observer.disconnect(); + }; + }, []); + const onEditorDidMount: CodeEditorProps["onEditorDidMount"] = (e) => { editorRef.current = e; }; @@ -137,6 +163,7 @@ export function SourceEditor({ height={`${height - 130}px`} onEditorDidMount={onEditorDidMount} emptyState={} + isDarkTheme={isDarkMode} code={code} /> )}