-
-
Notifications
You must be signed in to change notification settings - Fork 9.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
addon-docs: "escape-hatch" styling for MDX Blocks in DocPages #8502
Comments
Automention: Hey @ndelangen @patricklafrance, you've been tagged! Can you give a hand here? |
This was an oversight in our escape hatching. Should be pretty easy to add -- anybody want to pick it up? cc @domyen |
👍I support adding CSS escape hatches for further theming. A naming scheme like |
Interested in tackling this issue, I will look into it |
Hi @shilman That said, being unable to use If I find how to reliably have a dev server for --core on storybook v5, I will wrap up the pr, else I can push part of the solution. |
Hi @Jeremie-Chauvel that's great news! You should base off
And it should be much more efficient than |
It seems like the escape hatches require additional specificity due to the current cascade in the As of version <link href="main.123abc.css" rel="stylesheet">
<style>#root[hidden], #docs-root[hidden] {
display: none !important;
}</style>
<style data-emotion="css-global">
html.os-html,html.os-html > .os-host {
display:block;
...
}
</style>
<style data-emotion="css-global"></style>
<style data-emotion="css-global"></style>
<style data-emotion="css-global"></style>
<style data-emotion="css-global"></style>
<style data-emotion="css-global"></style>
... Our .sbdocs {
// doubling up to compile .sbdocs.sbdocs-content
// this increases the specificity since Storybook Docs styles lower in the cascade
&.sbdocs {
&-content {
max-width: 84ch;
}
}
...
} It seems like all elements have storybook classes assigned because even a /* Storybook Docs Paragraph Styles */
.css-19sr785 {
font-family: "Nunito Sans",-apple-system,".SFNSText-Regular","San Francisco",BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 16px; /* First font-size declaration */
margin: 0;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-overflow-scrolling: touch;
margin: 16px 0;
font-size: 14px; /* Second font-size declaration, overwriting the one above */
line-height: 24px;
color: #15191b;
} Is there a way to ensure our custom styles load at the bottom of <style>#root[hidden], #docs-root[hidden] {
display: none !important;
}</style>
<style data-emotion="css-global"></style>
<style data-emotion="css-global"></style>
...
<link href="main.123abc.css" rel="stylesheet"> This would allow us to easily assign a utility class without increasing its specificity. Such as updating the background: <Preview className="bg-blue">
...
</Preview> Note: I do realize Is this by design? To require us to provide Please let me know if I'm missing something, if there's a configuration setting I'm missing to correct the cascade structure. Hoping this is just an oversight on one of our ends. Thanks |
Not sure why your previous implementation doesn't work with 6.3.1 e.g., |
Emotion definitely overrides our styles provided in the CSS, and increased specificity overrides less specific selectors despite the cascade. The current implementation of increased specificity ( My interpretation of "narrow by design" was assuming you trusted in the power of the cascade by importing our custom css after Storybook's, allowing the cascade to be respected first. However, this isn't the case as previously noted, thus returning to the age old game of specificity wars. With the current CSS structure: <link href="main.123abc.css" rel="stylesheet">
<style data-emotion="css-global"></style>
<style data-emotion="css-global"></style>
... the cascade would be similar to: // Custom CSS loaded first via main.css
.sbdocs.sbdocs-h1 {
font-size: 123px;
}
// Emotion CSS inserted last
.css-abc123 { // equivalent to sbdocs-h1
font-size: 321px;
} The custom CSS selector ( // Emotion CSS inserted first
.css-abc123 { // equivalent to sbdocs-h1
font-size: 321px;
}
// Custom CSS loaded last via main.css
.sbdocs-h1 {
font-size: 123px;
} If the official position is to require increasing specificity then "narrow by design" is meaningless in my opinion. You're still having to determine amount of specificity, whether it's two classes or eight. It's fine if it is your standard but I'd recommend updating the documentation for more clarity and understand it causes the cascade to favor Emotion/Storybook and not our custom CSS. |
Got it, thanks for the clarification. This is how it's intended to work. As for specificity and the interpretation of "narrow by design", the official theme API is narrow by design. It has few properties you can customize (intentionally). Why? Every new property adds maintenance cost that prevents us from shipping features and fixing bugs. CSS escape hatches are not a part of the theme API. Which is why they're called "escape hatches" and have a "use at your own risk" message in the docs. Our intention is to provide other unofficial ways to customize that are outside of the official theme API. But even this level of customization and ergonomics might not be suitable for everyone (perhaps that's the case here). If you're looking for a fully custom docs site, I'd recommend using a static site generator like Gatsby, Nuxt, Hexo, etc and importing/embedding stories there. That offers ultimate flexibility and fine-grained control over when things load and where, the tradeoff is you have to maintain it yourself. Thanks for the docs suggestion. Would you submit a PR with what you'd like to see? |
Is your feature request related to a problem? Please describe.
It is difficult to customize MDX/DocPage stories using the
@storybook/theming
setup [v5.2.4]. Customizing individual blocks is difficult, as they only render with minified/hashed css classnames.Describe the solution you'd like
An intermediary solution similar to #8061 would be great in the short term.
Describe alternatives you've considered
Updating the
ThemeVars
interface seems like the more appropriate long-term solution, but I imagine this would be more complex of a change that could take a while to ship.If you do have plans for an update on the theming implementation, it would be great to have something to work with in the meantime.
Are you able to assist bring the feature to reality?
With the appropriate guidance/support.
The text was updated successfully, but these errors were encountered: