|
1 | 1 | import type { Theme } from '@mui/material' |
2 | 2 | import { |
3 | | - createTheme, |
4 | | - Stack, ThemeProvider, useColorScheme, useTheme |
| 3 | + createTheme, CssBaseline, |
| 4 | + ThemeProvider, useColorScheme, useTheme |
5 | 5 | } from '@mui/material' |
6 | 6 | import type { Decorator } from '@storybook/react-vite' |
7 | 7 | import { |
8 | 8 | DataismTheme, XyLabsTheme, XyosTheme, XyoTheme, |
9 | 9 | } from '@xylabs/react-theme' |
10 | | -import React, { useEffect } from 'react' |
| 10 | +import React, { useEffect, useLayoutEffect } from 'react' |
11 | 11 |
|
12 | 12 | const themeNames = ['None', 'XYO', 'Dataism', 'XYLabs', 'xyOS'] as const |
13 | 13 | type ThemeName = typeof themeNames[number] |
@@ -79,21 +79,28 @@ const withThemeProvider: Decorator = (Story, context) => { |
79 | 79 | const themeOptions = getTheme(context.globals.theme) |
80 | 80 | const theme = themeOptions |
81 | 81 |
|
| 82 | + // SB does not adjust the background color based off the color scheme, so we need to do it manually |
| 83 | + useLayoutEffect(() => { |
| 84 | + const body = document.getElementsByTagName('body')[0] |
| 85 | + if (body) { |
| 86 | + body.style.backgroundColor = themeOptions.vars?.palette?.background?.paper || 'transparent' |
| 87 | + } |
| 88 | + }, [themeOptions]) |
| 89 | + |
82 | 90 | return ( |
83 | | - <ThemeProvider theme={theme}> |
84 | | - <Stack alignItems="stretch"> |
| 91 | + <ThemeProvider theme={theme} defaultMode={'dark'}> |
| 92 | + <CssBaseline enableColorScheme /> |
85 | 93 | <Story {...context} /> |
86 | | - </Stack> |
87 | 94 | </ThemeProvider> |
88 | 95 | ) |
89 | 96 | } |
90 | 97 |
|
91 | 98 | const withModeSelector: Decorator = (Story, context) => { |
92 | 99 | const { mode } = context.globals |
93 | | - const { setMode: setMuiMode } = useColorScheme() |
| 100 | + const { setMode } = useColorScheme() |
94 | 101 |
|
95 | 102 | useEffect(() => { |
96 | | - setMuiMode(mode) |
| 103 | + setMode(mode) |
97 | 104 | }, [mode]) |
98 | 105 |
|
99 | 106 | return <Story {...context} /> |
|
0 commit comments