Skip to content

Commit

Permalink
feat: enabled dark theme preview for components
Browse files Browse the repository at this point in the history
  • Loading branch information
Powerplex committed Mar 28, 2023
1 parent 47452ce commit aab6a3c
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 2 deletions.
1 change: 1 addition & 0 deletions .storybook/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/addon-styling',
],
staticDirs: ['../public'],
framework: {
Expand Down
7 changes: 7 additions & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
window.global = window
</script>

<style>
/* Enabled dark mode preview in story views */
html {
@apply !bg-background;
}
</style>

<link href="/normalize.css" rel="stylesheet" />
14 changes: 14 additions & 0 deletions .storybook/preview.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import '../src/tailwind.css'
import './sb-theming.css'

import { withThemeByDataAttribute } from '@storybook/addon-styling'

export const parameters = {
controls: {
Expand All @@ -8,3 +11,14 @@ export const parameters = {
},
},
}

export const decorators = [
withThemeByDataAttribute({
themes: {
light: 'light',
dark: 'dark',
},
defaultTheme: 'light',
attributeName: 'data-theme',
}),
]
4 changes: 4 additions & 0 deletions .storybook/sb-theming.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Enabled dark mode preview inside Canvas blocks */
.docs-story:first-child {
@apply !bg-background;
}
Loading

0 comments on commit aab6a3c

Please sign in to comment.