Skip to content

Commit

Permalink
adding theme state and component to main.tsx.
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantrawal committed Dec 6, 2023
1 parent 7739681 commit 773a6f5
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions demo/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,40 @@ import './index.scss';
import App from './App';
import { DEMOS_LIST } from './demos/list';
import '@itwin/itwinui-react/styles.css';
import { ThemeProvider } from '@itwin/itwinui-react';
import { ThemeProvider, ThemeType } from '@itwin/itwinui-react';
import { ThemeContext } from './common/ThemeContext';

export const CustomThemeProvider = ({
children,
}: {
children: React.ReactNode;
}) => {
const [theme, setTheme] = React.useState<ThemeType>(() =>
window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light',
);

return (
<ThemeContext.Provider value={{ theme, setTheme }}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</ThemeContext.Provider>
);
};

createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<HashRouter>
<ThemeProvider>
<ThemeContext.Provider>
<Routes>
<Route path='/' element={<App />} />
{DEMOS_LIST.map(({ layouts }) =>
layouts.map(({ path, component: Component }) => (
<Route key={path} path={path} element={<Component />} />
)),
)}
</Routes>
</ThemeContext.Provider>
</ThemeProvider>
<CustomThemeProvider>
<Routes>
<Route path='/' element={<App />} />
{DEMOS_LIST.map(({ layouts }) =>
layouts.map(({ path, component: Component }) => (
<Route key={path} path={path} element={<Component />} />
)),
)}
</Routes>
</CustomThemeProvider>
</HashRouter>
</React.StrictMode>,
);

0 comments on commit 773a6f5

Please sign in to comment.