File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 1
1
import isChromatic from "chromatic/isChromatic"
2
2
import { MotionGlobalConfig } from "framer-motion"
3
- import { withThemeByDataAttribute } from "@storybook/addon-themes"
4
3
import type { Preview } from "@storybook/react"
5
4
6
5
import ThemeProvider from "@/components/ThemeProvider"
7
6
8
7
import i18n , { baseLocales } from "./i18next"
8
+ import { withNextThemes } from "./withNextThemes"
9
9
10
10
import "@docsearch/css"
11
11
import "../src/styles/global.css"
@@ -29,7 +29,7 @@ const preview: Preview = {
29
29
locales : baseLocales ,
30
30
} ,
31
31
decorators : [
32
- withThemeByDataAttribute ( {
32
+ withNextThemes ( {
33
33
themes : {
34
34
light : "light" ,
35
35
dark : "dark" ,
Original file line number Diff line number Diff line change
1
+ import { useEffect } from "react"
2
+ import { useTheme } from "next-themes"
3
+ import {
4
+ type DataAttributeStrategyConfiguration ,
5
+ DecoratorHelpers ,
6
+ } from "@storybook/addon-themes"
7
+ import type { Decorator } from "@storybook/react/*"
8
+
9
+ const { initializeThemeState, pluckThemeFromContext } = DecoratorHelpers
10
+
11
+ export const withNextThemes = ( {
12
+ themes,
13
+ defaultTheme,
14
+ } : DataAttributeStrategyConfiguration ) : Decorator => {
15
+ initializeThemeState ( Object . keys ( themes ) , defaultTheme )
16
+
17
+ return ( getStory , context ) => {
18
+ const selectedTheme = pluckThemeFromContext ( context )
19
+ const selected = selectedTheme || defaultTheme
20
+ const { setTheme } = useTheme ( )
21
+
22
+ useEffect ( ( ) => {
23
+ setTheme ( selected )
24
+ } , [ selected , setTheme ] )
25
+
26
+ return getStory ( context )
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments