-
-
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
Docs: using targetted styles, not components to style MDX #19958
Docs: using targetted styles, not components to style MDX #19958
Conversation
@tom There's one minor issue with our opt-out approach, namely style inheritance. Some styles are inherited by parents even if they are not set. With our global selector, this means that styles can get inherited even through an Examples:
if our global styles styled Solutions:
|
Also, I looked into the few components that still used the components from |
@@ -0,0 +1,39 @@ | |||
import { Unstyled } from './Unstyled.tsx'; |
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.
@jonniebigodes if you have feedback for this documentation, let me know.
'.sb-unstyled', | ||
'.sbdocs-preview', | ||
'.sb-story', | ||
'.docblock-source', | ||
'.sb-anchor', |
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.
It's up for discussion how the responsibility should be divided here.
This selector could also just be sb-unstyled
, and then it was the responsibility of any of the components (Story
, Canvas
, etc.) to add that class to their elements.
Who is responsible for unstyling elements, the styler (here) or the element?
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'm open to whatever but my instinct was the other way round (.sb-unstyled
)
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.
Let's keep it as-is then and revisit if we get wiser.
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.
Narrator: He did get wiser. #21150
@@ -40,9 +63,374 @@ export const Subtitle = styled.h2(withReset, ({ theme }) => ({ | |||
color: transparentize(0.25, theme.color.defaultText), | |||
})); | |||
|
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 following style are copied from all the components in https://github.com/storybookjs/storybook/tree/tom/sb-996-resolve-css-issue-with-introduction/code/ui/components/src/typography/elements
@JReinhold I get it, I think that limitation makes sense and is an issue in the 6.x implementation as well, right? I think we can live with it for sure. |
Huh, you must be right, I hadn't thought about that at all. No problem then. |
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.
Awesome @JReinhold! Can we add some notes about breaking change to the MIGRATION.md
(cc @shilman / @jonniebigodes we should maybe mention in MDX2 docs too):
- styles leak into non-story components if you don't wrap in
<Unstlyed>
<Code>
needs to be imported now
@JReinhold I can't approve as I opened this PR, but I'm happy with this. |
@tmeasday I've added some entries to the migration doc, please check it out.
This is actually not possible currently, because the component that replaces
As you can see from my migration notes, I think the use cases for defining a code block with |
I'm happy with that, that's great! |
Issue: Our MDX components no longer work for pure HTML in MDX, in particular our
Introduction.mdx
.Current:
6.x
The root cause here is a breaking change in MDX2: https://mdxjs.com/migrating/v2/#update-mdx-content
If you put down (as we do in
Introduction.mdx
):It will no longer be replaced by the component you specify for
<div>
to MDX. Currently we pass a "styled div" that (in the case of the<div>
) does a reset and sets fonts etc. This will not work in MDX2.There are a couple of problems:
What I did
@JReinhold and I have prototyped a solution using targetted styles on the
DocsContent
wrapper. Basically for the above, we use:To target styles at all
<div>
elements that are not children of.sb-story
(we will attach that style to the output of the<Story/>
block). That ensures the styles apply inside the MDX but not inside stories.However, there are some issues with this approach:
Some of the components do more than just styles, primarily the
<code>
. In this case, we won't be able achieve full parity.It seems like MDX is inserting some extra
<p>
elements that change the structure of the generated HTML anyway. I'm not sure if this is a bug, but this will likely mess people up too.The specificity of our styles change as a result -- before it was
.css-2ltd27
(some emotion class), now it it.css-2ltd27 div:not(.sb-story div)
which is a higher specificity, which is going to be a breaking change (in particular we need to retarget the inline styles inIntroduction.mdx
to ensure they override the reset).The styles will target other elements inside components the user uses in MDX, such as our doc blocks, or 3rd party "blocks".
Other options
Some other alternatives we've considered:
Alternative 1: Simply change the introduction to look nice (by adding more styles) and make raw HTML in MDX completely unstyled.
Alternative 2: As above, but include a very basic set of styles (e.g fonts, line-height) on the wrapper element, let it cascade, then reset it on the
<Story/>
element.Other notes