0

Fix dark mode on storybook

This commit is contained in:
Gabe Kangas 2022-05-17 14:23:52 -07:00
parent b6aa20b0aa
commit 8ce045aa9a
No known key found for this signature in database
GPG Key ID: 9A56337728BC81EA
2 changed files with 37 additions and 0 deletions

View File

@ -3,14 +3,19 @@ import '../styles/global.less';
import '../styles/theme.less';
import '../stories/preview.scss';
import { themes } from '@storybook/theming';
import { DocsContainer } from './storybook-theme';
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
docs: {
container: DocsContainer,
},
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
viewMode: 'docs',
},
darkMode: {
current: 'dark',
@ -21,6 +26,7 @@ export const parameters = {
brandImage: 'https://owncast.online/images/logo.svg',
brandTitle: 'Owncast',
brandUrl: 'https://owncast.online',
appContentBg: '#171523',
},
// Override the default light theme
light: { ...themes.normal },

View File

@ -0,0 +1,31 @@
import React from 'react';
import { DocsContainer as BaseContainer } from '@storybook/addon-docs/blocks';
import { useDarkMode } from 'storybook-dark-mode';
import { themes } from '@storybook/theming';
export const DocsContainer = ({ children, context }) => {
const dark = useDarkMode();
return (
<BaseContainer
context={{
...context,
storyById: id => {
const storyContext = context.storyById(id);
return {
...storyContext,
parameters: {
...storyContext?.parameters,
docs: {
...storyContext?.parameters?.docs,
theme: dark ? themes.dark : themes.light,
},
},
};
},
}}
>
{children}
</BaseContainer>
);
};