Skip to content
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

Core: Add viewMode to StoryContext #12566

Merged
merged 1 commit into from Sep 24, 2020
Merged

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Sep 24, 2020

Issue: #8474 Part of #12368

What I did

Add viewMode to the context object (second parameter in decorators) so that users can apply conditional code in their decorators depending if the story is either on canvas or docs.. but most importantly it's ground work for certain addons to take advantage of it, such as the backgrounds addon.

How to test

1 - Go to any story (e.g. addon-a11y/base-button.stories.js) and apply the following decorator:

decorators: [
    (StoryFn, context) => {
      console.log({ viewMode: context.viewMode });
      return <StoryFn />;
    },
],

2 - Run yarn start
3 - Check if the viewMode is present.

*The viewMode is always story for the iframed stories such as in angular.

@yannbf yannbf self-assigned this Sep 24, 2020
@shilman shilman changed the title feat(client-api): add viewmode to context Core: Add viewMode to StoryContext Sep 24, 2020
@shilman shilman added the core label Sep 24, 2020
@shilman shilman added this to the 6.1 core milestone Sep 24, 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.

Looks great, thanks for splitting this out! 💯

@shilman shilman merged commit 610d9a3 into next Sep 24, 2020
@shilman shilman deleted the feat/add-view-mode-to-context branch September 24, 2020 12:23
@manuelmeister
Copy link
Contributor

Why is it always story in iframes? Angular is currently iframe only, so this is completely useless and misleading for angular devs.

I tried to add a wrapper (decorator) that wraps only in canvas and not inside the docs. What would I need to do, to implement this for iframes?

@tmeasday
Copy link
Member

tmeasday commented Jan 4, 2021

@shilman this is an interesting problem ☝️ Let's take some time to consider it soon..

@manuelmeister
Copy link
Contributor

@tmeasday how would you solve this?

@tmeasday
Copy link
Member

@manuelmeister I'm not sure if there is a solution to your specific problem right now.

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

4 participants