-
Notifications
You must be signed in to change notification settings - Fork 3
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
Replace theme add-on with toolbar and global args #1219
Conversation
|
This is looking really good Tyler! I noticed a few oddities: Broken Docs PagesSome of our stories have broken docs pages with this change. For example, when I view one of our Prism docs pages I get a console error. Switching to the Canvas view shows that error in the canvas Getting Stuck in a ThemeI'm not exactly sure why this happens but it seems like on the Input docs page specifically I can get stuck in a theme: BunchFor some reason the Bunch example disappears on the canvas in dark mode. Upping the z-index on Table Theme IssuesThis is unrelated to this PR, but the table has some issues in dark mode (low contrast caption color, incorrect striped color.) What's the best place for me to report that? A new issue? Other than that it's looking great! Let me know if you need any more info on any of this! |
These are all great catches, @Paul-Hebert , thank you for testing so thoroughly! |
762b545
to
52bf4ff
Compare
src/design/themes.stories.mdx
Outdated
@@ -23,15 +13,17 @@ Themes may be applied to a containing element to change that content's appearanc | |||
The default theme, applied to the document `:root` by default. | |||
|
|||
<Canvas> | |||
<Story name="Light">{demoStory.bind({})}</Story> | |||
<Story name="Light" args={{ theme: 'light' }}> |
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.
Should this be light
or t-light
?
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.
In this case this is me telling the demo which theme is applied so it can modify its text and stuff accordingly, so even though it looks really close to the parameters it's not actually the same thing. I'm hoping this will only happen in the theme demos.
@Paul-Hebert I just pushed some updates that may address the issues you've observed...
I couldn't reproduce this error, but I added extra checks to make sure elements exist before using
I also couldn't reproduce this error, but I noticed a different console error relating to my use of
I could reproduce this one! I think I fixed it by applying the theme class to
I've created an issue to resolve this: #1229 |
I'm seeing the same problem @Paul-Hebert saw on the Input page — changing the theme to dark on the Input docs page doesn't change anything. I also still can't see the bunch icons in either theme on the Bunch docs pages. I'm testing in Edge, BTW |
Okay, now I can reproduce. Not sure what I'm doing differently now. I think this may have something to do with inline versus iframed stories. Thanks, @spaceninja! Sorry for the runaround. |
I'm not sure if this is a bug, because I'm not sure it's a real-world scenario, but if I apply the global dark theme on the Themes docs page, the nested dark card inside the light theme (that is now dark theme) remains dark. I would expect that if one changes, the other does also, but feel free to disregard if this isn't a situation a real user could end up in. |
Good catch. I think at the very least we could force them to stay the same theme regardless, since this is kind of a special case and someone could (as you suggest) swap themes and then head over here. |
Could we disable the theme control on that page? |
Gonna have to pick this up tomorrow, but there may be a major blocker to getting this working with iframed docs: storybookjs/storybook#13444 It doesn't even seem like the iframed docs are responding to a change in that toolbar, but I'd like to take a new look with fresh eyes tomorrow. |
Probably! |
I think this bug may be more closely related to the issue we're seeing on Input: storybookjs/storybook#14477 |
@tylersticka I can't tell the state of this PR at a glance. Are you in the process of addressing feedback or is the PR in a ready state for another review. Let me know how I can help! 🙂 |
@gerardo-rodriguez I'm in the process of addressing feedback at the moment! I just removed the open request for Dev review, sorry about that! |
Okay, I think this is ready for re-review, with a few caveats:
Both issues are solvable if we wanted to expand this from a custom toolbar and decorator to a full add-on, which would give us the ability to assign more complicated actions to the toolbar items and would allow us to force-refresh stories in contexts like the docs mode. I haven't done this because...
TL;DR: This isn't perfect, but it's a lot better than our current solution, and is likely to improve more as our dependencies update and our project evolves. But let me know if you disagree! |
const previewElement = storyElement.closest('.docs-story'); | ||
updateTheme(previewElement, theme); |
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 don't yet have an understanding of story elements and their contents. Is it a guaranty that there will always exist a .docs-story
or do we need to check that previewElement
is not null
before attempting to update the theme? 🤔 ¯\_(ツ)_/¯
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.
This seems like a good safety check given that the underlying Storybook markup is outside our control
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.
The updateTheme
function does check that the element is truthy and has a classList
property, so I don't think another check before calling it is necessary.
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.
TL;DR: This isn't perfect, but it's a lot better than our current solution, and is likely to improve more as our dependencies update and our project evolves. But let me know if you disagree!
That makes sense to me 👍 I'm cool with merging this in, though agree with Gerardo that it would be nice to add a safety check to confirm the .story-docs
element exists before interacting with it.
Overview
After upgrading Storybook (#1214), our themes add-on became available in Docs view but was not functional. I attempted to use he add-on's
withThemes
decorator, but it does not appear to be compatible with inlined HTML stories. So this PR replaces it with a custom toolbar using the Toolbar add-on that ships with Storybook's essential add-ons.This also helps us overcome an issue where we couldn't reliably configure a theme for a specific story. Now, we can specify a
theme
parameter corresponding to the desired theme class and the story will gain that theme. That means we can remove thefill-canvas
template we were using as kind of a hack.Screenshots
Testing
On the deploy preview…