Skip to content

Commit

Permalink
fix: force theme from props
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunvegda committed Apr 12, 2024
1 parent 4f713f8 commit ec11fe3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/DevTools/DevTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const theme = createTheme({
const DevToolsMain = ({
store,
isInitialOpen = false,
theme: userColorScheme = 'light',
theme: userColorScheme,
position = 'bottom-left',
nonce = '',
options,
Expand All @@ -79,19 +79,27 @@ const DevToolsMain = ({
setDevToolsOptions(options);
}, [setDevToolsOptions, options]);

const conditionalProps = React.useMemo(() => {
if (typeof userColorScheme === 'string') {
return { forceColorScheme: userColorScheme };
}
return {};
}, [userColorScheme]);

return (
<React.StrictMode>
<span id="jotai-devtools-root">
<MantineProvider
theme={theme}
colorSchemeManager={colorSchemeManager}
defaultColorScheme={userColorScheme}
defaultColorScheme="light"
classNamesPrefix="jotai-devtools"
withStaticClasses={false}
withGlobalClasses={false}
getRootElement={getRootElement}
cssVariablesSelector="#jotai-devtools-root"
getStyleNonce={() => nonce}
{...conditionalProps}
>
<Extension
store={store}
Expand Down
16 changes: 14 additions & 2 deletions src/stories/Default/Demos/DemoApp.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as React from 'react';
import { Grid, MantineProvider, Select, Text, Title } from '@mantine/core';
import {
Grid,
MantineProvider,
Select,

Check warning on line 5 in src/stories/Default/Demos/DemoApp.tsx

View workflow job for this annotation

GitHub Actions / build

'Select' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 5 in src/stories/Default/Demos/DemoApp.tsx

View workflow job for this annotation

GitHub Actions / build

'Select' is defined but never used. Allowed unused vars must match /^_/u
Text,
Title,
useComputedColorScheme,
} from '@mantine/core';
import { DevTools, DevToolsProps } from '../../../';
import { Async } from './Async';
import { Counter } from './Counter';
Expand All @@ -8,6 +15,11 @@ import { Random } from './Random';
import { ThemeToggle } from './ThemeToggle';
import { Todos } from './Todos';

const DevToolsWithColorScheme = (props: DevToolsProps) => {
const colorScheme = useComputedColorScheme();
return <DevTools store={demoStore} theme={colorScheme} {...props} />;
};

export const DemoApp = (props: DevToolsProps) => {
return (
<DemoJotaiStoreContext.Provider value={demoStore}>
Expand All @@ -17,7 +29,7 @@ export const DemoApp = (props: DevToolsProps) => {
cursorType: 'pointer',
}}
>
<DevTools store={demoStore} {...props} />
<DevToolsWithColorScheme {...props} />
<div className="App">
<ThemeToggle />
<React.Suspense
Expand Down

0 comments on commit ec11fe3

Please sign in to comment.