Skip to content

Commit

Permalink
fix the build
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed Nov 21, 2024
1 parent 54268f4 commit 08af9ad
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .changeset/fast-masks-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
34 changes: 34 additions & 0 deletions packages/libs/kode-ui/.storybook/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { DocsContainer } from '@storybook/addon-docs';
import { themes } from '@storybook/theming';
import React, { FC, useEffect, useState } from 'react';

export const ThemeProvider: FC = (props: any) => {
//const isDark = useDarkMode();
const [isDark, setIsDark] = useState(false);

useEffect(() => {
const key = 'sb-addon-themes-3';

const store = JSON.parse(localStorage.getItem(key) ?? '{}');
setIsDark(store.current === 'dark');

const listener = (event) => {
if (event.key !== key) return;
const values = JSON.parse(event.newValue ?? '{}');

setIsDark(values.current === 'dark');
};

addEventListener('storage', listener);

return () => {
removeEventListener('storage', listener);
};
}, []);

return (
<DocsContainer {...props} theme={isDark ? themes.dark : themes.light}>
{props.children}
</DocsContainer>
);
};
13 changes: 2 additions & 11 deletions packages/libs/kode-ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { DocsContainer } from '@storybook/addon-docs';
import { type Preview } from '@storybook/react';
import { themes } from '@storybook/theming';
import React from 'react';
import { useDarkMode } from 'storybook-dark-mode';
import { withCenteredStory } from '../src/storyDecorators';
import { darkThemeClass } from '../src/styles';
import { colorPalette } from '../src/styles/colors';
import '../src/styles/global.css';
import './global.css';
import { ThemeProvider } from './ThemeProvider';

const preview: Preview = {
parameters: {
Expand All @@ -19,7 +18,6 @@ const preview: Preview = {
},
darkMode: {
classTarget: 'html',
current: 'light',
// Override the default dark theme
dark: { ...themes.dark, appBg: colorPalette.$black },
darkClass: [darkThemeClass, 'dark-mode'],
Expand All @@ -31,14 +29,7 @@ const preview: Preview = {
},
docs: {
container: (context: any) => {
const isDark = useDarkMode();

const props = {
...context,
theme: isDark ? themes.dark : themes.light,
};

return React.createElement(DocsContainer, props);
return React.createElement(ThemeProvider, { ...context });
},
},
status: {
Expand Down

0 comments on commit 08af9ad

Please sign in to comment.