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

How to remove preview body padding in SB 6.0? #12109

Closed
Obiwarn opened this issue Aug 18, 2020 · 17 comments
Closed

How to remove preview body padding in SB 6.0? #12109

Obiwarn opened this issue Aug 18, 2020 · 17 comments

Comments

@Obiwarn
Copy link

Obiwarn commented Aug 18, 2020

This does not work (fixed element.style seems to be "padding: 1 rem"):

<!--  .storybook/preview-body.html -->
<style>
    body {
        padding: 0;
        background-color: #005cc5;
    }
</style>

Any ideas?

@shilman
Copy link
Member

shilman commented Aug 18, 2020

try the layout: 'fullscreen' story parameter

@coconewty
Copy link

Same issue here, setting isFullscreen: true as per https://storybook.js.org/docs/react/configure/features-and-behavior doesn't fix it.

Must admit I haven't dug far but SB is adding style="margin: 0px; padding: 1rem; display: block; justify-content: initial; align-items: initial; min-height: initial;" to body for some reason.

@shilman
Copy link
Member

shilman commented Aug 19, 2020

@coconewty isFullscreen: true isn't the same thing as layout: 'fullscreen'. in .storybook/preview.js:

export const parameters = { layout: 'fullscreen' }

@Obiwarn
Copy link
Author

Obiwarn commented Aug 20, 2020

Works great. Thank you.

@Obiwarn Obiwarn closed this as completed Aug 20, 2020
@coconewty
Copy link

Thanks @shilman I missed this.

FYI of anyone else hunting for this, it's here... https://storybook.js.org/docs/react/configure/story-layout

@webunderconstruction
Copy link

Thanks @shilman I missed this.

FYI of anyone else hunting for this, it's here... https://storybook.js.org/docs/react/configure/story-layout

Adding some google search keywords;

How to remove default canvas margin in Storybook v6

@mnlfischer
Copy link

mnlfischer commented Jan 30, 2021

is it possible to disable it for only specific stories?

@samwyma
Copy link

samwyma commented Feb 2, 2021

Yeah, second that ^^. Our use case is having a few stories which are full app pages (where padding screws up things like screen positioned elements) where we would like to disable padding, but also having component stories (e.g. buttons) where padding makes the viewing of those components nicer

@mnlfischer
Copy link

one solution are decorators but it is annoying set the layout to fullscreen and use decorators on 300 components only for a few pages that needs a fullscreen.

@benjaminbaldoni
Copy link

@mnlfischer you can achieve that by using the parameters attribute on each individual story:

export const Primary = Template.bind({})

Primary.args = {
  primary: true,
  label: 'Button',
}

Primary.parameters = {
  layout: 'fullscreen',
}

@mnlfischer
Copy link

@mnlfischer you can achieve that by using the parameters attribute on each individual story:

export const Primary = Template.bind({})

Primary.args = {
  primary: true,
  label: 'Button',
}

Primary.parameters = {
  layout: 'fullscreen',
}

misses that in the docs. thanks!

@iamandrewluca
Copy link
Contributor

So to generalise

Affects globally .storybook/preview.ts

import type { Parameters } from '@storybook/react';

export const parameters: Parameters = {
  layout: 'fullscreen'
};

Affects all stories in a file *.stories.tsx

import { Meta } from '@storybook/react';

export default {
  title: 'Stories Name',
  parameters: {
    layout: 'fullscreen',
  },
} as Meta;

Affects single story in a file *.stories.tsx

import { Story } from '@storybook/react';

export const MyStory: Story = () => <div />;
MyStory.parameters = {
  layout: 'fullscreen'
}

@benwinding
Copy link

Also worth mentioning that you can use the .addParameters() method too:

storiesOf('pages/home/story', module)
    .add('My story', {}, () => {
      return <div>EXAMPLE</div>
    })
    .addParameters({ layout: 'fullscreen' });

@shilman
Copy link
Member

shilman commented Sep 3, 2021

@benwinding For what it's worth, we recommend converting your stories from the storiesOf API to Component Story Format (CSF): https://storybook.js.org/docs/react/writing-stories/introduction

We've even provided a codemod to help automate this migration:

npx sb migrate storiesof-to-csf --glob "src/**/*.stories.js"

@benwinding
Copy link

@shilman thanks mate, it will take a while, but could be worth it

@jayarjo
Copy link

jayarjo commented Oct 27, 2022

@iamandrewluca neither one has any effect for me for some reason. Do you need to add some addon for this to have an effect?

UPDATE: Never mind. Turns out our Storybook has additional padding on the #root in preview-head.html.

@diondiondion
Copy link

For anyone wondering how to apply this option to individual stories in MDX files:

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

…or set it for all stories in the document:

<Meta
	title="Readme title"
	component={Component}
	parameters={{layout: 'fullscreen'}}
/>

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

No branches or pull requests