Skip to content

Commit 17c42ba

Browse files
author
Bryce Rothhammer
committed
Add theme toggle to component stories
1 parent e5710ff commit 17c42ba

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

packages/web-components/.storybook/preview.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,6 @@ export const parameters = {
5050
a11y: {
5151
element: '#root',
5252
},
53-
globalTypes: {
54-
theme: {
55-
description: 'Global theme for components',
56-
toolbar: {
57-
// The label to show for this toolbar item
58-
title: 'Theme',
59-
icon: 'circlehollow',
60-
// Array of plain string values or MenuItem shape (see below)
61-
items: ['light', 'dark'],
62-
// Change title based on selected value
63-
dynamicTitle: true,
64-
},
65-
},
66-
},
67-
initialGlobals: {
68-
theme: 'dark',
69-
},
70-
themes: {
71-
default: 'Dark Theme',
72-
list: [
73-
{ name: 'Light Theme', class: 'light-theme', color: '#eceff4' },
74-
{ name: 'Dark Theme', class: 'dark-theme', color: '#192635' },
75-
],
76-
},
7753
readme: {
7854
codeTheme: 'duotone-sea',
7955
theme: {
@@ -109,4 +85,32 @@ export const parameters = {
10985
},
11086
},
11187
}
112-
export const tags = ['autodocs'];
88+
89+
export const tags = ['autodocs']
90+
91+
export const globalTypes = {
92+
theme: {
93+
name: 'Theme',
94+
description: 'Global theme for components',
95+
defaultValue: 'dark',
96+
toolbar: {
97+
icon: 'circlehollow',
98+
items: [
99+
{ value: 'light', icon: 'sun', title: 'Light Theme' },
100+
{ value: 'dark', icon: 'moon', title: 'Dark Theme' },
101+
],
102+
showName: true,
103+
},
104+
},
105+
}
106+
107+
// Add a decorator to apply the theme class
108+
export const decorators = [
109+
(Story, context) => {
110+
// Apply the selected theme class
111+
const theme = context.globals.theme
112+
document.body.className =
113+
theme === 'light' ? 'light-theme' : 'dark-theme'
114+
return Story()
115+
},
116+
]

0 commit comments

Comments
 (0)