Skip to content

Core: Add new layout style none and fix layout styles #12727

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

Merged

Conversation

guilhermewaess
Copy link
Contributor

@guilhermewaess guilhermewaess commented Oct 10, 2020

Issue: #12434 #12041

This PR: Removes the logic from adding styles on body element through styles attr.
Adds a new option for layout: none.

What I did

Added a new option for layouts called none, which won't apply any new style on preview body.
Moved the layouts styles from js to CSS.
Fixed CSS initials override.

How to test

Change the layout property on story parameters to one of the available layouts:

example:
None.parameters = { layout: 'none' };

  • Is this testable with Jest or Chromatic screenshots?
    I don't think it will break any story.

  • Does this need a new example in the kitchen sink apps?
    It's added.

  • Does this need an update to the documentation?
    Yes, but I didn't find any docs related to available parameters.

If your answer is yes to any of these, please make sure to include it in your PR.

Discussion

When the received layout is invalid, what should be the proper behaviour?
For now, it is showing a warning on the console with the invalid option and telling the available options. However, this solution also adds an undefined as a class on the body.

Thanks to @yannbf for the guidance :D

@guilhermewaess guilhermewaess force-pushed the refactor/storyrenderer-styles branch from 922c952 to bc286be Compare October 10, 2020 13:37
@guilhermewaess guilhermewaess force-pushed the refactor/storyrenderer-styles branch from bc286be to 66138e3 Compare October 10, 2020 18:10
@shilman shilman changed the title refactor: move layout from styles attr to css classes and add none as new option. Core: Add new layout style none Oct 10, 2020
@shilman shilman changed the title Core: Add new layout style none Core: Add new layout style none and fix layout styles Oct 10, 2020
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! I'd like @ghengeveld to review since he introduced the layout parameter in 6.0

@shilman shilman added the P0 label Oct 16, 2020
@yannbf yannbf self-requested a review October 18, 2020 21:44
@yannbf
Copy link
Member

yannbf commented Oct 18, 2020

Great work @guilhermewaess! I've gone through the changes and tested them, seems great!
This will fix a lot of issues from users that use css resets or libraries that set styles that currently are getting overridden by storybook.

Copy link
Member

@ghengeveld ghengeveld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍
Only one minor thing.

Object.assign(document.body.style, styles || {});
this.previousStyles = styles;
checkIfLayoutExists(layout: string) {
if (!Object.keys(layoutClassMap).includes(layout)) {
Copy link
Member

@ghengeveld ghengeveld Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why not to use if (!layoutClassMap[layout]) ? Maybe TypeScript doesn't allow it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thing you added this warning by the way 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should make no difference to TS

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@guilhermewaess guilhermewaess Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree it's better to do !layoutClassMap[layout], will change it tonight :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Remove logic from adding styles through styles attr and start to use css instead.
@guilhermewaess guilhermewaess force-pushed the refactor/storyrenderer-styles branch from dd296a2 to 21ec3c9 Compare October 26, 2020 21:35
@shilman shilman merged commit 96a124e into storybookjs:next Oct 26, 2020
@guilhermewaess guilhermewaess deleted the refactor/storyrenderer-styles branch November 18, 2020 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants