-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(storybook): add theme toggle to storybook #18123
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
db7d560
replace deprecated DecoratorFn with Decorator
thmsobrmlr cee3da3
rename useFeatureFlags to setFeatureFlags
thmsobrmlr f6f4d41
add control for theme global
thmsobrmlr 83895dd
allow setting theme from globals
thmsobrmlr 25bd7bf
rename with3000 to withTheme
thmsobrmlr af21858
remove withTheme from existing stories
thmsobrmlr 6e39c8c
Update UI snapshots for `chromium` (1)
github-actions[bot] 62c2518
Update UI snapshots for `chromium` (1)
github-actions[bot] b37c0d1
Update UI snapshots for `chromium` (2)
github-actions[bot] bf76ae5
Merge branch 'master' into storybook-theme-control
thmsobrmlr 9f4e546
force feature flags for posthog 3000 stories
thmsobrmlr 35d6464
Update UI snapshots for `chromium` (1)
github-actions[bot] 81fa17b
Merge branch 'master' into storybook-theme-control
thmsobrmlr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { Decorator } from '@storybook/react' | ||
|
||
import { FEATURE_FLAGS } from 'lib/constants' | ||
|
||
/** Global story decorator that is used by the theming control to | ||
* switch between themes. | ||
*/ | ||
export const withTheme: Decorator = (Story, context) => { | ||
const theme = context.globals.theme | ||
|
||
// set the body class | ||
const actualClassState = document.body.classList.contains('posthog-3000') | ||
const desiredClassState = theme !== 'legacy' | ||
|
||
if (actualClassState !== desiredClassState) { | ||
if (desiredClassState) { | ||
document.body.classList.add('posthog-3000') | ||
} else { | ||
document.body.classList.remove('posthog-3000') | ||
} | ||
} | ||
|
||
// set the feature flag | ||
const actualFeatureFlagState = window.POSTHOG_APP_CONTEXT!.persisted_feature_flags?.includes( | ||
FEATURE_FLAGS.POSTHOG_3000 | ||
) | ||
const desiredFeatureFlagState = theme !== 'legacy' | ||
|
||
if (actualFeatureFlagState !== desiredFeatureFlagState) { | ||
const currentFlags = window.POSTHOG_APP_CONTEXT!.persisted_feature_flags || [] | ||
if (desiredFeatureFlagState) { | ||
window.POSTHOG_APP_CONTEXT!.persisted_feature_flags = [...currentFlags, FEATURE_FLAGS.POSTHOG_3000] | ||
} else { | ||
window.POSTHOG_APP_CONTEXT!.persisted_feature_flags = currentFlags.filter( | ||
(f) => f !== FEATURE_FLAGS.POSTHOG_3000 | ||
) | ||
} | ||
} | ||
|
||
// set the theme | ||
document.body.setAttribute('theme', theme === 'dark' ? 'dark' : 'light') | ||
|
||
return <Story /> | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+79 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--bullet-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+81 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--empty-notebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+51 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--notebook-not-found.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+67 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--notebooks-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+76 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--numbered-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+21 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--recordings-playlist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+79 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--text-formats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+73 Bytes
(100%)
frontend/__snapshots__/scenes-app-notebooks--text-only-notebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this needs to be changed (or removed) as we now do this via the theme picker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think for the purpose of snapshots we still need the decorator.
BTW looks like the now-unused dark mode and light mode snapshots weren't deleted, we might want to do some pruning of unused snapshots at some point. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I'd like to address this by adding an option to
testOptions
where you can specify wether "legacy", "3000" or "all" themes should be captured.I was hoping Storybook would provide a way to set globals for a specific story, so that we could override the theme there, but that doesn't seem to be the case.