Skip to content

Commit

Permalink
chore: Broken dark mode in Storybook docs and canvasses (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored Aug 12, 2024
1 parent 450f099 commit 9b8c578
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 4 deletions.
25 changes: 25 additions & 0 deletions packages/fuselage-toastbar/.storybook/DocsContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DocsContainer as BaseContainer } from '@storybook/blocks';
import { addons } from '@storybook/preview-api';
import { themes } from '@storybook/theming';
import type { ComponentPropsWithoutRef } from 'react';
import { useEffect, useState } from 'react';
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';

const channel = addons.getChannel();

const DocsContainer = (
props: ComponentPropsWithoutRef<typeof BaseContainer>
) => {
const [isDark, setDark] = useState(false);

useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, setDark);
return () => channel.removeListener(DARK_MODE_EVENT_NAME, setDark);
}, [setDark]);

return (
<BaseContainer {...props} theme={isDark ? themes.dark : themes.light} />
);
};

export default DocsContainer;
10 changes: 10 additions & 0 deletions packages/fuselage-toastbar/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import surface from '@rocket.chat/fuselage-tokens/dist/surface.json';
import { DarkModeProvider } from '@rocket.chat/layout';
import type { Preview } from '@storybook/react';
import { themes } from '@storybook/theming';
Expand All @@ -6,6 +7,7 @@ import { useDarkMode } from 'storybook-dark-mode';

import manifest from '../package.json';
import ToastBarProvider from '../src/ToastBarProvider';
import DocsContainer from './DocsContainer';
import logo from './logo.svg';

