Skip to content

Instantly share code, notes, and snippets.

@ixahmedxi
Created February 27, 2024 18:56
Show Gist options
  • Save ixahmedxi/5ee7dd6d2f92d185e061c847e4a808d4 to your computer and use it in GitHub Desktop.
Save ixahmedxi/5ee7dd6d2f92d185e061c847e4a808d4 to your computer and use it in GitHub Desktop.
Storybook docs page tailwind dark mode
@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;
}
}
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