Created
February 27, 2024 18:56
-
-
Save ixahmedxi/5ee7dd6d2f92d185e061c847e4a808d4 to your computer and use it in GitHub Desktop.
Storybook docs page tailwind dark mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tailwind base; | |
@tailwind components; | |
@tailwind utilities; | |
@layer base { | |
* { | |
@apply border-border; | |
} | |
body, | |
.docs-story { | |
@apply bg-background text-foreground; | |
font-feature-settings: | |
'rlig' 1, | |
'calt' 1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
import { addons, types, useGlobals } from '@storybook/manager-api'; | |
const ExampleToolbar = () => { | |
const [globals] = useGlobals(); | |
useEffect(() => { | |
const elements = document.querySelectorAll('.docs-story'); | |
elements.forEach((element) => { | |
element.classList.add(globals['theme'] as string); | |
}); | |
}, [globals]); | |
return null; | |
}; | |
addons.register('docs-theme', () => { | |
addons.add('docs-theme-addon', { | |
title: 'Addon to change docs story theme', | |
type: types.TOOL, | |
match: ({ viewMode }) => !!viewMode?.match(/^(story|docs)$/), | |
render: ExampleToolbar, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment