You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtype{Decorator}from'@storybook/react';exportconstwithTheme: Decorator=(StoryFn,{globals: { theme }, viewMode })=>{if(!theme){theme=window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';}if(viewMode==='docs'){// Make stories in docs mode all light theme, except for the `Themed` story (fragile, I know)// This should only really run once when the docs page loads, but I can't figure out// What event to use to listen for that. So it runs too much, but ¯\_(ツ)_/¯document.querySelectorAll('.sbdocs-preview').forEach((element)=>{if(!element.getAttribute('data-user-color-scheme')&&element.previousElementSibling?.id!=='themed'){element.setAttribute('data-user-color-scheme','light');}});}else{// Set theme data attributedocument.documentElement.setAttribute('data-user-color-scheme',theme);}return<StoryFn/>;};
I want to reduce examples of any in my codebase, so I would like to type the globals so that document.documentElement.setAttribute('data-user-color-scheme', theme); sets a string instead of an any type
Suggestion would be to change the Globals type to an interface to allow extending with user types.
This discussion was converted from issue #23977 on August 29, 2023 10:19.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Describe the bug
I have a story decorator:
I want to reduce examples of
any
in my codebase, so I would like to type theglobals
so thatdocument.documentElement.setAttribute('data-user-color-scheme', theme);
sets astring
instead of anany
typeSuggestion would be to change the
Globals
type to an interface to allow extending with user types.To Reproduce
View https://stackblitz.com/edit/github-4qskx4?file=src%2FwithTheme.tsx and inspect the type of the
theme
variable in the function argumentsSystem
Beta Was this translation helpful? Give feedback.
All reactions