Skip to content

Commit

Permalink
refactor: split theme context into a file
Browse files Browse the repository at this point in the history
  • Loading branch information
marabesi committed Mar 4, 2024
1 parent 25b659d commit dc49b8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { createContext, useEffect, useState } from 'react';
import DefaultLayout from './components/ui/layout/Default';
import { editorOptions } from './components/ui/editor/default-options';
import { EditorOptions } from './types/components/Editor';
import { theme, ThemeProvider } from './DarkMode';

export const SettingsContext = createContext(editorOptions);

const isDarkModeSet = () => {
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
};

const theme = { darkMode: false };
export const ThemeContext = createContext(theme);

function App() {
const [savedState, setSavedState] = useState<string>('');
const [darkModeEnabled, setDarkMode] = useState<boolean>(theme.darkMode);
Expand All @@ -39,7 +37,7 @@ function App() {

return (
<Router>
<ThemeContext.Provider value={theme as never}>
<ThemeProvider value={theme as never}>
<DefaultLayout onDarkThemeChanged={onDarkThemeChanged} darkModeEnabled={darkModeEnabled}>
<Routes>
<Route path="/" element={<Editors onPersist={saveState} currentJson={savedState} />} />
Expand All @@ -50,7 +48,7 @@ function App() {
} />
</Routes>
</DefaultLayout>
</ThemeContext.Provider>
</ThemeProvider>
</Router>
);
}
Expand Down
7 changes: 7 additions & 0 deletions src/DarkMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createContext } from 'react';

export const theme = { darkMode: false };
export const ThemeContext = createContext(theme);

export const ThemeProvider = ThemeContext.Provider;

3 changes: 2 additions & 1 deletion src/components/ui/editor/JsonEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import CodeMirror, { BasicSetupOptions, ReactCodeMirrorRef } from '@uiw/react-codemirror';
import fullConfig from '../../../tailwindResolver';
import { json } from '@codemirror/lang-json';
import { SettingsContext, ThemeContext } from '../../../App';
import { SettingsContext } from '../../../App';
import { CSSProperties, ForwardedRef, forwardRef, useContext } from 'react';
import { Option, Properties } from '../../../types/components/Editor';
import { duotoneLight } from '@uiw/codemirror-theme-duotone';
import { ThemeContext } from '../../../DarkMode';

type Event = {
value: string;
Expand Down

0 comments on commit dc49b8f

Please sign in to comment.