I've just upgraded to Storybook V5.0.1 and "storybook-readme" V5.0.0.
I followed the upgrade instructions:
import 'storybook-readme/register'; to .storybook\addons.js.import { addReadme } from 'storybook-readme'; and addDecorator(addReadme); to .storybook\config.js.And to each story, I've done the following (the example below is for Button story):
import Button from '../../components/Button/Button';
import README from './README.md';
storiesOf('Button', module)
.addParameters({
readme: {
sidebar: README,
},
})
.add('Button (default)', () => (
<Button
/* props go here... */
/>
));
The README content renders correctly in the sidebar.
However, all my stories are now wrapped in...
<div class="storybook-readme-story">
<div style="display: flex; align-items: center; justify-content: center; margin: 32px 0px;">
/* story content goes here... */
</div>
</div>
...that turns all my story content into a FLEX item, thereby affecting how it renders.
Is there really a need for these inline styles on the DIV wrapper?
Most helpful comment
I will remove default wrappepr in 5.0.2.
Going to release today or tomorrow
On Fri, Mar 22, 2019 at 14:28 Vladimir Humeniuk notifications@github.com
wrote:
All 13 comments
This is just default
StoryPreviewcomponent. By default it just make position centered for story component.Does it affects on your story's styles?
Here is sources of default
StoryPreview-- storybook-readme/src/components/Preview/StoryPreview.js.Possible solutions(this needs to path storybook-readme sources and publish new version):
contentdocs. ΩAlso it is possible to update
StorybookPreviewwrapper.Via parameters:
Or via Global configuration
Thanks for the quick reply @tuchk4
I've tried overriding
StoryPreviewboth globally (inconfig.js) and locally (in my stories), but I still cannot render the wrapper DIV with no inline styles.By defining this wrapper DIV as a
FLEXcontainer, any direct DIV children will be no longer beBLOCKlevel, and therefore any UI components being rendered inside the story will also inherit this new block formatting context.What this means in practise is that my UI components no longer take up 100% of the available space within
<div class="storybook-readme-story">. They are "_squashed_" and therefore don't give an accurate representation of how they should really behave. So, YES, my story styles are effectively broken.Can I suggest that any wrapper DIVs that your plugin generates should NOT generate any inline styles, especially those that affect layout of any nested children. I hope you agree? ;)
Yes I agree. But I would like default
StoryPreviewwrapper make story centered horizontally.As I see current implementation (styles with flex) is wrong so we needs to choose another. I would be happy for any help because I am not so strong in CSS.
For now it is possible to define custom
StoryPreview.I tested with
configureReadmeand it works fine.But you said that this didn't work for you?
OK - that works for me now. Thanks.
I still question why you would want to center the story horizontally if someone specifically uses the README plugin?
<div style="text-align:center;">will work without affecting BLOCK formatting context of the DIV.Oh, and thanks for the plugin in the first place!
I ended up using this block in my
.storybook/config.jsWith
storybook-readmev4, the component was center aligned, so I set thetextAlignto center to be consistent with v4.Yes. Maybe
storybook-readmeshould render story as is. From the beginning I just wanted default story wrapper to work as @storybook/addon-centered addon :)Yes, but the important bit is that the DIV wrapper is still BLOCK level, not FLEX, so children will not be squashed.
Flex children, by default, do not expand to fill their parent container. Instead, they just take up as much room as is needed to render their contents. They only grow if they have an explicit
widthorflex-basis, or haveflex-growset to an integer > 0.Therefore, the "_safest_" way to center content is just with
text-align.We just hit this issue in our component library too when trying to upgrade to storybook-readme 5.
We have some components that have quite significantly different appearance on mobile, as there they should expand to be full-width. Unfortunately the recent changes mean that as they've now been placed inside a flex container they're displayed with minimal width and we're not getting to see the component as intended.
I don't want to see my examples centred on page - I'd rather see them exactly as they would be shown when placed on a page. I'd also rather not have
text-alignbeing set on the container either, as that is not "safe" as that style can cascade down to affect my components.It would therefore be preferable if the default container in storybook-readme had no styling placed on it at all.
If folks desire to have their component examples centred on the page then they can use the
StoryPreviewconfig option as described above. It is just unfortunate that at this time theStoryPreviewcomponent is being placed inside adivthat's been styled as a flex container as it removes the freedom to properly control how the preview is displayed.@stevesims I totally agree with you. To solve this issue in our storybook I added the next code to
config.js:It will make all your storybook components full width and isolate them from flex inside additional
div.UPD:
Simple pure children return in
configureReadmewill remove flex wrapper:I will remove default wrappepr in 5.0.2.
Going to release today or tomorrow
On Fri, Mar 22, 2019 at 14:28 Vladimir Humeniuk notifications@github.com
wrote:
FYI: got this fix but still waiting for other bugs preparing for next release
published 5.0.2
~Hi there - I'm still seeing this issue in
5.0.2.~ Looks like this was a local caching issue - when I wipednode_modulesand reinstalled, it all worked. Thanks!Related issues