Skip to content

Commit

Permalink
Added support for dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thim81 committed Dec 20, 2024
1 parent e3c52d5 commit 757f99c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
29 changes: 15 additions & 14 deletions src/components/DiffEditorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ interface DiffEditorModalProps {
}

const DiffEditorModal: React.FC<DiffEditorModalProps> = ({ isOpen, onRequestClose, original, modified, language }) => {
const [theme, setTheme] = useState<'vs-light' | 'vs-dark'>(
window.matchMedia('(prefers-color-scheme: dark)').matches ? 'vs-dark' : 'vs-light'
);
const [theme, setTheme] = useState<'vs-light' | 'vs-dark'>('vs-light');

useEffect(() => {
// Listen for changes in system theme
const handleSystemThemeChange = (e: MediaQueryListEvent) => {
setTheme(e.matches ? 'vs-dark' : 'vs-light');
};
if (typeof window !== 'undefined' && window.matchMedia) {
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
setTheme(mediaQuery.matches ? 'vs-dark' : 'vs-light');

const handleSystemThemeChange = (e: MediaQueryListEvent) => {
setTheme(e.matches ? 'vs-dark' : 'vs-light');
};

const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
mediaQuery.addEventListener('change', handleSystemThemeChange);
mediaQuery.addEventListener('change', handleSystemThemeChange);

// Cleanup listener on unmount
return () => {
mediaQuery.removeEventListener('change', handleSystemThemeChange);
};
// Cleanup listener on unmount
return () => {
mediaQuery.removeEventListener('change', handleSystemThemeChange);
};
}
}, []);

const handleDiffEditorDidMount: DiffOnMount = (editor, monaco) => {
Expand All @@ -56,7 +57,7 @@ const DiffEditorModal: React.FC<DiffEditorModalProps> = ({ isOpen, onRequestClos
language={language || 'yaml'}
height="86vh"
options={editorOptions}
theme={theme} // Ensure the theme prop is passed correctly
theme={theme}
onMount={handleDiffEditorDidMount}
/>
</SimpleModal>
Expand Down
3 changes: 1 addition & 2 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
"./src/styles/**/*.{css}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}"
],
theme: {
extend: {
Expand Down

0 comments on commit 757f99c

Please sign in to comment.