Skip to content

Commit

Permalink
fix: update theme state provider
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Aug 2, 2020
1 parent f8c96f0 commit 6a95dd2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
9 changes: 2 additions & 7 deletions core/store/src/state/context/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import React, {
useState,
useEffect,
} from 'react';
import {
Store,
defaultStore,
PackageInfo,
RunConfiguration,
} from '@component-controls/core';
import { Store, defaultStore, PackageInfo } from '@component-controls/core';

interface StoreContextProps {
store: Store;
Expand Down Expand Up @@ -104,7 +99,7 @@ export const useThemeState = (): [
return [
config.theme,
theme => {
setConfig({ ...config, theme: theme || {} });
setConfig({ ...config, theme: theme || config.theme });
},
];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ tags:
- configuration
- theme
---
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import * as themes from '@theme-ui/presets';
import { ControlTypes } from '@component-controls/core';
import { useThemeState } from '@component-controls/store';
import { useStore, useThemeState } from '@component-controls/store';
import { Source } from '@component-controls/components';
import { Playground, Story, PropsTable } from '@component-controls/blocks';

Expand All @@ -25,13 +25,14 @@ You can use any [theme-ui](https://theme-ui.com) theme as a starting point for c

<Story name="select-theme" controls={{ theme: { type: ControlTypes.OPTIONS, options: ['none', ...Object.keys(themes)], value: 'none' }}}>
{({ theme: themeName }) => {
const [, setTheme] = useThemeState();

const store = useStore();
const [globalTheme, setGlobalTheme] = useThemeState();
const theme = themes[themeName] || store.config.theme;
useEffect(() => {
console.log(themeName);
setTheme(themes[themeName])
}, [themeName]);
const theme = themes[themeName];
if (globalTheme !== theme) {
setGlobalTheme(theme)
}
}, [theme]);
return (
<Source title=".config/runtime.js">
{`${themeName !== 'none' ? `import { ${themeName} } from '@theme-ui/presets';` : ''}
Expand Down
1 change: 0 additions & 1 deletion ui/blocks/src/ThemeProvider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ import { useTheme } from '@component-controls/store';

export const ThemeProvider: FC<Omit<ThemeProviderProps, 'theme'>> = props => {
const theme = useTheme();
console.log(theme);
return <ComponentsThemeProvider theme={theme} {...props} />;
};

0 comments on commit 6a95dd2

Please sign in to comment.