Skip to content

Commit ea51c3c

Browse files
authored
storybook-dark-theme-toogle (#10168)
* feat(storybook): add theme toolbar and decorator to toggle dark mode * chore(ui remove emoji from select option labels to improve accessibility and consistency
1 parent fa8944f commit ea51c3c

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

packages/ui/.storybook/preview.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,39 @@ const preview: Preview = {
1515
},
1616
docs: {
1717
autodocs: 'tag'
18-
},
19-
darkMode: {
20-
classTarget: 'html',
21-
stylePreview: true,
22-
dark: {
23-
appPreviewBg: '#272321'
24-
},
25-
light: {
26-
appPreviewBg: '#fff'
18+
}
19+
},
20+
globalTypes: {
21+
theme: {
22+
name: 'Theme',
23+
description: 'Toggle between light and dark theme',
24+
defaultValue: 'light',
25+
toolbar: {
26+
icon: 'contrast',
27+
items: [
28+
{ value: 'light', title: 'Light mode', icon: 'sun' },
29+
{ value: 'dark', title: 'Dark mode', icon: 'moon' }
30+
],
31+
showName: false,
32+
dynamicTitle: true
33+
}
34+
}
35+
},
36+
decorators: [
37+
(Story, context) => {
38+
const theme = context.globals.theme || 'light';
39+
if (typeof document !== 'undefined') {
40+
const htmlElement = document.documentElement;
41+
42+
if (theme === 'dark') {
43+
htmlElement.classList.add('dark');
44+
} else {
45+
htmlElement.classList.remove('dark');
46+
}
2747
}
48+
return Story();
2849
}
29-
}
50+
]
3051
};
3152

3253
export default preview;

packages/ui/.storybook/stories-styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
body {
2+
background-color: var(--clr-bg-1);
23
color: var(--clr-text-1);
34
}
45

packages/ui/src/stories/components/Select.stories.svelte

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@
5959
{ value: '8', label: 'Final long option to complete the test suite for overflow behavior' }
6060
],
6161
optionsWithSeparators: [
62-
{ value: 'new', label: '📄 New Document' },
63-
{ value: 'open', label: '📂 Open Document' },
64-
{ value: 'recent', label: '🕐 Recent Documents' },
62+
{ value: 'new', label: 'New Document' },
63+
{ value: 'open', label: 'Open Document' },
64+
{ value: 'recent', label: 'Recent Documents' },
6565
{ separator: true },
66-
{ value: 'save', label: '💾 Save' },
67-
{ value: 'save-as', label: '💾 Save As...' },
68-
{ value: 'export', label: '📤 Export' },
66+
{ value: 'save', label: 'Save' },
67+
{ value: 'save-as', label: 'Save As...' },
68+
{ value: 'export', label: 'Export' },
6969
{ separator: true },
70-
{ value: 'cut', label: '✂️ Cut' },
71-
{ value: 'copy', label: '📋 Copy' },
72-
{ value: 'paste', label: '📋 Paste' },
70+
{ value: 'cut', label: 'Cut' },
71+
{ value: 'copy', label: 'Copy' },
72+
{ value: 'paste', label: 'Paste' },
7373
{ separator: true },
74-
{ value: 'settings', label: '⚙️ Settings' },
75-
{ value: 'help', label: 'Help' },
76-
{ value: 'about', label: 'ℹ️ About' }
74+
{ value: 'settings', label: 'Settings' },
75+
{ value: 'help', label: 'Help' },
76+
{ value: 'about', label: 'ℹAbout' }
7777
]
7878
},
7979
argTypes: {}

0 commit comments

Comments
 (0)