import '@rocket.chat/fuselage/dist/fuselage.css';
Expand All @@ -21,6 +23,9 @@ export default {
opacity: 0.5,
},
},
docs: {
container: DocsContainer,
},
options: {
storySort: {
method: 'alphabetical',
Expand All @@ -29,12 +34,17 @@ export default {
darkMode: {
dark: {
...themes.dark,
appBg: surface.surface.dark.sidebar,
appContentBg: surface.surface.dark.light,
appPreviewBg: 'transparent',
barBg: surface.surface.dark.light,
brandTitle: manifest.name,
brandImage: logo,
brandUrl: manifest.homepage,
},
light: {
...themes.normal,
appPreviewBg: 'transparent',
brandTitle: manifest.name,
brandImage: logo,
brandUrl: manifest.homepage,
Expand Down
1 change: 1 addition & 0 deletions packages/fuselage-toastbar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@rocket.chat/eslint-config-alt": "workspace:~",
"@rocket.chat/fuselage": "workspace:~",
"@rocket.chat/fuselage-hooks": "workspace:~",
"@rocket.chat/fuselage-tokens": "workspace:~",
"@rocket.chat/layout": "workspace:~",
"@rocket.chat/prettier-config": "workspace:~",
"@rocket.chat/styled": "workspace:~",
Expand Down
25 changes: 25 additions & 0 deletions packages/fuselage/.storybook/DocsContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DocsContainer as BaseContainer } from '@storybook/blocks';
import { addons } from '@storybook/preview-api';
import { themes } from '@storybook/theming';
import type { ComponentPropsWithoutRef } from 'react';
import { useEffect, useState } from 'react';
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';

const channel = addons.getChannel();

const DocsContainer = (
props: ComponentPropsWithoutRef<typeof BaseContainer>
) => {
const [isDark, setDark] = useState(false);

useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, setDark);
return () => channel.removeListener(DARK_MODE_EVENT_NAME, setDark);
}, [setDark]);

return (
<BaseContainer {...props} theme={isDark ? themes.dark : themes.light} />
);
};

export default DocsContainer;
14 changes: 10 additions & 4 deletions packages/fuselage/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import breakpointTokens from '@rocket.chat/fuselage-tokens/breakpoints.json';
import surface from '@rocket.chat/fuselage-tokens/dist/surface.json';
import type { Preview } from '@storybook/react';
import { themes } from '@storybook/theming';
import { useDarkMode } from 'storybook-dark-mode';

import manifest from '../package.json';
import { PaletteStyleTag } from '../src';
import { surface } from './helpers';
import DocsContainer from './DocsContainer';
import logo from './logo.svg';

import 'normalize.css/normalize.css';
Expand All @@ -21,6 +22,9 @@ export default {
opacity: 0.5,
},
},
docs: {
container: DocsContainer,
},
options: {
storySort: {
order: [
Expand Down Expand Up @@ -54,15 +58,17 @@ export default {
darkMode: {
dark: {
...themes.dark,
appBg: surface.sidebar,
appContentBg: surface.main,
barBg: surface.main,
appBg: surface.surface.dark.sidebar,
appContentBg: surface.surface.dark.light,
appPreviewBg: 'transparent',
barBg: surface.surface.dark.light,
brandTitle: manifest.name,
brandImage: logo,
brandUrl: manifest.homepage,
},
light: {
...themes.normal,
appPreviewBg: 'transparent',
brandTitle: manifest.name,
brandImage: logo,
brandUrl: manifest.homepage,
Expand Down
25 changes: 25 additions & 0 deletions packages/layout/.storybook/DocsContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DocsContainer as BaseContainer } from '@storybook/blocks';
import { addons } from '@storybook/preview-api';
import { themes } from '@storybook/theming';
import type { ComponentPropsWithoutRef } from 'react';
import { useEffect, useState } from 'react';
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';

const channel = addons.getChannel();

const DocsContainer = (
props: ComponentPropsWithoutRef<typeof BaseContainer>
) => {
const [isDark, setDark] = useState(false);

useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, setDark);
return () => channel.removeListener(DARK_MODE_EVENT_NAME, setDark);
}, [setDark]);

return (
<BaseContainer {...props} theme={isDark ? themes.dark : themes.light} />
);
};

export default DocsContainer;
10 changes: 10 additions & 0 deletions packages/layout/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import surface from '@rocket.chat/fuselage-tokens/dist/surface.json';
import type { Preview } from '@storybook/react';
import { themes } from '@storybook/theming';
import { Suspense } from 'react';
import { useDarkMode } from 'storybook-dark-mode';

import manifest from '../package.json';
import DarkModeProvider from '../src/DarkModeProvider';
import DocsContainer from './DocsContainer';
import logo from './logo.svg';

import '@rocket.chat/fuselage/dist/fuselage.css';
Expand All @@ -20,6 +22,9 @@ export default {
opacity: 0.5,
},
},
docs: {
container: DocsContainer,
},
options: {
storySort: {
method: 'alphabetical',
Expand All @@ -29,12 +34,17 @@ export default {
darkMode: {
dark: {
...themes.dark,
appBg: surface.surface.dark.sidebar,
appContentBg: surface.surface.dark.light,
appPreviewBg: 'transparent',
barBg: surface.surface.dark.light,
brandTitle: manifest.name,
brandImage: logo,
brandUrl: manifest.homepage,
},
light: {
...themes.normal,
appPreviewBg: 'transparent',
brandTitle: manifest.name,
brandImage: logo,
brandUrl: manifest.homepage,
Expand Down
1 change: 1 addition & 0 deletions packages/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"devDependencies": {
"@rocket.chat/eslint-config-alt": "workspace:~",
"@rocket.chat/fuselage": "workspace:~",
"@rocket.chat/fuselage-tokens": "workspace:~",
"@rocket.chat/prettier-config": "workspace:~",
"@storybook/addon-essentials": "~8.2.7",
"@storybook/addon-webpack5-compiler-swc": "~1.0.5",
Expand Down
25 changes: 25 additions & 0 deletions packages/onboarding-ui/.storybook/DocsContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DocsContainer as BaseContainer } from '@storybook/blocks';
import { addons } from '@storybook/preview-api';
import { themes } from '@storybook/theming';
import type { ComponentPropsWithoutRef } from 'react';
import { useEffect, useState } from 'react';
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';

const channel = addons.getChannel();

const DocsContainer = (
props: ComponentPropsWithoutRef<typeof BaseContainer>
) => {
const [isDark, setDark] = useState(false);

useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, setDark);
return () => channel.removeListener(DARK_MODE_EVENT_NAME, setDark);
}, [setDark]);

return (
<BaseContainer {...props} theme={isDark ? themes.dark : themes.light} />
);
};

export default DocsContainer;
10 changes: 10 additions & 0 deletions packages/onboarding-ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import surface from '@rocket.chat/fuselage-tokens/dist/surface.json';
import { DarkModeProvider } from '@rocket.chat/layout';
import type { Preview } from '@storybook/react';
import { themes } from '@storybook/theming';
Expand All @@ -7,6 +8,7 @@ import { I18nextProvider, initReactI18next } from 'react-i18next';
import { useDarkMode } from 'storybook-dark-mode';

import manifest from '../package.json';
import DocsContainer from './DocsContainer';
import logo from './logo.svg';

import '@rocket.chat/fuselage/dist/fuselage.css';
Expand Down Expand Up @@ -40,6 +42,9 @@ export default {
opacity: 0.5,
},
},
docs: {
container: DocsContainer,
},
options: {
storySort: {
method: 'alphabetical',
Expand All @@ -48,12 +53,17 @@ export default {
darkMode: {
dark: {
...themes.dark,
appBg: surface.surface.dark.sidebar,
appContentBg: surface.surface.dark.light,
appPreviewBg: 'transparent',
barBg: surface.surface.dark.light,
brandTitle: manifest.name,
brandImage: logo,
brandUrl: manifest.homepage,
},
light: {
...themes.normal,
appPreviewBg: 'transparent',
brandTitle: manifest.name,
brandImage: logo,
brandUrl: manifest.homepage,
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4568,6 +4568,7 @@ __metadata:
"@rocket.chat/eslint-config-alt": "workspace:~"
"@rocket.chat/fuselage": "workspace:~"
"@rocket.chat/fuselage-hooks": "workspace:~"
"@rocket.chat/fuselage-tokens": "workspace:~"
"@rocket.chat/layout": "workspace:~"
"@rocket.chat/prettier-config": "workspace:~"
"@rocket.chat/styled": "workspace:~"
Expand Down Expand Up @@ -4758,6 +4759,7 @@ __metadata:
dependencies:
"@rocket.chat/eslint-config-alt": "workspace:~"
"@rocket.chat/fuselage": "workspace:~"
"@rocket.chat/fuselage-tokens": "workspace:~"
"@rocket.chat/prettier-config": "workspace:~"
"@storybook/addon-essentials": "npm:~8.2.7"
"@storybook/addon-webpack5-compiler-swc": "npm:~1.0.5"
Expand Down

0 comments on commit 9b8c578

Please sign in to comment.