Fix dark mode on storybook
This commit is contained in:
@@ -3,14 +3,19 @@ import '../styles/global.less';
|
|||||||
import '../styles/theme.less';
|
import '../styles/theme.less';
|
||||||
import '../stories/preview.scss';
|
import '../stories/preview.scss';
|
||||||
import { themes } from '@storybook/theming';
|
import { themes } from '@storybook/theming';
|
||||||
|
import { DocsContainer } from './storybook-theme';
|
||||||
|
|
||||||
export const parameters = {
|
export const parameters = {
|
||||||
actions: { argTypesRegex: '^on[A-Z].*' },
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
||||||
|
docs: {
|
||||||
|
container: DocsContainer,
|
||||||
|
},
|
||||||
controls: {
|
controls: {
|
||||||
matchers: {
|
matchers: {
|
||||||
color: /(background|color)$/i,
|
color: /(background|color)$/i,
|
||||||
date: /Date$/,
|
date: /Date$/,
|
||||||
},
|
},
|
||||||
|
viewMode: 'docs',
|
||||||
},
|
},
|
||||||
darkMode: {
|
darkMode: {
|
||||||
current: 'dark',
|
current: 'dark',
|
||||||
@@ -21,6 +26,7 @@ export const parameters = {
|
|||||||
brandImage: 'https://owncast.online/images/logo.svg',
|
brandImage: 'https://owncast.online/images/logo.svg',
|
||||||
brandTitle: 'Owncast',
|
brandTitle: 'Owncast',
|
||||||
brandUrl: 'https://owncast.online',
|
brandUrl: 'https://owncast.online',
|
||||||
|
appContentBg: '#171523',
|
||||||
},
|
},
|
||||||
// Override the default light theme
|
// Override the default light theme
|
||||||
light: { ...themes.normal },
|
light: { ...themes.normal },
|
||||||
|
|||||||
31
web/.storybook/storybook-theme.js
Normal file
31
web/.storybook/storybook-theme.js
Normal 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>
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user