Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark mode support for Storybook #1834

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .storybook/dark-mode.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.sb-show-main.dark {
background: #111827;
}
52 changes: 25 additions & 27 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
import type { Preview } from '@storybook/svelte';

import '../src/app.css';
import './dark-mode.css';

import DarkMode, { useDarkMode } from '../src/lib/utilities/dark-mode';

const preview: Preview = {
decorators: [
(_, { globals }) => {
useDarkMode.set(globals.theme === 'dark');
return { Component: DarkMode };
},
],
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
backgrounds: {
default: 'primary',
values: [
{
name: 'space-black',
value: '#141414',
},
{
name: 'off-white',
value: '#f8f8f7',
},
{
name: 'black',
value: '#000',
},
{
name: 'white',
value: '#fff',
},
{
name: 'light',
value: '#f4f4f5',
},
{
name: 'dark',
value: '#18181b',
},
],
disable: true,
},
controls: {
matchers: {
Expand All @@ -42,4 +26,18 @@ const preview: Preview = {
},
};

export const globalTypes = {
theme: {
name: 'Toggle Theme',
description: 'Global theme for components',
defaultValue: 'light',
toolbar: {
icon: 'circlehollow',
items: ['light', 'dark'],
showName: true,
dynamicTitle: true,
},
},
};

export default preview;
1 change: 1 addition & 0 deletions src/lib/utilities/dark-mode/dark-mode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
</script>

<svelte:body use:darkMode />
<slot />
2 changes: 1 addition & 1 deletion src/lib/utilities/dark-mode/dark-mode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { persistStore } from '$lib/stores/persist-store';

const useDarkMode = persistStore(
export const useDarkMode = persistStore(
'dark mode',
!!import.meta.env.VITE_DARK_MODE,
true,
Expand Down
1 change: 1 addition & 0 deletions src/lib/utilities/dark-mode/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import DarkMode from './dark-mode.svelte';

export default DarkMode;
export { useDarkMode } from './dark-mode';
Loading