File tree Expand file tree Collapse file tree 3 files changed +35
-30
lines changed Expand file tree Collapse file tree 3 files changed +35
-30
lines changed Load Diff This file was deleted.
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"
9
- import { ThemeChanger } from "./ThemeChanger "
8
+ import { withNextThemes } from "./withNextThemes "
10
9
11
10
import "@docsearch/css"
12
11
import "../src/styles/global.css"
@@ -30,21 +29,18 @@ const preview: Preview = {
30
29
locales : baseLocales ,
31
30
} ,
32
31
decorators : [
33
- withThemeByDataAttribute ( {
32
+ withNextThemes ( {
34
33
themes : {
35
34
light : "light" ,
36
35
dark : "dark" ,
37
36
} ,
38
37
defaultTheme : "light" ,
39
38
} ) ,
40
- ( Story , context ) => {
41
- return (
42
- < ThemeProvider >
43
- < ThemeChanger theme = { context . globals . theme } />
44
- < Story />
45
- </ ThemeProvider >
46
- )
47
- } ,
39
+ ( Story ) => (
40
+ < ThemeProvider >
41
+ < Story />
42
+ </ ThemeProvider >
43
+ ) ,
48
44
] ,
49
45
parameters : {
50
46
i18n,
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