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

Global layout parameter isn't applied to DocsPage canvas #12135

Closed
robbertkl opened this issue Aug 19, 2020 · 15 comments · Fixed by #20723
Closed

Global layout parameter isn't applied to DocsPage canvas #12135

robbertkl opened this issue Aug 19, 2020 · 15 comments · Fixed by #20723

Comments

@robbertkl
Copy link
Contributor

Describe the bug

When I add a global layout parameter (e.g. layout: 'fullscreen') in preview.js it gets applied to the Canvas tab of all stories. However, it does not get applied to the stories / Canvas element on my MDX DocsPage. I would still need to set this manually for it to work:

<Canvas>
  <Story name="storyname" parameters={{ layout: 'fullscreen' }}>

To Reproduce

Add a global layout parameter to .storybook/preview.js and check out a docs page with a story wrapped in a canvas.

Expected behavior

I expected the docs page story to apply the same global parameters and not need to manually add the parameters to every story.

System:

Environment Info:

System:
OS: macOS 10.15.5
CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
Binaries:
Node: 14.8.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.7 - /usr/local/bin/npm
Browsers:
Chrome: 84.0.4147.125
Firefox: 75.0
Safari: 13.1.1
npmPackages:
@storybook/addon-controls: ^6.0.13 => 6.0.13
@storybook/addon-docs: ^6.0.13 => 6.0.13
@storybook/react: ^6.0.13 => 6.0.13

@stale
Copy link

stale bot commented Sep 20, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Sep 20, 2020
@shilman shilman added the P1 label Sep 25, 2020
@stale stale bot removed the inactive label Sep 25, 2020
@shilman shilman assigned ndelangen and unassigned ndelangen Sep 25, 2020
@dmondev
Copy link

dmondev commented Oct 9, 2020

Hi, is there any workaround for this issue ?

@shilman shilman modified the milestones: 6.0.x, 6.1 docs Nov 2, 2020
@shilman shilman removed the tracked label Nov 4, 2020
@dmartinjs
Copy link
Contributor

Same problem, but the workaround doesn't seems to work if you use the CSF.

@shilman shilman modified the milestones: 6.1 docs, 6.2 docs Nov 23, 2020
@stale
Copy link

stale bot commented Dec 25, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Dec 25, 2020
@shilman shilman modified the milestones: 6.2 docs, 6.2 candidates Mar 4, 2021
@stale stale bot removed inactive labels Mar 4, 2021
@shilman shilman removed this from the 6.2 candidates milestone Mar 11, 2021
@gburning
Copy link

gburning commented Apr 4, 2022

Hi! Bumping this. I'm setting the layout parameter to fullscreen in the default export of my story but under the docs panel it's still padded. Is the only workaround to manually replace the docs page with a custom MDX file that sets the right layout or can I achieve this with just parameters somehow?

It's not very clear what parameters are available for the various tools/addons in the documentation.

@superkat64
Copy link

Hi! Same problem -- I would like to set all my docPage stories to have layout: 'centered' without having to set them all in each individual story but it isn't looking like there is a great way to do this 🤔

Would love anyone suggestions...

@ndelangen
Copy link
Member

perhaps a prop on the docs parameter @shilman ?

@shilman shilman removed the P1 label Oct 18, 2022
@tgelu
Copy link

tgelu commented Oct 27, 2022

This seems to be tagged as "has workaround". What is the workaround @shilman ? :)

@shilman
Copy link
Member

shilman commented Oct 27, 2022

@tgelu In the original issue description @robbertkl mentioned that it works if he adds a layout parameter to the Story block, so I added has workaround label. I did not verify the behavior. Though re-reading the issue I doubt that actually works. Removing the label, but please let me know if you find a workaround!

@rschaufler
Copy link

rschaufler commented Jan 20, 2023

It still doesn't work in Storybook 7 Beta 31.

@shilman I found one workaround for this issue by referencing Stories within an MDX file instead of embedding them directly.

Working example of a Web-component story (should work with other frameworks like React too)

my-component.mdx

import { Canvas, Meta, Story } from '@storybook/blocks'

import * as Stories from './my-component.stories'

<Meta of={ Stories } />

# My component

Some documentation

<Canvas>
  <Story of={ Stories.ExampleStory } />
</Canvas>

my-component.stories.tsx

import { html } from 'lit/static-html.js'

export default {
  title: 'Components/MyComponent,
  parameters: {
    layout: 'fullscreen'
  }
}

export const ExampleStory = {
  render: () => html`<my-component title="Hello World"></my-component>`
}

The key here is that in the MDX file you reference the Meta definition of the TSX file by doing <Meta of={ Stories } />.

In the default export of the TSX file, parameters.layout is set to fullscreen and will be respected in the rendered MDX output.

@shilman
Copy link
Member

shilman commented Jan 20, 2023

@rschaufler what you shared is the recommended way of using CSF+MDX in 7.0 and beyond. Thank you for following up!

@tmeasday @JReinhold is this something we can fix as we stabilize the changes to the story block?

@JReinhold
Copy link
Contributor

As a matter of fact I was working on this exact thing yesterday. I'm not sure I understand this issue completely, but the next iteration of the Canvas doc block will respect layout defined in the following order:

  1. as a prop - <Canvas layout="centered" of={MyStory} />
  2. at parameters.docs.canvas.layout
  3. at parameters.layout
  4. defaults to "padded"

It will take the parameters from the story, which should include whatever is defined globally in preview.js or at the meta level.

@shilman
Copy link
Member

shilman commented Jan 24, 2023

Olé!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.33 containing PR #20723 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb@next upgrade --prerelease

@cr0cK
Copy link

cr0cK commented May 2, 2024

Looks like it still doesn't work.

const preview: Preview = {
  parameters: {
    layout: 'fullscreen',
    docs: {
      canvas: {
        layout: 'fullscreen'
      }
    }
  }
}

or

<Meta title="Title" parameters={{
  docs: {
    canvas: {
      layout: 'fullscreen'
    }
  },
  layout: 'fullscreen'
}} />

Temporarily, I found this workaround.

// .storybook/styles.css
// import './styles.css' in .storybook/preview.ts

.sbdocs {
  padding: 0 20px !important;
}

.sbdocs-content {
  width: 100% !important;
  max-width: inherit !important;
}

Which is quite sad but it's working.

@JReinhold
Copy link
Contributor

@cr0cK can you open a new issue with a minimal reproduction showcasing the issue?

https://storybook.js.org/docs/contribute/how-to-reproduce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.